简体   繁体   中英

Update existing mysql record using php

Trying to update existing records in phpMyAdmin, but the following code doesn't seem to be working.

<?php 
$id = stripslashes($_POST['id']);

$title = stripslashes($_POST['title']);
$first = stripslashes($_POST['first']);
$surname = stripslashes($_POST['surname']);
$email = stripslashes($_POST['email']);
$promotion = stripslashes($_POST['promotion']);

$maths11 = stripslashes($_POST['maths11']);
$english11 = stripslashes($_POST['english11']);
$english13 = stripslashes($_POST['english13']);
$science13 = stripslashes($_POST['science13']);
$maths133 = stripslashes($_POST['maths133']);
$maths132 = stripslashes($_POST['maths132']);

$address = stripslashes($_POST['address']);
$address2 = stripslashes($_POST['address2']);
$town = stripslashes($_POST['town']);
$county = stripslashes($_POST['county']);
$code = stripslashes($_POST['code']);
$tel = stripslashes($_POST['tel']);

//database connection

$query="UPDATE Promotions SET address='$address', address2='$address2', town='$town', county='$county', postcode='$code', tel='$tel' WHERE id = '$id'";
mysql_query($query) or die(mysql_error());


include 'confirm.php';
include 'registerEmail.php';
?>

Any help? Thanks

Instead of rather useless die ('Error updating database'); handle your errors in more informative way

mysql_query($query) or trigger_error(mysql_error().' in '.$query);

and read what it says

Use mysql_error() like Col. Shrapnel showed.

But what troubles me ... Is that all the code for that page? Because you have //database connection but I don't see any database connection. Are you sure you are connecting to your database and included that connection in your file?

EDIT:

what does your query look like when you echo it? maybe the id is empty ... that way you can see what exactly is going to be send to the db

echo $query;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM