Forum Moderators: coopster

Message Too Old, No Replies

Wont Insert into database

my code wont insert into database

         

bysonary

10:23 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



ok Before i start talking here is my code,


<?php
//include '/home/www/juttuffi/auth.php';
include '/home/www/juttuffi/dbc.php';

$question = $_POST['quest'];
$answer = $_POST['answer'];
$nextq = $_POST['nextquest'];
$weight = $_POST['weight'];

$query1 = mysql_query("SELECT qid FROM tquestions WHERE question='$question'");

$qrow1 = mysql_fetch_array($query1,MYSQL_ASSOC);

$quest = $qrow1['qid'];

$sqlquery = "INSERT INTO tanswers (qid, answer, next_qid. weight) VALUES ('$quest','$answer','$nextq','$weight')";

//header("Location: index.php");

print $sqlquery;
$results = mysql_query($sqlquery);

mysql_close($dbc);
?>

Ok now this code outputs exactly what I want i want it to on the screen, that is it prints out the sql query which when i am submitting looks a little like this

INSERT INTO tanswers (qid, answer, next_qid. weight) VALUES ('3','BACK TO PREVIOUS','1','5')

The only problem is, the data i can see on screen doesn't appear to be appearing in the database table tanswers

can anyone tell me why the above code might not spit out any errors but at the same time doesn't appear to add to the database?

I would greatly appreciate the help here.

scriptmasterdel

10:51 pm on Feb 11, 2007 (gmt 0)

10+ Year Member



OK, you have a full stop instead of a commer on this insert, this would throw an error if the correct level of error is set in your coniguration.

"INSERT INTO tanswers (qid, answer, next_qid. weight) VALUES ('3','BACK TO PREVIOUS','1','5')"

Should be ...

"INSERT INTO tanswers (qid, answer, next_qid, weight) VALUES ('3','BACK TO PREVIOUS','1','5')"

Also, i suggest you use a debuging method to see what the mysql error is.

e.g.

$results = mysql_query($sqlquery);

Could be.

$results = mysql_query($sqlquery) or die(mysql_error());

This will output the exact error and give you a better idea of what the prolem could be.

Hope i have helped.

Del

LifeinAsia

4:58 pm on Feb 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Are qid, next_qid, weight all CHAR or VARCHAR fields? If not, then you shouldn't be trying to insert them with single quotes around the values.

bysonary

5:01 pm on Feb 12, 2007 (gmt 0)

10+ Year Member



they are INT fields

LifeinAsia

5:14 pm on Feb 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Try:
"INSERT INTO tanswers (qid, answer, next_qid, weight) VALUES (3,'BACK TO PREVIOUS',1,5)"

bysonary

5:22 pm on Feb 12, 2007 (gmt 0)

10+ Year Member



that works thanks :-)