PHP Posting

Soldato
Joined
26 Nov 2005
Posts
3,839
Location
Doon the Bay (Newcastle)
Can't get this to work, could you please take a look:

Connection works fine, table can be retrieved.

$Q2s = @mysql_query( 'SELECT Q2ID, Answer FROM q2');
if (!$Q2s) {
exit ('<p align="center"> Unable to gather data for question 2.</p>');
}



<div align="center">
<form action="questionres.php" method="post">
<fieldset>
<legend>Theia Questionnaire</legend>
</select></label><br />
<label> Q2: What is your secondary use?
<select name="q2id" size="6">
<option selected value=""> Please Select one...</option>

<?php
;
while ($q2 = mysql_fetch_array($Q2s)){
$q2id= $Qq2['id'];
$q2ans = htmlspecialchars($q2['Answer']);
echo "<option value='$q2id'>$q2ans</option>\n";
}
?>



<?php
$Q2s = $_POST['Answer'];
?>


<?php
$sql="INSERT INTO Savedq SET Q2s = '".$_POST['Answer']."'";
mysql_query($sql) or die("Could not process $sql");
?>


Error message: Could not process INSERT INTO Savedq SET Q2s = ''
 
Try:
$sql='INSERT INTO Savedq (Q2s) VALUES ('.$_POST['Answer'].')';

You might want to escape your inputs though.
 
Still not working, though is there a way i can check my post is carrying across as in echoing the data in $Q2s = $_POST['Answer'];?

Cheers
 
Getting a bit further forward, at least i now know the post is bringing in the data.

<?php
$q12id = $_POST['q12id'];
$q2id = $_POST['q2id'];
$q34id = $_POST['q34id'];
$q4id = $_POST['q4id'];
$q5id = $_POST['q5id'];
?>

<?php
$sql = 'INSERT INTO `questionnaire`.`savedq` (`1`, `2`, `3`) VALUES ('.$_POST['q12id'].', '.$_POST['q2id'].', '.$_POST['q34id'].')';
mysql_query($sql) or die("Could not process $sql");

?>

Only its not submitting it to the table in the BD, and values 2 & 3 are empty.

Here;s the error text:

Could not process INSERT INTO `questionnaire`.`savedq` (`1`, `2`, `3`) VALUES (Gaming, , )


DB name is questionnaire and the table in it savedq

:)

Figured out why the values were empty, now it really is just getting it to submit to the table.
 
Last edited:
if i use this i get this:

$sql = 'INSERT INTO `questionnaire`.`savedq` (`1`,`2`,`3`) VALUES ('.$_POST['q12id'].', '.$_POST['q2id'].', '.$_POST['q34id'].')';

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Processing, Yes)' at line 1


or this i get this:

$sql="INSERT INTO `questionnaire`. savedq (1, 2, 3) VALUES ('$_POST[q12id]','$_POST[q2id]','$_POST[q34id]')";

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, 2, 3) VALUES ('Gaming','Word Processing','Yes')' at line 1

any ideas?


Nevermind, i got it working.

$sql= "INSERT INTO `questionnaire`.`savedq` (`1`, `2`, `3`, `4`, `5`) VALUES ('$_POST[q12id]', '$_POST[q2id]', '$_POST[q34id]', '$_POST[q4id]', '$_POST[q5id]')";
 
Last edited:
Back
Top Bottom