# Insert statement fails:

**URL:** https://forum.kirupa.com/t/insert-statement-fails/269679
**Category:** Uncategorized
**Created:** [August 30, 2008, 5:46pm UTC](https://forum.kirupa.com/t/insert-statement-fails/269679 "2008-08-30T17:46:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![sami\_rima](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@sami\_rima](https://forum.kirupa.com/u/sami_rima)
#### Post date: [August 30, 2008, 5:46pm UTC](https://forum.kirupa.com/t/insert-statement-fails/269679/1 "2008-08-30T17:46:56Z")

</div>

My insert statement always fails her is the code:

```php
 
// If form is submitted, then insert into DB
if (!empty($HTTP_POST_VARS["THERE"]) ) {
 $NAME = $HTTP_POST_VARS["NAME"];
 $DATE_IN = $HTTP_POST_VARS["DATE_IN"];
 $SENTENCE = $HTTP_POST_VARS["SENTENCE"];
 //$ID = $HTTP_POST_VARS["ID"];
 $DISPLAY = $HTTP_POST_VARS["DISPLAY"];
 $DETAILS = $HTTP_POST_VARS["DETAILS"];
 $PIC = $HTTP_POST_VARS["PIC"];
 
 /*$approved = $HTTP_POST_VARS["approved"];*/
 
 
 
 $gb_query =" insert into RESIDENTS(NAME,DATE_IN,SENTENCE,THERE,DISPLAY,DETAILS,PIC) VALUES
 
                               ('$NAME', '$DATE_IN', '$SENTENCE', '0','$DISPLAY','$DETAILS','$PIC') ";
 
 mysql_query($gb_query);
 $res = mysql_affected_rows();
 
 // See if insert was successful or not
 if($res > 0) {
  $ret_str="Your guestbook entry was successfully added.";
  //echo $gb_query;
 } else {
  $ret_str = "Your guestbook entry was NOT successfully added.";
  echo $gb_query;
 }
 
 // Append success/failure message
 $gb_str .= "<span class=\"ret\">$ret_str</span><BR>";
}
?>

```

the table description is:

ID = PRIMARY KEY ==INT(50) AUTO INCREMENT

WHEN I ECHO THE QUERY i GET:

Nothing is inserted in the database:

insert into RESIDENTS(NAME,DATE\_IN,SENTENCE,THERE,DISPLAY,DETAILS,PIC) VALUES (‘1’, ‘546’, ‘54’, ‘0’,‘45’,‘5’,‘45’) Your guestbook entry was NOT successfully added.

AND here is the form section of the page:

```auto
 
<form name="gb" action="signrimaguest.php" method="post">
<BR><B><div class="poo" style="text-align: right" dir="rtl">&nbsp;&nbsp;&nbsp;
<!--Name: <input type="Text" name="ID" size="30"><p>-->
Name: <input type="Text" name="NAME" size="30"><p>
Date:<input type="Text" name="DATE_IN" size="30"><p>
Sentence:<input type="Text" name="SENTENCE" size="30"><p>
there:<input type="HIDDEN" name="THERE" default='0'size="30"><p>
DISPLAY:<input type="Text" name="DISPLAY" ><p>
DETAILS:<textarea name="DETAILS" size="800" rows="5" COLS ="40"></textarea><P>
PIC:<input type="Text" name="PIC" ><p>
<input type="submit" name="THERE" value="submit" ">
 

```

Any ideas? thanks
