ShadeSlayer Posted June 15, 2009 Share Posted June 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/ Share on other sites More sharing options...
Jibberish Posted June 15, 2009 Share Posted June 15, 2009 You are checking for the action variable via get, when the form method is post if($_GET['action'] == "add") should be if($_POST['action'] == "add") Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/#findComment-856070 Share on other sites More sharing options...
ToonMariner Posted June 15, 2009 Share Posted June 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/#findComment-856073 Share on other sites More sharing options...
ShadeSlayer Posted June 15, 2009 Author Share Posted June 15, 2009 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 ) Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/#findComment-856228 Share on other sites More sharing options...
PFMaBiSmAd Posted June 15, 2009 Share Posted June 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/#findComment-856230 Share on other sites More sharing options...
ShadeSlayer Posted June 15, 2009 Author Share Posted June 15, 2009 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. Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/#findComment-856671 Share on other sites More sharing options...
ToonMariner Posted June 16, 2009 Share Posted June 16, 2009 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. Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/#findComment-857044 Share on other sites More sharing options...
ShadeSlayer Posted June 16, 2009 Author Share Posted June 16, 2009 I've already done that, and just under that post, I replied with what it did. Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/#findComment-857518 Share on other sites More sharing options...
ToonMariner Posted June 17, 2009 Share Posted June 17, 2009 sorry didn't see it... is that portion of code still in place? if the error processing query is being displayed the if($_POST['do'] == "process") is evaluating to false. Link to comment https://forums.phpfreaks.com/topic/162212-script-not-executing-page-simply-refreshes/#findComment-857798 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.