Jump to content

[SOLVED] My Code Won't UPDATE the Database -- NEEDED ASAP


skiingguru1611

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.