gilgimech Posted March 30, 2010 Share Posted March 30, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196941-unable-to-update-mysql-with-php/ Share on other sites More sharing options...
Potatis Posted March 30, 2010 Share Posted March 30, 2010 @MYSQL_SELECT_DB("$database") OR DIE("Unable to select database"); Why do you have an @ at the start of the above line? Quote Link to comment https://forums.phpfreaks.com/topic/196941-unable-to-update-mysql-with-php/#findComment-1033961 Share on other sites More sharing options...
trq Posted March 30, 2010 Share Posted March 30, 2010 You need to actually execute your query. See mysql_query. Quote Link to comment https://forums.phpfreaks.com/topic/196941-unable-to-update-mysql-with-php/#findComment-1033963 Share on other sites More sharing options...
oni-kun Posted March 30, 2010 Share Posted March 30, 2010 Most of the time it'll fails It'll always fail. You don't have $checkresult defined as well. $checkresult = mysql_query($query) or die('Cannot execute query'); I believe you wanted. Quote Link to comment https://forums.phpfreaks.com/topic/196941-unable-to-update-mysql-with-php/#findComment-1033964 Share on other sites More sharing options...
gilgimech Posted March 30, 2010 Author Share Posted March 30, 2010 that helped allot. thanks Quote Link to comment https://forums.phpfreaks.com/topic/196941-unable-to-update-mysql-with-php/#findComment-1034351 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.