coalduststar Posted November 23, 2010 Share Posted November 23, 2010 Hi I'm trying to update a form to a mysql database- it's simply all text fields except for one integer which is the primar key (auto increment etc) http://www.arts.ulster.ac.uk/interviews/test.php http://www.arts.ulster.ac.uk/interviews/thanks3.php test.php holds the form and the recaptcha which all seems to be fine and it posts to thanks3.php which (when i switched to $_GET) is passing the variables to that page but those values are not being stored. I then input my query into the mySQL query browser: INSERT INTO UCASinterviews VALUES ('','$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents'); which updated the values i put in but gave this error: Incorrect integer value: '' for column 'ID' at row 1 thanks3.php just won't transfer that info to the table no matter what I try. I used $_GET, I used PHP_SELF, I stripped the rest of the page away to make sure nothing was conflicting and now I'm totally stumped- please could someone look at this with fresh eyes? test.php: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <form action="thanks3.php" method="post" id="form2" style="margin-left:15px; display:;"> <dl id="contform"> <dd><label>Name:</label><br /> <input class="padform" type="text" name="name" size="43" maxlength="20" tabindex="2"/></dd> <label>UCAS ID:</label><br /> <input class="padform" name="UCAS" type="text" id="UCAS" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Email:</label><br /> <input class="padform" name="email" type="text" id="email" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Mobile:</label><br /> <input class="padform" name="mob" type="text" id="mob" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Landline:</label><br /> <input class="padform" name="tel" type="text" id="tel" tabindex="3" size="43" maxlength="30"/></dd> <dd> <label>Subject:</label><br /> <select name="subject" tabindex="1" class="padform"> <option value="English">English</option> <option value="European Studies">European Studies</option> <option selected value="Film Studies">Film Studies</option> <option value="French">French</option> <option value="German">German</option> <option value="History">History</option> <option value="Irish">Irish</option> <option value="Spanish">Spanish</option> <option value="Journalism">Journalism</option> <option value="Photo Imaging">Photo Imaging</option> <option value="Media Studies and Production">Media Studies & Production</option> <option value="Interactive Media Arts">Interactive Media Arts</option> </select></dd> <dd><label>Address:</label><br /> <textarea class="padform"name="address" cols="40" rows="15" id="address" tabindex="5"/> </textarea></dd> <dd> <label>Preferred Interview Date:</label> <select name="interviewdate" class="padform"> <option value="26/02/11">26 February 2011</option> <option selected value="12/03/11">12 March 2011</option> </select> </dd> <dd> <label>Preferred Interview Time:</label> <select name="interviewtime" class="padform"> <option value="AM">Morning (AM)</option> <option selected value="PM">Afternoon (PM)</option> </select> </dd> <dd> <label>Parents/Guardians:</label> <select name="parents" class="padform"> <option value="1">1</option> <option selected value="2">2</option> </select> </dd> <dd> <p> <?php require_once('recaptcha/recaptchalib.php'); $publickey = "6LdU2b4SAAAAAGsh6Z78HjunUL6Mt-ZqCXtIimOs"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> </p> </dd> <dd style="background:none;"><input class="btn" type="submit" name="submit" value="Send" tabindex="6" id="submit" /></dd> </dl> </form> </div> </body> </html> thanks3.php <?php require_once('recaptcha/recaptchalib.php'); $privatekey = "6LdU2b4SAAAAAN_Z9rLyvle0vb4n4EbyAVyXDa6V"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification require_once("../includes/db_connect.php"); if($_POST['submit']=="true"){ $name=$_POST['name']; $address=$_POST['address']; $UCAS=$_POST['UCAS']; $mobile=$_POST['mob']; $email=$_POST['email']; $tel=$_POST['tel']; $subject=$_POST['subject']; $interviewdate=$_POST['interviewdate']; $interviewtime=$_POST['interviewtime']; $parents=$_POST['parents']; $addEntry="INSERT INTO UCASinterviews VALUES ('','$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents');"; $addResult=mysql_query($addEntry,$db); } } ?> I have other forms working with this near enough the same structure/layout/code - i'm ready to have a coronary! Is it the database setup? It's same as it ever was myISAM, UTF unicode... [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/ Share on other sites More sharing options...
robert_gsfame Posted November 23, 2010 Share Posted November 23, 2010 Incorrect integer value: '' for column 'ID' at row 1 Did u set ID column as autoincrement INT?? if yes then you have to modify the query and specify each column INSERT INTO UCASinterviews(name,address,address,UCAS,telephone,email,mobile,subject,interviewdate,interviewtime)VALUES ('$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents'); hope that will solve the problem Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138506 Share on other sites More sharing options...
merylvingien Posted November 23, 2010 Share Posted November 23, 2010 Is this supposed to update info thats already in the database or add new info? insert into database will add another row update set will overwrite existing data Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138510 Share on other sites More sharing options...
coalduststar Posted November 23, 2010 Author Share Posted November 23, 2010 Hi - thanks for the replies but unfortunately that didn't work. It's meant just to add another record everytime, not update an existing one. This is what I attempted: <?php require_once('recaptcha/recaptchalib.php'); $privatekey = "6LdU2b4SAAAAAN_Z9rLyvle0vb4n4EbyAVyXDa6V"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification require_once("../includes/db_connect.php"); if($_POST['submit']=="true"){ $name=$_POST['name']; $address=$_POST['address']; $UCAS=$_POST['UCAS']; $mobile=$_POST['mob']; $email=$_POST['email']; $tel=$_POST['tel']; $subject=$_POST['subject']; $interviewdate=$_POST['interviewdate']; $interviewtime=$_POST['interviewtime']; $parents=$_POST['parents']; $addEntry="INSERT INTO UCASinterviews(name,address,UCAS,tel,email,mob,subject,interviewdate,interviewtime,parents)VALUES('$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents');"; $addResult=mysql_query($addEntry,$db); } } ?> Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138511 Share on other sites More sharing options...
Pikachu2000 Posted November 23, 2010 Share Posted November 23, 2010 Echo the query string and make sure the values are what you expect them to be. Then paste it in to phpMyAdmin and see if it executes that way. $addEntry="INSERT INTO UCASinterviews(name,address,UCAS,tel,email,mob,subject,interviewdate,interviewtime,parents)VALUES('$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents');"; //$addResult=mysql_query($addEntry,$db); echo $addEntry; Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138513 Share on other sites More sharing options...
robert_gsfame Posted November 23, 2010 Share Posted November 23, 2010 If i am not wrong, you must set mob column NOT NULL this might be the problem, you are not correctly insert the record $mobile=$_POST['mob']; VALUES('$name','$address','$UCAS','$tel','$email','$mob' see the bold one Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138515 Share on other sites More sharing options...
litebearer Posted November 23, 2010 Share Posted November 23, 2010 Old man rambling (been know to be wrong more times than right)... in your form... name="submit" value="Send" in your thanks3 if($_POST['submit']=="true"){ (Hopefully Pika will correct me if wrong) Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138516 Share on other sites More sharing options...
coalduststar Posted November 23, 2010 Author Share Posted November 23, 2010 Query string is getting passed to the thanks3.php and being lost before the INSERT somehow. It won't echo the variables but if I use $_GET, they appear as they should in the query string in the top of the browser. @robert_gsfame - well spotted but that doesn't seem to have changed anything @ litebearer- tried this too- doesn't seem to have any bearing :/ Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138521 Share on other sites More sharing options...
Pikachu2000 Posted November 23, 2010 Share Posted November 23, 2010 Old man rambling (been know to be wrong more times than right)... in your form... name="submit" value="Send" in your thanks3 if($_POST['submit']=="true"){ (Hopefully Pika will correct me if wrong) Good catch, and it also brings up another point. How is it possible that the query is even executing, since it's in a conditional that can't possibly evaluate to TRUE? Are you sure you're editing/uploading the correct file? Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138524 Share on other sites More sharing options...
robert_gsfame Posted November 23, 2010 Share Posted November 23, 2010 if($_POST['submit']=="true") have u tried if(isset($_POST['submit'])) ?? Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138525 Share on other sites More sharing options...
coalduststar Posted November 23, 2010 Author Share Posted November 23, 2010 You, my friend are a hero- it's passing everything through now but it's leaving out the "address" field :/ For want of sounding thick- at this point i don't care- Why did that make it work? (and thanks) Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138530 Share on other sites More sharing options...
robert_gsfame Posted November 23, 2010 Share Posted November 23, 2010 <textarea class="padform"name="address" cols="40" rows="15" id="address" tabindex="5"/> move that name a bit <textarea class="padform" name="address" cols="40" rows="15" id="address" tabindex="5"/> Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138531 Share on other sites More sharing options...
coalduststar Posted November 23, 2010 Author Share Posted November 23, 2010 that didn't solve it- the spelling is consistent so it can't be that- i'll have another wee look at the database... <?php require_once('recaptcha/recaptchalib.php'); $privatekey = "6LdU2b4SAAAAAN_Z9rLyvle0vb4n4EbyAVyXDa6V"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification require_once("../includes/db_connect.php"); if(isset($_POST['Send'])){ $name=$_POST['name']; $address=$_POST['address']; $UCAS=$_POST['UCAS']; $mob=$_POST['mob']; $email=$_POST['email']; $tel=$_POST['tel']; $subject=$_POST['subject']; $interviewdate=$_POST['interviewdate']; $interviewtime=$_POST['interviewtime']; $parents=$_POST['parents']; $addEntry="INSERT INTO UCASinterviews(name,address,UCAS,tel,email,mob,subject,interviewdate,interviewtime,parents)VALUES('$name','$address','$UCAS','$tel','$email','$mob','$subject','$interviewdate','$interviewtime','$parents');"; $addResult=mysql_query($addEntry,$db); } } ?> Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138535 Share on other sites More sharing options...
coalduststar Posted November 23, 2010 Author Share Posted November 23, 2010 is "address" a reserved term? Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138536 Share on other sites More sharing options...
Pikachu2000 Posted November 23, 2010 Share Posted November 23, 2010 if(isset($_POST['Send'])){ should probably be if(isset($_POST['submit'])){ Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138539 Share on other sites More sharing options...
robert_gsfame Posted November 23, 2010 Share Posted November 23, 2010 okay lets try this way instead of having this <textarea class="padform" name="address" cols="40" rows="15" id="address" tabindex="5"/> change the order into this <textarea name="address" id="address" cols="40" rows="15" tabindex="5" class="padform"/> Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138540 Share on other sites More sharing options...
litebearer Posted November 23, 2010 Share Posted November 23, 2010 also do a simple check of the variable echo $address=$_POST['address']; Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138544 Share on other sites More sharing options...
coalduststar Posted November 24, 2010 Author Share Posted November 24, 2010 Hi - the address was passing in but the textarea was padded in and it wasn't appearing in my query browser window :/ You've all been pretty much fantastic help- thanks!! Link to comment https://forums.phpfreaks.com/topic/219594-utterly-baffled-update-a-table/#findComment-1138908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.