Jump to content

[SOLVED] $_POST variable not updating mysql table


rubing

Recommended Posts

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);
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!!

Link to comment
Share on other sites

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();
}
}
?>

Link to comment
Share on other sites

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.