Forums

PHP

This topic is locked

insert into other table if value yes

Posted 28 Jul 2003 14:27:38
1
has voted
28 Jul 2003 14:27:38 Adam Davies posted:
Sorry to be a bother but I cant get my head round this (don't know where to start).
I have a competition form which among other things has a "subscribe to newsletter" option with a vlaue of yes or no, what I need to do is when the form is submitted the competition entry is inserted into the "competition" table (which I have already done" but if the "subscribe to newsletter" drop down box has a value of yes it also checks to see if the email address is aleady in the "newsletter" table and if it isn't adds the email address to that table and if the value is no then it ignores it and just adds the competition entry to the "competition" table..

So basically the logic is this user click submit > competition form checks if subsribe to newsletter is yes > if yes competition form checks if email already exists > if no insert email address into "newsletter table" ELSE ignore email > insert comeptition entry into "comeptitions"

can anyone provide me with a link to a tutorial so I can achieve this using dmx 6.1 with the php server model

Cheers



Edited by - cotc2001 on 28 Jul 2003 14:31:23

Replies

Replied 28 Jul 2003 15:30:43
28 Jul 2003 15:30:43 Patrick Woldberg replied:
Just a little code to bring you on the way:

if ($HTTP_POST_VARS['newsletter'] == yes) {
$query_id = mysql_query("SELECT id FROM newsletter WHERE email = ".$HTTP_POST_VARS['email']) or die("Error in query: " . mysql_error());
$rows = mysql_num_rows(query_id);
if ($rows > 0) {
echo "Email allready exists";
exit;
} else {
mysql_query("INSERT INTO newsletter VALUES (null, '$email')" or die("Error in query: " . mysql_error());
}
}

I didn't test it so there could be some errors in it

--------------------------------------------------
Patrick Woldberg
Web Developer at Dynamic Zones
Manager at DMXzone.com
--------------------------------------------------

Reply to this topic