Using dyanmaic URLs and need some help with a form

  • 74123
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 06, 2005
  • Posts: 190
  • Status: Offline

Post October 7th, 2005, 7:39 pm

PHP Code: [ Select ]
 
<?php
 
include("config/config.php");
 
 
 
   if($submit)
 
  {
 
 
 
      $title = $_POST['title'];
 
     $name = $_POST['name'];
 
      $content = $_POST['content'];
 
 
 
 
 
 
 
         $result = mysql_query("UPDATE news SET title='$title', name='$name', content='$content' WHERE id='$id' ",$connect);
 
 
 
          echo "<b><strong>Thank you! News UPDATED Successfully!</strong>";
 
         // echo "<meta http-equiv=Refresh content=2;url=../index.php target='_self'>";
 
}
 
elseif($id)
 
{
 
 
 
        $result = mysql_query("SELECT * FROM news WHERE id='$id' ",$connect);
 
        while($row = mysql_fetch_assoc($result))
 
             {
 
                $title = $row["title"];
 
            $name = $row["name"];
 
                $content = $row["content"];
 
               
 
?>
 
 
 
<form action="<? echo $PHP_SELF ?>" method="post" name="form">
 
  <p>
 
  <p>Name :<br />
 
    <input name="name" size="40" maxlength="20" value="<? echo $name; ?>">
 
    <br />
 
Headline:<br />
 
<input name="title" size="40" maxlength="255" value="<? echo $title; ?>">
 
<br />
 
<br />
 
<input onClick="document.form.news.value+=''" type="button" value="Bold">
 
<input onClick="document.form.news.value+=''" type="button" value="Italic">
 
<input onClick="document.form.news.value+=''" type="button" value="Underlined">
 
<input onClick="document.form.news.value+='[img src=http://]'" type="button" value="Image">
 
<input onClick="document.form.news.value+='[url=http://]Link[/url]'" type="button" value="URL">
 
<br>
 
<span class="style4"><em>Example: <br>
 
</em>[img src=http://<span class="style1">www.url.com/image.jpg</span>]<br>
 
[url=http://<span class="style1">www.url.com</span>]<span class="style1">URL Title</span>[/url] <br />
 
</span><br />
 
<a href="javascript&#058;;" onClick="document.form.news.value+=':@'"><img src="images/smilies/angry.gif" alt=":@" height="15" width="15" /></a>
 
<a href="javascript&#058;;" onClick="document.form.news.value+=':D'"><img src="images/smilies/biggrin.gif" alt=":D" height="15" width="15" /></a>
 
<a href="javascript&#058;;" onClick="document.form.news.value+=':S'"><img src="images/smilies/confused.gif" alt=":S" height="15" width="15" /></a>
 
<a href="javascript&#058;;" onClick="document.form.news.value+='B)'"><img src="images/smilies/cool.gif" alt="B)" height="15" width="15" /></a>
 
<a href="javascript&#058;;" onClick="document.form.news.value+=':)'"><img src="images/smilies/happy.gif" alt=":)" height="15" width="15" /></a>
 
<a href="javascript&#058;;" onClick="document.form.news.value+=':|'"><img src="images/smilies/mellow.gif" alt=":|" height="15" width="15" /></a>
 
<a href="javascript&#058;;" onClick="document.form.news.value+=':('"><img src="images/smilies/sad.gif" alt=":(" height="15" width="15" /></a>
 
<a href="javascript&#058;;" onClick="document.form.news.value+=':P'"><img src="images/smilies/tongue.gif" alt=":P" height="15" width="15" /></a>
 
<a href="javascript&#058;;" onClick="document.form.news.value+=';)'"><img src="images/smilies/wink.gif" alt=";)" height="15" width="15" /></a><br />
 
<br />
 
<textarea name="content"  rows="15" cols="75"><? echo $content; ?></textarea>
 
<br />
 
<br />
 
<input name="submit" type="submit" value="submit" />
 
</form>
 
 
 
<?
 
      }
 
?>
 
 
  1.  
  2. <?php
  3.  
  4. include("config/config.php");
  5.  
  6.  
  7.  
  8.    if($submit)
  9.  
  10.   {
  11.  
  12.  
  13.  
  14.       $title = $_POST['title'];
  15.  
  16.      $name = $_POST['name'];
  17.  
  18.       $content = $_POST['content'];
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.          $result = mysql_query("UPDATE news SET title='$title', name='$name', content='$content' WHERE id='$id' ",$connect);
  27.  
  28.  
  29.  
  30.           echo "<b><strong>Thank you! News UPDATED Successfully!</strong>";
  31.  
  32.          // echo "<meta http-equiv=Refresh content=2;url=../index.php target='_self'>";
  33.  
  34. }
  35.  
  36. elseif($id)
  37.  
  38. {
  39.  
  40.  
  41.  
  42.         $result = mysql_query("SELECT * FROM news WHERE id='$id' ",$connect);
  43.  
  44.         while($row = mysql_fetch_assoc($result))
  45.  
  46.              {
  47.  
  48.                 $title = $row["title"];
  49.  
  50.             $name = $row["name"];
  51.  
  52.                 $content = $row["content"];
  53.  
  54.                
  55.  
  56. ?>
  57.  
  58.  
  59.  
  60. <form action="<? echo $PHP_SELF ?>" method="post" name="form">
  61.  
  62.   <p>
  63.  
  64.   <p>Name :<br />
  65.  
  66.     <input name="name" size="40" maxlength="20" value="<? echo $name; ?>">
  67.  
  68.     <br />
  69.  
  70. Headline:<br />
  71.  
  72. <input name="title" size="40" maxlength="255" value="<? echo $title; ?>">
  73.  
  74. <br />
  75.  
  76. <br />
  77.  
  78. <input onClick="document.form.news.value+=''" type="button" value="Bold">
  79.  
  80. <input onClick="document.form.news.value+=''" type="button" value="Italic">
  81.  
  82. <input onClick="document.form.news.value+=''" type="button" value="Underlined">
  83.  
  84. <input onClick="document.form.news.value+='[img src=http://]'" type="button" value="Image">
  85.  
  86. <input onClick="document.form.news.value+='[url=http://]Link[/url]'" type="button" value="URL">
  87.  
  88. <br>
  89.  
  90. <span class="style4"><em>Example: <br>
  91.  
  92. </em>[img src=http://<span class="style1">www.url.com/image.jpg</span>]<br>
  93.  
  94. [url=http://<span class="style1">www.url.com</span>]<span class="style1">URL Title</span>[/url] <br />
  95.  
  96. </span><br />
  97.  
  98. <a href="javascript&#058;;" onClick="document.form.news.value+=':@'"><img src="images/smilies/angry.gif" alt=":@" height="15" width="15" /></a>
  99.  
  100. <a href="javascript&#058;;" onClick="document.form.news.value+=':D'"><img src="images/smilies/biggrin.gif" alt=":D" height="15" width="15" /></a>
  101.  
  102. <a href="javascript&#058;;" onClick="document.form.news.value+=':S'"><img src="images/smilies/confused.gif" alt=":S" height="15" width="15" /></a>
  103.  
  104. <a href="javascript&#058;;" onClick="document.form.news.value+='B)'"><img src="images/smilies/cool.gif" alt="B)" height="15" width="15" /></a>
  105.  
  106. <a href="javascript&#058;;" onClick="document.form.news.value+=':)'"><img src="images/smilies/happy.gif" alt=":)" height="15" width="15" /></a>
  107.  
  108. <a href="javascript&#058;;" onClick="document.form.news.value+=':|'"><img src="images/smilies/mellow.gif" alt=":|" height="15" width="15" /></a>
  109.  
  110. <a href="javascript&#058;;" onClick="document.form.news.value+=':('"><img src="images/smilies/sad.gif" alt=":(" height="15" width="15" /></a>
  111.  
  112. <a href="javascript&#058;;" onClick="document.form.news.value+=':P'"><img src="images/smilies/tongue.gif" alt=":P" height="15" width="15" /></a>
  113.  
  114. <a href="javascript&#058;;" onClick="document.form.news.value+=';)'"><img src="images/smilies/wink.gif" alt=";)" height="15" width="15" /></a><br />
  115.  
  116. <br />
  117.  
  118. <textarea name="content"  rows="15" cols="75"><? echo $content; ?></textarea>
  119.  
  120. <br />
  121.  
  122. <br />
  123.  
  124. <input name="submit" type="submit" value="submit" />
  125.  
  126. </form>
  127.  
  128.  
  129.  
  130. <?
  131.  
  132.       }
  133.  
  134. ?>
  135.  
  136.  


I get this error:
Code: [ Select ]
Parse error: parse error, unexpected $ in /var/www/verysecretsite.com/public_html/verysecretsite_final/includes/admin/panels/news/edit.php on line 68


Any help would be great.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 7th, 2005, 7:39 pm

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post October 7th, 2005, 7:53 pm

PHP Code: [ Select ]
<form action="<? echo $PHP_SELF ?>" method="post" name="form">


Where is $PHP_SELF defined in your code? That would be my first question.
I'm also assuming line 68 is the end line of your code which typically occurs if there is a parse error such as this:
Quote:
Parse error: parse error, unexpected $ in
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • 74123
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 06, 2005
  • Posts: 190
  • Status: Offline

Post October 7th, 2005, 8:38 pm

from what I undersyand, $PHP_SELF just tells it to submit the page to itself, it doesnt need to be defined.

I dont know whats wrong there, I ended up just rewriting the whole thing and its working. as far as i can tell there is nothing different (of any significance) in the new one.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post October 7th, 2005, 9:02 pm

Try:
PHP Code: [ Select ]
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" >
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • 74123
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 06, 2005
  • Posts: 190
  • Status: Offline

Post October 10th, 2005, 3:03 pm

Im having a problem with submitting a form to itself so it will upload to a db. I tried the page by itself without using includes and it works. I have tried:

Code: [ Select ]
http://www.somewebsite.com/somewebsite_final/includes/admin/panels/news/add.php


Code: [ Select ]
index.php?content=admin&section=panel&edit=news&action=add


Code: [ Select ]
<?php echo $_SERVER['PHP_SELF'];?>


as my forma action. Yes, I am telling it to post.
When I have the page by itself it works just fine, but if im trying to include it in index.php it doesnt work, once you hit submit, it just shows you the index page.

Page Code:
Code: [ Select ]
  <?php
//beginning of Add news
include("../../../../config/config.php");


 if($submit)
 {
   $title = $_POST['title'];
     $name = $_POST['name'];
   $content = $_POST['content'];



       if(!$content){ 
           echo "Error: News is a required field. Please fill it.";
           exit();
       }


     $result = mysql_query("INSERT INTO news (title, name, dtime, content)
            VALUES ('$title','$name',NOW(),'$content')",$connect);
    
     echo "<b><strong>Thank you! News added Successfully!</strong>";
     // echo "<meta http-equiv=Refresh content=2;url=view.php target='_self'>";
        }

else
        {

?>
<form method="post" action="http://www.somewebsite.com/somewebsite_final/includes/admin/panels/news/add.php">
    Name: <br>
<input name="name" size="40" maxlength="20">
       <br>
    Title:<br>
<input name="title" size="40" maxlength="255">
       <br>
    News: <br>
        <input onClick="document.form.news.value+='[b][/b]'" type="button" value="Bold">
        <input onClick="document.form.news.value+='[i][/i]'" type="button" value="Italic">
        <input onClick="document.form.news.value+='[u][/u]'" type="button" value="Underlined">
        <input onClick="document.form.news.value+='[img src=http://]'" type="button" value="Image">
        <input onClick="document.form.news.value+='[url=http://]Link[/url]'" type="button" value="URL">
        <br />
        <a href="javascript:;" onClick="document.form.news.value+=':@'"><img src="images/smilies/angry.gif" alt=":@" height="15" width="15" /></a>
        <a href="javascript:;" onClick="document.form.news.value+=':D'"><img src="images/smilies/biggrin.gif" alt=":D" height="15" width="15" /></a>
        <a href="javascript:;" onClick="document.form.news.value+=':S'"><img src="images/smilies/confused.gif" alt=":S" height="15" width="15" /></a>
        <a href="javascript:;" onClick="document.form.news.value+='B)'"><img src="images/smilies/cool.gif" alt="B)" height="15" width="15" /></a>
        <a href="javascript:;" onClick="document.form.news.value+=':)'"><img src="images/smilies/happy.gif" alt=":)" height="15" width="15" /></a>
        <a href="javascript:;" onClick="document.form.news.value+=':|'"><img src="images/smilies/mellow.gif" alt=":|" height="15" width="15" /></a>
        <a href="javascript:;" onClick="document.form.news.value+=':('"><img src="images/smilies/sad.gif" alt=":(" height="15" width="15" /></a>
        <a href="javascript:;" onClick="document.form.news.value+=':P'"><img src="images/smilies/tongue.gif" alt=":P" height="15" width="15" /></a>
        <a href="javascript:;" onClick="document.form.news.value+=';)'"><img src="images/smilies/wink.gif" alt=";)" height="15" width="15" /></a><br />
<textarea name="content" rows="15" cols="75"></textarea>
       <br>
<input type="submit" name="submit" value="Add News">
       </form>
<?
        }
//End of Add news 
?>
  1.   <?php
  2. //beginning of Add news
  3. include("../../../../config/config.php");
  4.  if($submit)
  5.  {
  6.    $title = $_POST['title'];
  7.      $name = $_POST['name'];
  8.    $content = $_POST['content'];
  9.        if(!$content){ 
  10.            echo "Error: News is a required field. Please fill it.";
  11.            exit();
  12.        }
  13.      $result = mysql_query("INSERT INTO news (title, name, dtime, content)
  14.             VALUES ('$title','$name',NOW(),'$content')",$connect);
  15.     
  16.      echo "<b><strong>Thank you! News added Successfully!</strong>";
  17.      // echo "<meta http-equiv=Refresh content=2;url=view.php target='_self'>";
  18.         }
  19. else
  20.         {
  21. ?>
  22. <form method="post" action="http://www.somewebsite.com/somewebsite_final/includes/admin/panels/news/add.php">
  23.     Name: <br>
  24. <input name="name" size="40" maxlength="20">
  25.        <br>
  26.     Title:<br>
  27. <input name="title" size="40" maxlength="255">
  28.        <br>
  29.     News: <br>
  30.         <input onClick="document.form.news.value+='[b][/b]'" type="button" value="Bold">
  31.         <input onClick="document.form.news.value+='[i][/i]'" type="button" value="Italic">
  32.         <input onClick="document.form.news.value+='[u][/u]'" type="button" value="Underlined">
  33.         <input onClick="document.form.news.value+='[img src=http://]'" type="button" value="Image">
  34.         <input onClick="document.form.news.value+='[url=http://]Link[/url]'" type="button" value="URL">
  35.         <br />
  36.         <a href="javascript:;" onClick="document.form.news.value+=':@'"><img src="images/smilies/angry.gif" alt=":@" height="15" width="15" /></a>
  37.         <a href="javascript:;" onClick="document.form.news.value+=':D'"><img src="images/smilies/biggrin.gif" alt=":D" height="15" width="15" /></a>
  38.         <a href="javascript:;" onClick="document.form.news.value+=':S'"><img src="images/smilies/confused.gif" alt=":S" height="15" width="15" /></a>
  39.         <a href="javascript:;" onClick="document.form.news.value+='B)'"><img src="images/smilies/cool.gif" alt="B)" height="15" width="15" /></a>
  40.         <a href="javascript:;" onClick="document.form.news.value+=':)'"><img src="images/smilies/happy.gif" alt=":)" height="15" width="15" /></a>
  41.         <a href="javascript:;" onClick="document.form.news.value+=':|'"><img src="images/smilies/mellow.gif" alt=":|" height="15" width="15" /></a>
  42.         <a href="javascript:;" onClick="document.form.news.value+=':('"><img src="images/smilies/sad.gif" alt=":(" height="15" width="15" /></a>
  43.         <a href="javascript:;" onClick="document.form.news.value+=':P'"><img src="images/smilies/tongue.gif" alt=":P" height="15" width="15" /></a>
  44.         <a href="javascript:;" onClick="document.form.news.value+=';)'"><img src="images/smilies/wink.gif" alt=";)" height="15" width="15" /></a><br />
  45. <textarea name="content" rows="15" cols="75"></textarea>
  46.        <br>
  47. <input type="submit" name="submit" value="Add News">
  48.        </form>
  49. <?
  50.         }
  51. //End of Add news 
  52. ?>
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post October 10th, 2005, 3:40 pm

Where is $submit defined ?
Does the form display when it "just shows index.php when pressing submit" ?
What's index.php look like ?
Strong with this one, the sudo is.
  • 74123
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 06, 2005
  • Posts: 190
  • Status: Offline

Post October 10th, 2005, 5:05 pm

1) <input type="submit" name="submit" value="Add News">

2) No, it shows the news (as defaults). It doesnt display "Thank you! News added Successfully!" Like it should.

Index.php is:
Code: [ Select ]
<?
    switch($content) {
        case "index":
        include ("includes/news/index.php");
        break;
        case "admin":
        include ("includes/admin/index.php");
        break;
        case "hand_of_choice":
        include ("includes/hand_of_choice/index.php");
        break;
        case "handhistory":
        include ("includes/handhistory/index.php");
        break;
        case "way_to_vegas":
        include ("includes/way_to_vegas/index.php");
        break;
        case "*plum*":
        include ("includes/*plum*/index.php");
        break;
        case "forum":
        include ("includes/forum/index.php");
        break;
        case "donations":
        include ("includes/donations/index.php");
        break;
        case "contact":
        include ("includes/contact/index.php");
        break;
        case "challenge":
        include ("includes/challenge/index.php");
        break;
        case "join":
        include ("includes/join/index.php");
        break;
        case "showhand":
        include ("includes/showhand/index.php");
        break;
        default:
        include ("includes/news/index.php");
        break;
    }

?>
  1. <?
  2.     switch($content) {
  3.         case "index":
  4.         include ("includes/news/index.php");
  5.         break;
  6.         case "admin":
  7.         include ("includes/admin/index.php");
  8.         break;
  9.         case "hand_of_choice":
  10.         include ("includes/hand_of_choice/index.php");
  11.         break;
  12.         case "handhistory":
  13.         include ("includes/handhistory/index.php");
  14.         break;
  15.         case "way_to_vegas":
  16.         include ("includes/way_to_vegas/index.php");
  17.         break;
  18.         case "*plum*":
  19.         include ("includes/*plum*/index.php");
  20.         break;
  21.         case "forum":
  22.         include ("includes/forum/index.php");
  23.         break;
  24.         case "donations":
  25.         include ("includes/donations/index.php");
  26.         break;
  27.         case "contact":
  28.         include ("includes/contact/index.php");
  29.         break;
  30.         case "challenge":
  31.         include ("includes/challenge/index.php");
  32.         break;
  33.         case "join":
  34.         include ("includes/join/index.php");
  35.         break;
  36.         case "showhand":
  37.         include ("includes/showhand/index.php");
  38.         break;
  39.         default:
  40.         include ("includes/news/index.php");
  41.         break;
  42.     }
  43. ?>


Of course it also has the gfx and html.
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post October 10th, 2005, 8:31 pm

In the form,
The first one you posted
Use this action.
Code: [ Select ]
action="<?php echo $_SERVER['PHP_SELF'] . '?content=admin&section=panel&edit=news&action=add'; ?>"


In "index.php"
Before the switch
Add this,
Code: [ Select ]
$submit = false;
$content = false;
$section = false;
$edit = false;
$action = false;
if(!empty($_POST['submit']))
{
    $submit = $_POST['submit'];
}
if(!empty($_GET['content']))
{
    $content = $_GET['content'];
}
if(!empty($_GET['section']))
{
    $section = $_GET['section'];
}
if(!empty($_GET['edit']))
{
    $edit = $_GET['edit'];
}
if(!empty($_GET['action']))
{
    $action = $_GET['action'];
}
  1. $submit = false;
  2. $content = false;
  3. $section = false;
  4. $edit = false;
  5. $action = false;
  6. if(!empty($_POST['submit']))
  7. {
  8.     $submit = $_POST['submit'];
  9. }
  10. if(!empty($_GET['content']))
  11. {
  12.     $content = $_GET['content'];
  13. }
  14. if(!empty($_GET['section']))
  15. {
  16.     $section = $_GET['section'];
  17. }
  18. if(!empty($_GET['edit']))
  19. {
  20.     $edit = $_GET['edit'];
  21. }
  22. if(!empty($_GET['action']))
  23. {
  24.     $action = $_GET['action'];
  25. }


That should at least get you into includes/admin/index.php if not through the entire script.
Strong with this one, the sudo is.
  • 74123
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 06, 2005
  • Posts: 190
  • Status: Offline

Post October 10th, 2005, 9:57 pm

It works, thanks a lot! This is a great help =)
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13458
  • Loc: Florida
  • Status: Offline

Post October 10th, 2005, 10:20 pm

Glad it works, just make sure your variables are going through security checks later on (if not in that addition) and do me a favor, don't start new topics on the same issue like this anymore, it gets confusing. Posting to the original thread with tales of your progress makes things much easier.
Strong with this one, the sudo is.
  • 74123
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 06, 2005
  • Posts: 190
  • Status: Offline

Post October 11th, 2005, 8:31 pm

I googled security checks and the results I recieved were a bit confusing. What do you mean exactly?

I have moved the website to a different server and now when I click on the link to edit the contents, it doesnt work. It just reloads and shows the list of things that I can edit. Does the server need to have something enabled for it to work?
  • Funny_Fuzz
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Jan 18, 2005
  • Posts: 1517
  • Status: Offline

Post October 12th, 2005, 1:34 am

Your code looks different to mine. I use:
PHP Code: [ Select ]
<?=$_SERVER['PHP_SELF']; ?>

Instead of
PHP Code: [ Select ]
<?php echo $_SERVER['PHP_SELF']; ?>

I wonder if that actually makes a difference though...
THE BEST THINGS IN LIFE ARE FREE...
JOIN THE MEDIASHARK COMMUNITY TODAY!

Post Information

  • Total Posts in this topic: 12 posts
  • Users browsing this forum: No registered users and 87 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.