ballhogjoni Posted January 24, 2007 Share Posted January 24, 2007 I know its kinda sloppy but for some reason I cannot get variables $question4q1,$question4q2,$question4q3,$question4q4,$question4q5 to write to my db. I have echoed these variables below and they show up, so I know that everything on my form page is correct, but I think it has something to do with my query. All my other queries work and write the variables to my db. Please help![code]$fname=$_POST['fname'];$lname=$_POST['lname'];$position=$_POST['position'];$email=$_POST['email'];$state=$_POST['state'];$phone=$_POST['phone'];$question1=$_POST['question1'];$question2=$_POST['question2'];$question2q1=$_POST['question2q1'];$question2q2=$_POST['question2q2'];$question2q3=$_POST['question2q3'];$question2q4=$_POST['question2q4'];$question2q5=$_POST['question2q5'];$question2q6=$_POST['question2q6'];$question3=$_POST['question3'];$question4q1=$_POST['question4q1'];$question4q2=$_POST['question4q2'];$question4q3=$_POST['question4q3'];$question4q4=$_POST['question4q4'];$question4q5=$_POST['question4q5'];$question5q1=$_POST['question5q1'];$question5q2=$_POST['question5q2'];$question5q3=$_POST['question5q3'];$question5q4=$_POST['question5q4'];$question5q5=$_POST['question5q5'];$question5q6=$_POST['question5q6'];$question6=$_POST['question6'];$question7=$_POST['question7'];$question8=$_POST['question8'];$question9=$_POST['question9'];mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query = "INSERT INTO contactinfo VALUES ('','$fname','$lname','$position','$email','$state','$phone')";mysql_query($query);$query1 = "INSERT INTO questions123 VALUES('','$question1','$question2','$question3')";mysql_query($query1);$query2 = "INSERT INTO question4 VALUES ('','$question4q1','$question4q2','$question4q3','$question4q4',$question4q5')";mysql_query($query2);$query3 = "INSERT INTO question5 VALUES ('','$question5q1','$question5q2','$question5q3','$question5q4','$question5q5','$question5q6')";mysql_query($query3);$query4 = "INSERT INTO question6789 VALUES ('','$question6','$question7','$question8','$question9')";mysql_query($query4);$query5 = "INSERT INTO question2checkbox VALUES ('','$question2q1','$question2q2','$question2q3','$question2q4','$question2q5','$question2q6')";mysql_query($query5);mysql_close();?><body bgcolor="#FFFFFF"><table align=center><tr><td>Thank You <?php echo $fname; ?> for Submitting Your Survey. You have also been entered in to win a Lieca Geosystems Total Station or $5,000 Dollars!<p><?php echo $question4q1,$question4q2,$question4q3,$question4q4,$question4q5; ?></td></tr></table></body></html>[/code] Link to comment https://forums.phpfreaks.com/topic/35528-writing-variables-to-my-db/ Share on other sites More sharing options...
Cep Posted January 24, 2007 Share Posted January 24, 2007 I am going to assume that these variables come from checkboxes?oh and noticed this,[code=php:0]$query2 = "INSERT INTO question4 VALUES ('','$question4q1','$question4q2','$question4q3','$question4q4',$question4q5')";[/code]should be[code=php:0]$query2 = "INSERT INTO question4 VALUES ('','$question4q1','$question4q2','$question4q3','$question4q4','$question4q5')";[/code] Link to comment https://forums.phpfreaks.com/topic/35528-writing-variables-to-my-db/#findComment-168193 Share on other sites More sharing options...
ballhogjoni Posted January 24, 2007 Author Share Posted January 24, 2007 I should have expressed that. Actually these variables are from a select field just like the state variable. Link to comment https://forums.phpfreaks.com/topic/35528-writing-variables-to-my-db/#findComment-168201 Share on other sites More sharing options...
ballhogjoni Posted January 24, 2007 Author Share Posted January 24, 2007 anybody? Link to comment https://forums.phpfreaks.com/topic/35528-writing-variables-to-my-db/#findComment-168247 Share on other sites More sharing options...
Cep Posted January 25, 2007 Share Posted January 25, 2007 Did you follow my change above? Link to comment https://forums.phpfreaks.com/topic/35528-writing-variables-to-my-db/#findComment-168818 Share on other sites More sharing options...
boo_lolly Posted January 25, 2007 Share Posted January 25, 2007 make sure to add[code]OR die(mysql_error());[/code]after all of your queries. this will help you diagnose the issue. you also may want to elaborate your query a little bit. for instance, try:[code]$query = "INSERT INTO table_name ('column1', 'column2', 'column3', 'column4') VALUES ('$question1', '$question2', '$question3', '$question4')";mysql_query($query) OR die(mysql_error());[/code][url=http://w3schools.com/php/php_mysql_insert.asp]this[/url] may help, as well. Link to comment https://forums.phpfreaks.com/topic/35528-writing-variables-to-my-db/#findComment-168979 Share on other sites More sharing options...
ballhogjoni Posted January 26, 2007 Author Share Posted January 26, 2007 yes i did thank you! it worked as well. Link to comment https://forums.phpfreaks.com/topic/35528-writing-variables-to-my-db/#findComment-169708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.