Update row from input boxes

I know i must be getting on everyones nerves with these questions but i could do with a bit of help… I’ve built my submissions page that pulls all the submissions from my database. So now i need to get the editing part of my code done.

I’ve started building the page that pulls a specific row from the database and displays all the details in input boxed for editing. The thing is, what would the query look like to update that row in the database with the new data?

All the data has been pulled from the database and is now displaying correctly in the input boxes, it’s just i haven’t ever used update in mysql before. I’m not asking you guys to write the entire thing, maybe just a short example that i could play around with.

Thanks
Andrew

you can use the query such as this…

$q = “UPDATE mytable SET myfield = ‘$myvalue’ WHERE id = ‘$id’”;

Multiple fields are seperated by a comma.

SET myfield1 = ‘$myvalue1’, myfield2 = ‘$myvalue2’, myfield3 = '$myvalue3

So would the following query be valid? The reason i ask, is since i changed the query on one of my pages it has decided not to load. Is there a tool to check the validity of a query?

$query = “UPDATE request_data SET ‘$manufaturer’, manufacturer = ‘$model’, model = ‘$capacity’, capacity = ‘$year’, year = ‘$part_one’, part_one = ‘$part_two’, part_two = ‘$part_three’, part_three = ‘$part_four’, part_four = ‘$part_five’, part_five = ‘$full_name’, full_name = ‘$telephone’, telephone = '$alt_telephone ', alt_telehone = ‘$email’, email = ‘$area’, area = ‘$comments’, comments WHERE req_id = $req_id”;

No, that isn’t valid…
Look at what I have and look closely at what you have, I have the field equals the value…

SET myfield = ‘$myvalue’ You have SET $value, field1 = ‘$value2’, field2 = ‘$value3’,… so on and so forth.

– Sounds to me like you need to get some errors turned on…
error_reporting(“E_ALL”); at the very top of your page should help and you would be able to see why the page isn’t loading.

Otherwise I would highly recommend $r = mysql_query($q) or die("Error Updating Table. REASON: " . mysql_error());

Or something similar to this…
The error message can be changed to match whatever it is you are doing with mysql so you know where you are in your script and what is going wrong.

Doh, sorry, should have read your original post thoroughly.

I’ll let you know how i get on. :D

Thanks

Why would this be returning Query Empty errors?

[php]
$dbid = mysql_connect (‘localhost’, ‘database’, ‘password’);
mysql_select_db(‘table’,$dbid)
or die (“Cannot find database”);

  $query = mysql_query("UPDATE request_data SET manufacturer='$manufaturer', model=$model, capacity='$capacity', year='$year', part_one='$part_one', part_two='$part_two', part_three='$part_three', part_four='$part_four', part_five='$part_five', full_name='$full_name', telephone='$telephone', alt_telehone='$alt_telephone', email='$email', area='$area', comments='$comments' WHERE req_id='$req_id'");	  
     $result = mysql_query($query,$dbid) 
     	     or die("Update error:".mysql_error());
 	 
  // If all is cool, this will redirect to a thank you page.
    header('Location: http://www.website.co.uk/submissions.php');
    exit;

[/php]

What’s the exact error look like? They usually give you a hint or two.

$query = mysql_query("UPDATE request_data SET…

There is a problem here… You are simply setting a variable. You don’t want to be actually querying the database yet.

$query = "UPDATE request_data SET…

That is what it should look like.

Sponsor our Newsletter | Privacy Policy | Terms of Service