Jump to content

Writing variables to my db


ballhogjoni

Recommended Posts

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; ?>&nbsp;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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.