Jump to content

Recommended Posts

After looking through this code, I couldn't figure out why it doesn't work.

 

Some other forms work just fine, and they aren't written any differently. When I enter the info in this one and click Submit, the page just refreshes, doesn't enter the stuff into the database, and displays a blank form when it refreshes.

 

I've checked this multiple times for open HTML tags, anything that could have made this not work and thus, cannot find a solution.

 

if($_GET['action'] == "add")
{
$output = "\n<form action=\"".$_SERVER['PHP_SELF']."?action=add\" method=\"post\">\n"
         ."<b>Title:</b> <input type=\"text\" name=\"title\" value=\"\" /><br />\n"
         ."<b>Author Name:</b> <input type=\"text\" name=\"creator\" value=\"\" /><br />\n"
         ."<b>Tags:</b> <input type=\"text\" name=\"tags\" value=\"\" /> *separate with commas<br />\n"
 ."<b>Blog Entry:</b><br />\n"
         ."<textarea style=\"width: 100%; height: 150px;\" name=\"body\" value=\"\">\n"
 ."</textarea><br /><br />\n"
 ."<input type=\"hidden\" name=\"do\" value=\"process\" />\n"
 ."<input type=\"submit\" />\n"
 ."</form>\n";
         
if($_POST['do'] == "process")
{
$sql = "INSERT INTO ".TABLE_CONTENT." (title, creator, body, timestamp, tags) VALUES ('".addslashes($_POST['title'])."', '".addslashes($_POST['creator'])."', '".addslashes($_POST['body']).", '".date("U")."', '".addslashes($_POST['tags'])."')";
  if($exe = mysql_query($sql))
  {
  $output = "Content item successfully added. <a href=\"manage.php\">Return to Administration.</a>";
  }
}
}

 

I'd love for you guys to help me, I very much appreciate it.

try printing out the get and post array to sse what is and isn't set prior to the first conditional you in your code.

 

print_r($_GET);

 

print_r($_POST);

 

That will let you know what has and hasn't been set - then you can follow your logic and see whats happening.

No, it should be $_GET['action'] since that's the page that displays the form.

 

I set up the "print_r" code and it displays this on the top once I try to submit the form (note the text there is just jibberish):

 

Array ( [action] => add ) Array ( [title] => fg [creator] => gdfgdf [tags] => [body] => dfgdf [do] => process )

When your query fails, the posted logic just falls through. Why not have an else {} statement to at least tell you that the query failed and then if you use mysql_error() in the else statement you can get php/mysql to tell you why the query failed.

Okay, I've updated the code to this to see where it's going wrong:

 

if($_GET['action'] == "add")
{
$output = "\n<form action=\"".$_SERVER['PHP_SELF']."?action=add\" method=\"post\">\n"
         ."<b>Title:</b> <input type=\"text\" name=\"title\" value=\"\" /><br />\n"
         ."<b>Author Name:</b> <input type=\"text\" name=\"creator\" value=\"\" /><br />\n"
         ."<b>Tags:</b> <input type=\"text\" name=\"tags\" value=\"\" /> *separate with commas<br />\n"
 ."<b>Blog Entry:</b><br />\n"
         ."<textarea style=\"width: 100%; height: 150px;\" name=\"body\" value=\"\">\n"
 ."</textarea><br /><br />\n"
 ."<input type=\"hidden\" name=\"do\" value=\"process\" />\n"
 ."<input type=\"submit\" />\n"
 ."</form>\n";
         
if($_POST['do'] == "process")
{
$sql = "INSERT INTO ".TABLE_CONTENT." (title, creator, body, timestamp, tags) VALUES ('".addslashes($_POST['title'])."', '".addslashes($_POST['creator'])."', '".addslashes($_POST['body']).", '".date("U")."', '".addslashes($_POST['tags'])."')";
  if($exe = mysql_query($sql))
  {
  $output = "Content item successfully added. <a href=\"manage.php\">Return to Administration.</a>";
  }
  else
  {
  $output = mysql_error()."<br />\n";
}
else
{
$output = "Error processing query.<br />\n";
}
}

 

The error that displays when going to "?action=add" is "Error Processing Query", so for some reason, when simply visiting ?action=add, the page still tries to do something with &do=process.

No it shows that error because it is NOT trying to do anything with the POSTED value of 'do'.

 

Again I suggest you print the post and get array prior to that code so you can see what is in them and follow your logic...

 

read my initial post in this thread.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.