ryanfilard Posted April 30, 2011 Share Posted April 30, 2011 I am trying to update a mysql field. I am using this php code all the login info is right and it does not work Table Name: camera Field I Want To Change: public1 //Connect To Database $db_host = "localhost"; $db_name = "mydbname"; $username = "myusername"; $password = "mypassword"; mysql_connect($db_host,$username,$password); mysql_select_db($db_name); $result = mysql_query("UPDATE camera SET public1='2' WHERE cwuser='$user'"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235219-mysql-update-will-not-work/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 30, 2011 Share Posted April 30, 2011 Where in your code are you setting $user to a value? And have you echoed it so that you know it contains the value you expect? Quote Link to comment https://forums.phpfreaks.com/topic/235219-mysql-update-will-not-work/#findComment-1208774 Share on other sites More sharing options...
ryanfilard Posted April 30, 2011 Author Share Posted April 30, 2011 $user is set to $_SESSION['Username'] Quote Link to comment https://forums.phpfreaks.com/topic/235219-mysql-update-will-not-work/#findComment-1208775 Share on other sites More sharing options...
PFMaBiSmAd Posted April 30, 2011 Share Posted April 30, 2011 And are you sure that is working, because in programming, you can not assume anything. You must always check and confirm what something is. Quote Link to comment https://forums.phpfreaks.com/topic/235219-mysql-update-will-not-work/#findComment-1208776 Share on other sites More sharing options...
ryanfilard Posted April 30, 2011 Author Share Posted April 30, 2011 I have checked this here is the full page code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>PRIVATE | CWUFORUM.COM</title> </head> <?php //username $useah = $_SESSION['MM_Username']; $idfree = $_GET['camid3']; //database $db_host = "localhost"; $db_name = "mydb"; $username = "myuser"; $password = "mypass"; //connect mysql_connect($db_host,$username,$password); mysql_select_db($db_name); //Camera View Link ?> <?PHP $result = mysql_query("UPDATE camera SET public1='1' WHERE cwuser='$user'"); ?> <body> <p>Your camera has been made private!</p> <p><a href="index.php">Back</a></p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/235219-mysql-update-will-not-work/#findComment-1208777 Share on other sites More sharing options...
PFMaBiSmAd Posted April 30, 2011 Share Posted April 30, 2011 You cannot be serious. You haven't checked anything. There's no code setting the variable $user. There's also no session_start() statement so no $_SESSION variables exist either. Quote Link to comment https://forums.phpfreaks.com/topic/235219-mysql-update-will-not-work/#findComment-1208778 Share on other sites More sharing options...
ryanfilard Posted April 30, 2011 Author Share Posted April 30, 2011 Thanks so much, I am a starter at php coding Quote Link to comment https://forums.phpfreaks.com/topic/235219-mysql-update-will-not-work/#findComment-1208781 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.