Jump to content

Unable to update MYSQL with PHP


gilgimech

Recommended Posts

Not sure if this should go in this area or MYSQL. If it's in the wrong section, sorry.

 

I cannot update my myqsl database the form I created.

 

the form


<!DOCTYPE html>
<html>
   <head></head>
   <body>
      <form action="../includes/maintenance_on_off2.php" method="$_POST">
<select name="maintonoff">
<option  value="" selected="selected">Select a On/Off</option>
<option value="0">Off</option>
<option value="1">On</option>
</select>
         <input type="submit" name="submit" value="Submit" />
      </form>
   </body>

</html>

 

 

This is the maintenance_on_off2.php script


<?php
$maint_on_off = $_REQUEST['maintonoff'];

$hostname="localhost"; 
$username="user"; 
$password="pass"; 
$database="database";
$tbl_name="table";

// Connect to the database 
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect"); 
@MYSQL_SELECT_DB("$database") OR DIE("Unable to select database");

$query="UPDATE $tbl_name SET on_off='$maint_on_off'"; 

if ($checkresult) echo '<p>update query succeeded'; 
else echo '<p>update query failed';

echo $on_off;
mysql_close();
?>

 

Sometimes it'll echo "update query succeed' and echo the $on_off value, but it won't update the database.

Most of the time it'll fails. It seem kinda random if it succeeds or fails.

 

Link to comment
https://forums.phpfreaks.com/topic/196941-unable-to-update-mysql-with-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.