skiingguru1611 Posted January 12, 2009 Share Posted January 12, 2009 I am working on some code for my neighbor's camp, but for some reason the code that allows people to update their registration information will not update. <?php mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "UPDATE registration SET playerfirst = '$playerfirst', playerlast = '$playerlast', playeraddress = '$playeraddress', playercity = '$playercity', playerstate = '$playerstate', playerzipcode = '$playerzipcode', guardianphone = '$homephone', guardiancell = '$cellphone', playeremail = '$playeremail', playerage = '$playerage', playerweight = '$playerweight', playerheight = '$playerheight', playergrade = '$playergrade', playerposition = '$playerposition', playerschool'$playerschool', playerlevel = '$playerlevel', playercoach = '$playercoach', playercountry = '$playercountry', roommate = '$roommate', guardianwork = '$workphone', guardianfirst = '$guardianfirst', guardianlast = '$guardianlast', guardianemail = '$guardianemail', emergencyfirst = '$emergencyfirst', emergencylast = '$emergencylast', emergencyhome = '$emergencyhomephone', emergencycell = '$emergencycellphone', emergencyemail = '$emergencyemail' WHERE user = '$user'"; mysql_query($query); mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/ Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Remove the @ symbol, and add die statements to the connect and the query. And please don't put NEEDED ASAP in the title, we are doing this for free and no ones script is more important than the rest Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/#findComment-735704 Share on other sites More sharing options...
awpti Posted January 12, 2009 Share Posted January 12, 2009 Just a little commentary: Don't ever suppress error messages using @. Either write an exception handler or disable the display of errors. The @ slows down the speed of code parsing/lexing in the engine. Plus, it's just bad practice. Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/#findComment-735706 Share on other sites More sharing options...
skiingguru1611 Posted January 12, 2009 Author Share Posted January 12, 2009 Remove the @ symbol, and add die statements to the connect and the query. And please don't put NEEDED ASAP in the title, we are doing this for free and no ones script is more important than the rest Thank You. And I understand that mine is no more important than the others, but my neighbor needs to get it up so people can start registering. And, I've never been very good with die statements. Could you help me out there? Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/#findComment-735707 Share on other sites More sharing options...
skiingguru1611 Posted January 12, 2009 Author Share Posted January 12, 2009 Also, removing the @ didn't make the code execute. Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/#findComment-735708 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 This should show any errors <?php error_reporting(E_ALL); ini_set("display_errors",true); mysql_connect(localhost,$username,$password) or die("Cannot connect to db ".mysql_error()); mysql_select_db($database) or die("Cannot find DB ".mysql_error()); $query = "UPDATE registration SET playerfirst = '$playerfirst', playerlast = '$playerlast', playeraddress = '$playeraddress', playercity = '$playercity', playerstate = '$playerstate', playerzipcode = '$playerzipcode', guardianphone = '$homephone', guardiancell = '$cellphone', playeremail = '$playeremail', playerage = '$playerage', playerweight = '$playerweight', playerheight = '$playerheight', playergrade = '$playergrade', playerposition = '$playerposition', playerschool'$playerschool', playerlevel = '$playerlevel', playercoach = '$playercoach', playercountry = '$playercountry', roommate = '$roommate', guardianwork = '$workphone', guardianfirst = '$guardianfirst', guardianlast = '$guardianlast', guardianemail = '$guardianemail', emergencyfirst = '$emergencyfirst', emergencylast = '$emergencylast', emergencyhome = '$emergencyhomephone', emergencycell = '$emergencycellphone', emergencyemail = '$emergencyemail' WHERE user = '$user'"; mysql_query($query) or die("Cannot run query ".mysql_error()); mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/#findComment-735709 Share on other sites More sharing options...
premiso Posted January 12, 2009 Share Posted January 12, 2009 A few questions, where are those variables coming from? A form? If so you should really be escaping the data with mysql_real_escape_string. You should also access them with $_POST or $_GET. The or die(mysql_error); should be added after the mysql_query click on the links I posted for examples. Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/#findComment-735710 Share on other sites More sharing options...
skiingguru1611 Posted January 12, 2009 Author Share Posted January 12, 2009 A few questions, where are those variables coming from? A form? If so you should really be escaping the data with mysql_real_escape_string. You should also access them with $_POST or $_GET. The or die(mysql_error); should be added after the mysql_query click on the links I posted for examples. Yes, they come from a form, and I use $_POST to retrieve them, and I have a bunch of functions running on them to secure the database. I'll check out the links. Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/#findComment-735712 Share on other sites More sharing options...
skiingguru1611 Posted January 12, 2009 Author Share Posted January 12, 2009 The Error reporting thing helped me out alot. It made me realize there was no "=" at playerlevel = '$playerlevel'. Thank You. My Code now works. I appreciate the help, and again I am sorry for putting the NEEDED ASAP part in the title. It won't happen again. Quote Link to comment https://forums.phpfreaks.com/topic/140585-solved-my-code-wont-update-the-database-needed-asap/#findComment-735717 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.