rubing Posted April 18, 2008 Share Posted April 18, 2008 I am writing a script that presents an administrator with a page to update some of the system-level variables. First, it checks to see if anything was submitted, if not it presents the option update values of variables. If the admin submits (POST) these values the script then runs a mysql query to update them. Unfortunately, the variables never update, they always stay the same. <?php //if nothing was submitted present the updating form if (!$_POST['submit']) { include "dbinfo.inc"; $query= "SELECT * FROM program_setup"; $program_setup =mysql_query($query); $siteurl = mysql_result($program_setup,0,"siteurl"); echo ' <html><head></head><body> <form action="admin_try1.php" method="post"> <table> <tr> <td>Name: siteurl Description: The complete directory URL to my program: Example: ' . $siteurl . '<br /> <input type="text" name="newsiteurl" size="60" value="' . $siteurl . '"> </tr> <tr> <td> <input type="submit" name="submit" value="Update Setup Variables"> </td> </tr> </table> </table> </form></body> </html>'; } //else if something was submitted, update with the following query: else { include "dbinfo.inc"; $query="UPDATE program_setup SET siteurl={$_POST['newsiteurl']}"; mysql_query($query); } ?> Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 18, 2008 Share Posted April 18, 2008 Try this: <?php //if nothing was submitted present the updating form if (!$_POST['submit']) { include "dbinfo.inc"; $query= "SELECT * FROM program_setup"; $program_setup =mysql_query($query); $siteurl = mysql_result($program_setup,0,"siteurl"); echo ' <html><head></head><body> <form action="admin_try1.php" method="post"> <table> <tr> <td>Name: siteurl Description: The complete directory URL to my program: Example: ' . $siteurl . '<br /> <input type="text" name="newsiteurl" size="60" value="' . $siteurl . '"> </tr> <tr> <td> <input type="submit" name="submit" value="Update Setup Variables"> </td> </tr> </table> </table> </form></body> </html>'; } //else if something was submitted, update with the following query: else { include "dbinfo.inc"; $query="UPDATE `program_setup` SET `siteurl` = '".$_POST['newsiteurl']."'"; mysql_query($query); } ?> I changed the update query to use complete syntax. Quote Link to comment Share on other sites More sharing options...
Zhadus Posted April 18, 2008 Share Posted April 18, 2008 if (!$_POST['submit']) { should be if empty($_POST['newsiteurl']) { Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 18, 2008 Share Posted April 18, 2008 Or isset($_POST['submit']) Quote Link to comment Share on other sites More sharing options...
Zhadus Posted April 18, 2008 Share Posted April 18, 2008 You'd have to use a not (!) operand with isset(). Quote Link to comment Share on other sites More sharing options...
rubing Posted April 18, 2008 Author Share Posted April 18, 2008 I made ALL of the above changes, yet it still doesn't work. It just refuses to update...like I am not changing the variable. Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 18, 2008 Share Posted April 18, 2008 Echo out the generated query and post. Quote Link to comment Share on other sites More sharing options...
rubing Posted April 18, 2008 Author Share Posted April 18, 2008 sorry for my naivete, but how do I echo an UPDATE query ??? Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 18, 2008 Share Posted April 18, 2008 You have this: <?php // Var needs to be cleaned as shown below $newsiteurl = trim(mysql_real_escape_string($_POST['newsiteurl'])); $query="UPDATE `program_setup` SET `siteurl` = '$newsiteurl'"; // then just add echo $query;die(); ?> This way we can make sure the data is ok. Also you need to clean your post vars before running an update. Quote Link to comment Share on other sites More sharing options...
rubing Posted April 18, 2008 Author Share Posted April 18, 2008 OK, so my code looks like this: mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name); $newsiteurl = trim(mysql_real_escape_string($_POST['newsiteurl'])); $query="UPDATE `program_setup` SET `siteurl` = '$newsiteurl'"; mysql_query($query); // then just add echo $query; die(); } ?> I run it and get: UPDATE `program_setup` SET `siteurl` = 'http://www.pleasepleasepleaseupdate.com/' However the value in the database for this cell does not change!! Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 18, 2008 Share Posted April 18, 2008 Try displaying mysql errors: <?php mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name); $newsiteurl = trim(mysql_real_escape_string($_POST['newsiteurl'])); $query="UPDATE `program_setup` SET `siteurl` = '$newsiteurl'"; $run = mysql_query($query); if($run){ echo $query; die(); }else{ echo mysql_error(); die(); } } ?> Quote Link to comment Share on other sites More sharing options...
rubing Posted April 18, 2008 Author Share Posted April 18, 2008 IT WORKS!! I forgot to put back in the real name of my table after I added all of your suggested changes. Thank you so much guys!!! Quote Link to comment Share on other sites More sharing options...
p2grace Posted April 18, 2008 Share Posted April 18, 2008 Good deal Could you mark the topic as solved when you get a chance Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.