Double Entries
am 28.08.2006 04:45:53 von Nobody
Hello,
Im learning PHP and MySQL and wrote a simple script to store an email
address from a Form Submit into a table. The script works, but when I
check the table the email address is listed twice.
Has anybody experienced this in the past? ANy suggestions is greatly
appreciated. Thank you in advance for your time and words.
George
Re: Double Entries
am 28.08.2006 06:55:13 von Johnny
wrote in message news:BNsIg.958$N84.153@trnddc08...
> Hello,
>
> Im learning PHP and MySQL and wrote a simple script to store an email
> address from a Form Submit into a table. The script works, but when I
> check the table the email address is listed twice.
>
> Has anybody experienced this in the past? ANy suggestions is greatly
> appreciated. Thank you in advance for your time and words.
>
> George
Hi George,
You'll get more help if you post your simple script so we can see what 's
what.
Re: Double Entries
am 28.08.2006 07:10:01 von Nobody
Hi John,
Sure. Here it is. Hope this helps.
$connection = mysql_connect("serverhost","username","password");
if (!$connection) {
die ("Could not connect: " . mysql_error());
}else{
echo "Connected";
}
mysql_select_db("dbname", $connection);
$sql = ("INSERT INTO newsletter
(email)
VALUES
('$_POST[email]')");
mysql_query($sql,$connection);
if (!mysql_query($sql,$connection)) {
die ("Could not update" . mysql_error());
}
echo "Updated";
?>
Johnny wrote:
> wrote in message news:BNsIg.958$N84.153@trnddc08...
>
>>Hello,
>>
>>Im learning PHP and MySQL and wrote a simple script to store an email
>>address from a Form Submit into a table. The script works, but when I
>>check the table the email address is listed twice.
>>
>>Has anybody experienced this in the past? ANy suggestions is greatly
>>appreciated. Thank you in advance for your time and words.
>>
>>George
>
> Hi George,
> You'll get more help if you post your simple script so we can see what 's
> what.
>
>
--
-------------------------------
http://www.gpalzproductions.com
"The world is full of Kings and Queens who blind your eyes and steal
your dreams. Its Heaven and Hell!" - Ronnie James Dio
Re: Double Entries
am 28.08.2006 08:03:18 von Andy Hassall
On Mon, 28 Aug 2006 05:10:01 GMT, nobody@thisaddress.net wrote:
>mysql_query($sql,$connection);
>
>if (!mysql_query($sql,$connection)) {
>die ("Could not update" . mysql_error());
>}
>echo "Updated";
You've called mysql_query twice, so you get two rows.
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Re: Double Entries
am 28.08.2006 15:16:07 von Johnny
wrote in message
news:44F27A73.8000102@thisaddress.net...
> Hi John,
>
> Sure. Here it is. Hope this helps.
>
>
>
> $connection = mysql_connect("serverhost","username","password");
>
>
> if (!$connection) {
> die ("Could not connect: " . mysql_error());
> }else{
> echo "Connected";
> }
>
> mysql_select_db("dbname", $connection);
>
> $sql = ("INSERT INTO newsletter
> (email)
> VALUES
> ('$_POST[email]')");
>
> mysql_query($sql,$connection);
>
> if (!mysql_query($sql,$connection)) {
> die ("Could not update" . mysql_error());
> }
> echo "Updated";
>
> ?>
loks like you have called 'mysql_query($sql,$connection)' twice to
me....that might explain the double entry.
Re: Double Entries
am 28.08.2006 20:30:38 von Nobody
Oh, OK. Yes that would make sense. I thought I was testing for a return
value in the if statement. Didn't realize I could do both at once. I'll
drop the first query. Thanks Andy and John for your assistance.
Johnny wrote:
> wrote in message
> news:44F27A73.8000102@thisaddress.net...
>> Hi John,
>>
>> Sure. Here it is. Hope this helps.
>>
>>
>>
>> $connection = mysql_connect("serverhost","username","password");
>>
>>
>> if (!$connection) {
>> die ("Could not connect: " . mysql_error());
>> }else{
>> echo "Connected";
>> }
>>
>> mysql_select_db("dbname", $connection);
>>
>> $sql = ("INSERT INTO newsletter
>> (email)
>> VALUES
>> ('$_POST[email]')");
>>
>> mysql_query($sql,$connection);
>>
>> if (!mysql_query($sql,$connection)) {
>> die ("Could not update" . mysql_error());
>> }
>> echo "Updated";
>>
>> ?>
> loks like you have called 'mysql_query($sql,$connection)' twice to
> me....that might explain the double entry.
Re: Double Entries
am 29.08.2006 21:21:52 von Neil Trigger
yeah just put "or die" after one interation, rather than do it again.
PHP is funny like that. I was always making that mistake when i first
started.
--
Neil Trigger
Magic2k Manager
http://www.magic2k.com
http://www.oddmap.com
wrote in message
news:iDGIg.4404$pX3.2414@trnddc07...
> Oh, OK. Yes that would make sense. I thought I was testing for a return
> value in the if statement. Didn't realize I could do both at once. I'll
> drop the first query. Thanks Andy and John for your assistance.
>
> Johnny wrote:
> > wrote in message
> > news:44F27A73.8000102@thisaddress.net...
> >> Hi John,
> >>
> >> Sure. Here it is. Hope this helps.
> >>
> >>
> >>
> >> $connection = mysql_connect("serverhost","username","password");
> >>
> >>
> >> if (!$connection) {
> >> die ("Could not connect: " . mysql_error());
> >> }else{
> >> echo "Connected";
> >> }
> >>
> >> mysql_select_db("dbname", $connection);
> >>
> >> $sql = ("INSERT INTO newsletter
> >> (email)
> >> VALUES
> >> ('$_POST[email]')");
> >>
> >> mysql_query($sql,$connection);
> >>
> >> if (!mysql_query($sql,$connection)) {
> >> die ("Could not update" . mysql_error());
> >> }
> >> echo "Updated";
> >>
> >> ?>
> > loks like you have called 'mysql_query($sql,$connection)' twice to
> > me....that might explain the double entry.