Jump to content

Recommended Posts

	mysql_query("UPDATE customer 
	SET customer_firstname = `$_POST[customerupdate_firstname]`, 
	customer_lastname = `$_POST[customerupdate_lastname]`, 
	customer_address1 = `$_POST[customerupdate_address1]`, 
	customer_address2 = `$_POST[customerupdate_address2]`, 
	customer_postcode = `$_POST[customerupdate_postcode]`, 
	customer_dob = `$_POST[customer_dob]`, 
	customer_email = `$_POST[customerupdate_email]`, 
	customer_tel = `$_POST[customerupdate_tel]` 
	WHERE customer_id = `$_POST[customerupdate_id]`");

 

Whats wrong with that?

Link to comment
https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/
Share on other sites

Now I have the following and it's still not working:

 

mysql_query("UPDATE customer 
	SET customer_firstname = '$_POST[customerupdate_firstname]', 
	customer_lastname = '$_POST[customerupdate_lastname]', 
	customer_address1 = '$_POST[customerupdate_address1]', 
	customer_address2 = '$_POST[customerupdate_address2]', 
	customer_postcode = '$_POST[customerupdate_postcode]', 
	customer_dob = '$_POST[customer_dob]', 
	customer_email = '$_POST[customerupdate_email]', 
	customer_tel = '$_POST[customerupdate_tel]' 
	WHERE customer_id = '$_POST[customerupdate_id]'");

You need to have a container("", or '') around the $_POST value:

 

mysql_query("UPDATE customer 
	SET customer_firstname = '$_POST["customerupdate_firstname"]', 
	customer_lastname = '$_POST["customerupdate_lastname"]', 
	customer_address1 = '$_POST["customerupdate_address1"]', 
	customer_address2 = '$_POST["customerupdate_address2"]', 
	customer_postcode = '$_POST["customerupdate_postcode"]', 
	customer_dob = '$_POST["customer_dob"]', 
	customer_email = '$_POST["customerupdate_email"]', 
	customer_tel = '$_POST["customerupdate_tel"]' 
	WHERE customer_id = '$_POST["customerupdate_id"]'");

add some debugging...MySQL will tell you the problem:

mysql_query("UPDATE customer 
SET customer_firstname = '$_POST[customerupdate_firstname]', 
customer_lastname = '$_POST[customerupdate_lastname]', 
customer_address1 = '$_POST[customerupdate_address1]', 
customer_address2 = '$_POST[customerupdate_address2]', 
customer_postcode = '$_POST[customerupdate_postcode]', 
customer_dob = '$_POST[customer_dob]', 
customer_email = '$_POST[customerupdate_email]', 
customer_tel = '$_POST[customerupdate_tel]' 
WHERE customer_id = '$_POST[customerupdate_id]'") or die(mysql_error());

 

p.s. - whenever you are debugging a MySQL problem....step 1 is to make sure you echo out mysql_error(). if that isn't helpful, echo out the generated SQL and make sure all the values are inserting as you are expecting them to.

Maybe it'll help if I post my form:

 

<br />

<form name="updatecustomer" method="POST" action="customer.php?module=update">
<input type="hidden" name="module" value="update" />

Customer ID: <br />
<input type="text" name="customerupdate_id" id="customerupdate_firstname" disabled="disabled" value="<? echo $row['customer_id']; ?>">

<br /><br />

First Name: <br />
<input type="text" name="customerupdate_firstname" id="customerupdate_firstname" value="<? echo $row['customer_firstname']; ?>">

<br /><br />

Surname: <br />
<input type="text" name="customerupdate_surname" id="customerupdate_surname" value="<? echo $row['customer_lastname']; ?>">

<br /><br />

Address Line 1: <br />
<input type="text" name="customerupdate_address1" id="customerupdate_address1" value="<? echo $row['customer_address1']; ?>">

<br /><br />

Address Line 2: <br />
<input type="text" name="customerupdate_address2" id="customerupdate_address2"  value="<? echo $row['customer_address2']; ?>">

<br /><br />

Postcode: <br />
<input type="text" name="customerupdate_postcode" id="customerupdate_postcode" value="<? echo $row['customer_postcode']; ?>">

<br /><br />

Date of Birth <b>(YYYY-MM-DD)</b>: <br />
<input type="text" name="customerupdate_dob" id="customerupdate_dob" value="<? echo $row['customer_dob']; ?>">

<br /><br />

E-mail: <br />
<input type="text" name="customerupdate_email" id="customerupdate_email" value="<? echo $row['customer_email']; ?>">

<br /><br />

Telephone: <br />
<input type="text" name="customerupdate_tel" id="customerupdate_tel" value="<? echo $row['customer_tel']; ?>">

    <input name="submitcustomerupdate" type="submit" value="submit">

</form>

 

and

if($_GET[module] == "update" || isset($_GET['submitcustomerupdate'])) {
	mysql_query("UPDATE customer
		SET customer_firstname = '$_POST[customerupdate_firstname]',
		customer_lastname = '$_POST[customerupdate_lastname]',
		customer_address1 = '$_POST[customerupdate_address1]',
		customer_address2 = '$_POST[customerupdate_address2]',
		customer_postcode = '$_POST[customerupdate_postcode]',
		customer_dob = '$_POST[customer_dob]',
		customer_email = '$_POST[customerupdate_email]',
		customer_tel = '$_POST[customerupdate_tel]'
		WHERE customer_id = '$_POST[customerupdate_id]'") or die(mysql_error());
	}

 

Which gives me: http://i43.tinypic.com/20axus2.jpg

Hi

 

You are mixing $_GET and $_POST.

 

All the best

 

Keith

 

Ah, that is one mistake I didn't notice, I've changed it, but it's still not working...

 

Did you miss my post? Also kickstart is correct, you need to use either $_GET or $_POST.

 

Sorry, I did miss it! But the code you have posted will not work, I can tell just by looking.I already have quatation marks around the entire query, so it will assume it is the end as soon as it comes across the next lot...

you can mix GET and POST...your use of them is fine

 

is it producing an error or just not running the update? if there is an error, what is it?

 

try this:

if($_GET['module'] == "update" || isset($_POST['submitcustomerupdate'])) {
  $sql = printf("UPDATE customer
      SET customer_firstname = '%s',
      customer_lastname = '%s',
      customer_address1 = '%s',
      customer_address2 = '%s',
      customer_postcode = '%s',
      customer_dob = '%s',
      customer_email = '%s',
      customer_tel = '%s'
      WHERE customer_id = '%s'",
    mysql_real_escape_string($_POST['customerupdate_firstname']),
    mysql_real_escape_string($_POST['customerupdate_lastname']),
    mysql_real_escape_string($_POST['customerupdate_address1']),
    mysql_real_escape_string($_POST['customerupdate_address2']),
    mysql_real_escape_string($_POST['customerupdate_postcode']),
    mysql_real_escape_string($_POST['customer_dob']),
    mysql_real_escape_string($_POST['customerupdate_email']),
    mysql_real_escape_string($_POST['customerupdate_tel']),
    mysql_real_escape_string($_POST['customerupdate_id'])
  );
  mysql_query($sql) or die(mysql_error()." Query: $sql");
}

you can mix GET and POST...your use of them is fine

 

is it producing an error or just not running the update? if there is an error, what is it?

 

try this:

if($_GET['module'] == "update" || isset($_POST['submitcustomerupdate'])) {
  $sql = printf("UPDATE customer
      SET customer_firstname = '%s',
      customer_lastname = '%s',
      customer_address1 = '%s',
      customer_address2 = '%s',
      customer_postcode = '%s',
      customer_dob = '%s',
      customer_email = '%s',
      customer_tel = '%s'
      WHERE customer_id = '%s'",
    mysql_real_escape_string($_POST['customerupdate_firstname']),
    mysql_real_escape_string($_POST['customerupdate_lastname']),
    mysql_real_escape_string($_POST['customerupdate_address1']),
    mysql_real_escape_string($_POST['customerupdate_address2']),
    mysql_real_escape_string($_POST['customerupdate_postcode']),
    mysql_real_escape_string($_POST['customer_dob']),
    mysql_real_escape_string($_POST['customerupdate_email']),
    mysql_real_escape_string($_POST['customerupdate_tel']),
    mysql_real_escape_string($_POST['customerupdate_id'])
  );
  mysql_query($sql) or die(mysql_error()." Query: $sql");
}

 

That gives me the following:

 

UPDATE customer SET customer_firstname = 'Johm', customer_lastname = 'Hodges', customer_address1 = '122 Union Lane', customer_address2 = 'Chesterton', customer_postcode = 'CB4 1QB', customer_dob = '', customer_email = 'aaron@themungo.com', customer_tel = '07751224346' WHERE customer_id = ''You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '354' at line 1 Query: 354

sorry thinking cap was off. The correct format would be this:

 


customer_firstname = '".$_POST["customerupdate_firstname"]."'

 

Thats just one example. you will have to change them all.

 

I have use queries such as mysql_query("SELECT * FROM customer WHERE '$_GET[customerupdate_id]' = customer_id"); without problem in the past, I dont think thats the problem at all.

I didnt necessarily say that it was your only problem but you should always use the correct syntax when coding. Look around the forums and you will see that 9 out of 10 use either '' or "" around the $_POST. Obviously you dont care about doing it the right way just the fast way so good luck

first...to settle this..you should ALWAYS use single or double quotes around your array keys. if you don't, you are actually calling the constant, which since the constant isn't defined it returns the name back. while it may work, you will get NOTICES if you have them on and then there is the case where your array key is actually a constant, which will mess everything up.

 

anyways...Mundo...change printf() to sprintf() and try again...sorry

first...to settle this..you should ALWAYS use single or double quotes around your array keys. if you don't, you are actually calling the constant, which since the constant isn't defined it returns the name back. while it may work, you will get NOTICES if you have them on and then there is the case where your array key is actually a constant, which will mess everything up.

 

anyways...Mundo...change printf() to sprintf() and try again...sorry

 

Thank you for clearing that up for him

actually...looking at it again...it seems like $_POST['customerupdate_id'] doesn't have a value...so i jumped to your form, and notice you have the value in a disabled element. disabled elements aren't passed with the data. make it a hidden element, remove the disabled part, and just print the customer id

actually...looking at it again...it seems like $_POST['customerupdate_id'] doesn't have a value...so i jumped to your form, and notice you have the value in a disabled element. disabled elements aren't passed with the data. make it a hidden element, remove the disabled part, and just print the customer id

 

Yeh I just noticed this! I still wanted it to be visable but not editable, it's a shame I can't use the disabled attribute.

Yeah me too, thats why I was trying to get him to put them in there but it just makes me laugh when someone comes here for help and you try to help them and they try to tell you that your wrong. I just think to myself well if you knew how to do it you wouldnt be here lol.

first...to settle this..you should ALWAYS use single or double quotes around your array keys. if you don't, you are actually calling the constant, which since the constant isn't defined it returns the name back. while it may work, you will get NOTICES if you have them on and then there is the case where your array key is actually a constant, which will mess everything up.

 

anyways...Mundo...change printf() to sprintf() and try again...sorry

 

sprintf fixed everything, thanks!

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.