Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

not inserting into database

4:44 pm on May 18, 2008 (gmt 0)

New User

5+ Year Member

joined:May 18, 2008
posts: 3
votes: 0

Hello All,

Im having a problem with my php code not inserting into my database. Im not getting an error message its just not putting the info into my database.

<?php include('dommailinglist.php');
$email = $_POST[‘email’];

if (isset($email) ¦¦ $email<>"") { //is is set or it equals something
// if the product name contains something, meaning that
// the form was submitted, so process it
$sql = "INSERT INTO users (email) VALUES email($email) WHERE id='$email'";

$strResult = mysql_query($sql) or die(mysql_errno() . " : " . mysql_error() . " <strong>Insert Failed for Some Reason</strong>");



5:17 pm on May 18, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Apr 13, 2008
votes: 0

Two things i noticed:
<?php include('dommailinglist.php');
$email = $_POST[‘email’]; <-- The quotes in here are not regular ', is this ok with your system?

And for the insert statement, simply try:
$sql = "INSERT INTO users (email) VALUES $email";


12:31 am on May 19, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Sept 7, 2005
votes: 0

$strResult = mysql_query($sql) or die(mysql_errno()

This will not exit (or die) upon error, it will merely set the value of $strResult to false. Furthermore the proper sql statement is:

$sql = "INSERT INTO users (email) VALUES ('".mysql_real_escape_string($email)."')";

5:41 am on May 19, 2008 (gmt 0)

New User

5+ Year Member

joined:May 18, 2008
posts: 3
votes: 0

Thanks for the help, but its still not inserting. The php Im running is v5 if that would matter any. On a v4.1 sql server.

If the quotes isnt regular what should it be?

Ok what will make it exit?

In advance Thank you.


10:47 am on May 19, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:May 4, 2002
posts: 97
votes: 0

Hi there,

Put the following bit of code in your script and see what it prints out...

$sql = "INSERT INTO users (email) VALUES ('$email');";
$result = mysql_query($sql) or die(mysql_error());
3:09 pm on May 19, 2008 (gmt 0)

New User

5+ Year Member

joined:May 18, 2008
posts: 3
votes: 0

Thank you All for the help we solved that problem now I have another problem. Now how would I code the radios so it well insert and delete when thay subscribe and unsubscribe?

<TD width="570" height="589" valign="top" id="content"><H1>Newsletter Subscribe / Unsubscribe </H1>
<FORM action="<?php self?>" method="post">
<SPAN class="style69">Enter your name and email address below:</SPAN><BR /><BR />
<SPAN class="style70">NAME:
<SPAN id="sprytextfield1">
<INPUT name="ename" type="text" class="style58" id="elistname" style="width: 140px" size="5" maxlength="50" />
<SPAN class="textfieldRequiredMsg">A value is required.</SPAN><SPAN class="textfieldMinCharsMsg">Minimum number of characters not met.</SPAN></SPAN> <BR />
<BR />
<SPAN class="style70">EMAIL:</SPAN>
<SPAN class="style70"><SPAN id="sprytextfield2">
<INPUT name="emailaddress" type="text" class="style58" id="emailaddress" style="width: 140px" size="5" maxlength="100" />
<SPAN class="textfieldRequiredMsg">A value is required.</SPAN><SPAN class="textfieldInvalidFormatMsg">Invalid format.</SPAN></SPAN><BR />

<INPUT name="action" type="radio" style="border: 0px;" value="join" checked="CHECKED" />
<INPUT type="radio" name="action" value="leave" style="border: 0px;" />

<SPAN class="style70">

<INPUT type="submit" name="submit" value="Submit"/>
<P align="center" class="style61 style1">
<INPUT type="hidden" name="subject" value="Newsletter Subscribe/Unsubscribe" />
<INPUT type="hidden" name="recipient" value="e-mail address" />
<INPUT type="hidden" name="title" value="Newsletter Subscribe/Unsubscribe">
<INPUT type="hidden" name="redirect" value="url" />
</FORM> </TD>

Thank You in advance