homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
not inserting into database
jrproduc




msg:3653145
 4:44 pm on May 18, 2008 (gmt 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>");

}

?>

 

ag_47




msg:3653155
 5:17 pm on May 18, 2008 (gmt 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";

Cheers.

BananaFish




msg:3653313
 12:31 am on May 19, 2008 (gmt 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)."')";

jrproduc




msg:3653445
 5:41 am on May 19, 2008 (gmt 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.

James

dublinmike




msg:3653503
 10:47 am on May 19, 2008 (gmt 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());

jrproduc




msg:3653671
 3:09 pm on May 19, 2008 (gmt 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>
<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" />
Subscribe&nbsp;
<INPUT type="radio" name="action" value="leave" style="border: 0px;" />
Unsubscribe&nbsp;</SPAN>

<SPAN class="style70">

</SPAN>
<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

James

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved