lpollard Posted October 1, 2011 Share Posted October 1, 2011 Hello all, I have tried the following syntax to update a record from the $_POST method, and I cannot get it to update the record. Can anyone spot where I'm going wrong in my code <?php $idstudent = $_POST["idstudent"]; $childname = $_POST["childname"]; $parentname = $_POST["parentname"]; $dated = $_POST["dated"]; $datem = $_POST["datem"]; $datey = $_POST["datey"]; $dob = $datey ."-". $datem ."-".$dated; $age = $_POST["age"]; $lastupdate = date("Y\-m\-d"); $gender = $_POST["gender"]; $address1 = $_POST["address1"]; $address2= $_POST["address2"]; $city = $_POST["city"]; $postcode = $_POST["postcode"]; $phone = $_POST["phone"]; $mobile = $_POST["mobile"]; $email = $_POST["email"]; $pass= $_POST["password"]; $height = $_POST["height"]; $neck = $_POST["neck"]; $chest = $_POST["chest"]; $hips = $_POST["hips"]; $waist = $_POST["waist"]; $insideleg = $_POST["insideleg"]; $dress = $_POST["dress"]; $shoe = $_POST["shoes"]; $haircolour = $_POST["haircolour"]; $hairlength = $_POST["hairstyle"]; $eyes = $_POST["eyecolour"]; $ethnicity = $_POST["ethnicity"]; $image = $_POST["image"]; $approve = "0"; $actor = $_POST["actor"]; $standin = $_POST["standin"]; $voiceover = $_POST["voiceover"]; $stagecombat = $_POST["stagecombat"]; $daballet = $_POST["daballet"]; $dasalsa = $_POST["dasalsa"]; $dabreak = $_POST["dabreak"]; $dadisco = $_POST["dadisco"]; $dahiphop = $_POST["dahiphop"]; $dajazz = $_POST["dajazz"]; $damodern = $_POST["damodern"]; $dastreet = $_POST["dastreet"]; $datap = $_POST["datap"]; $dacontemp = $_POST["dacontemp"]; $dafreestyle = $_POST["dafreestyle"]; $daswing = $_POST["daswing"]; $dawaltz = $_POST["dawaltz"]; include ('../../source/db_config.php'); $db = mysql_connect($host,$username,$password) or die(mysql_error()); mysql_select_db($database, $db) or die(mysql_error()); $update = "UPDATE 'students' SET 'childname'='$childname', 'parentname'='$parentname', 'dob'='$dob', 'age'='$age', 'lastupdate'='$lastupdate', 'gender'='$gender', 'address1'='$address1', 'address2'='$address2', 'city'='$city', 'postcode'='$postcode', 'phone'='$phone', 'mobile'='$mobile', 'email'='$email', 'password'='$pass', 'height'='$height', 'neck'='$neck', 'chest'='$chest', 'hips'='$hips', 'waist'='$waist', 'insideleg'='$insideleg', 'dress'='$dress', 'shoe'='$shoe', 'haircolour'='$haircolour', 'hairlength'='$hairlength', 'eyes'='$eyes', 'ethnicity'='$ethnicity', 'actor'='$actor', 'standin'='$standin', 'stagecombat'='$stagecombat', 'daballet'='$daballet', 'dasalsa'='$dasalsa', 'dabreak'='$dabreak', 'dadisco'='$dadisco', 'dahiphop'='$dahiphop', 'dajazz'='$dajazz', 'damodern'='$damodern', 'dastreet'='$dastreet', 'datap'='$datap', 'dacontemp'='$dacontemp', 'dafreestyle'='$dafreestyle', 'daswing'='$daswing', 'dawaltz'='$dawaltz' WHERE 'id'='$idstudent'"; mysql_query($update); ?> Don't worry about the password either.. it is passed through md5 encryption. But any help will be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/248244-update-phpsql-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 1, 2011 Share Posted October 1, 2011 Table and column names do not get enclosed by single-quotes as that would make them literal string data, not table and column names. Quote Link to comment https://forums.phpfreaks.com/topic/248244-update-phpsql-not-working/#findComment-1274815 Share on other sites More sharing options...
lpollard Posted October 1, 2011 Author Share Posted October 1, 2011 Just tried it removing the quotes around the column and tablename and still no update $update = "UPDATE students SET childname='$childname', parentname='$parentname', dob='$dob', age='$age', etc. Quote Link to comment https://forums.phpfreaks.com/topic/248244-update-phpsql-not-working/#findComment-1274816 Share on other sites More sharing options...
PFMaBiSmAd Posted October 1, 2011 Share Posted October 1, 2011 I would echo the $update variable so that you can proofread it to make sure it contains what you think, such as a valid id value in the where clause. You can also get php/mysql to tell you if/why a query is failing by using mysql_error() - mysql_query($update) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/248244-update-phpsql-not-working/#findComment-1274817 Share on other sites More sharing options...
lpollard Posted October 2, 2011 Author Share Posted October 2, 2011 Ahh thankyou, it returned an unknown field name, and i checked the database and i had put 'dadreestyle' not 'dafreestyle' as a field name. Typo on my behalf. Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/248244-update-phpsql-not-working/#findComment-1274820 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.