0

simply put my code doesn't seem to be working probably the variables work and echo out its simply the code for insert im doing wrong no error just doesnt insert into the table.. the idea is that it inserts in to a table and replaces the data already in the id selected

if(($_REQUEST['questionbox']=="" )||($_REQUEST['boxA']=="")|| ($_REQUEST['boxB']=="")|| ($_REQUEST['boxC']=="")|| ($_REQUEST['boxD']=="")|| ($_REQUEST['correctbox']==""))
{
echo "must enter data";
}else{
 $sql2 = "INSERT INTO `tblas`(`id`, `question`, `A`, `B`, `C`, `D`, `correct`) VALUES ([".$idbox."],[".$questionbox."],[".$boxA."],[".$boxB."],[".$boxC."],[".$boxD."],[".$correctbox."])";
$editquery= mysql_query($sql2, $db);
echo $editquery;
5
  • You want to insert or update the row? Commented Oct 19, 2013 at 10:05
  • u need to write query for UPDATE if u want to replace contents from old ID Commented Oct 19, 2013 at 10:08
  • You can use the UPDATE action as already mentioned. You can also use the REPLACE INTO action dev.mysql.com/doc/refman/5.0/en/replace.html Commented Oct 19, 2013 at 10:16
  • well that would make a difference, looking over examples how would I do this with my code? dont have to write it out just if you could show an example with my code so far I am thinking something like "UPDATE tblas SET question =$questionbox, A=$boxA WHERE id=$idbox"; would that be it? or am i far off? Commented Oct 19, 2013 at 10:21
  • Thank you guys for the help and yeah update worked perfectly, can't believe i didnt stumble upon that earlier!!! Thanks again!!! Commented Oct 19, 2013 at 10:25

1 Answer 1

2

try this query instead of insert query

if(($_REQUEST['questionbox']=="" )||($_REQUEST['boxA']=="")|| ($_REQUEST['boxB']=="")|| ($_REQUEST['boxC']=="")|| ($_REQUEST['boxD']=="")|| ($_REQUEST['correctbox']==""))
{   
    echo "must enter data";
}else{
    $sql2 = "UPDATE tblas SET id='".$idbox."', question = '".$questionbox."', A = '".$boxA."', B = '".$boxB."' ,C = '".$boxC."', D= '".$boxD."' , correct= '".$correctbox."'";
}

echo $editquery;
Sign up to request clarification or add additional context in comments.

1 Comment

added where id=$idbox and it worked perfectly thank you so much!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.