ducky101 Posted November 25, 2007 Share Posted November 25, 2007 Hi, I'm trying to create a form where people can register by entering their names, email addresses and one "promotional" code (the same for everyone). The names and emails I've got, I just can't seem to wrap my head around the notion of one single access code. I mean, do I create a new table for just one value or do I have to do something else, and also what would the query look like? I hope someone can help me. Thanks in advance. Alex Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 25, 2007 Share Posted November 25, 2007 create a field and name it say "promo" and then do this: <?php $entrycode = $_POST['$entrycode'']; // connect to db // select db $contentsearch = mysql_query("select promo from tblName where promo='$entrycode'") or die("Invalid Promotional Code"); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2007 Share Posted November 25, 2007 If its the same promo code for everyone and if you don't plan to change it, I wouldn't even bother storing it in a field of a DB and just hard code it. But if there is any chance you'll change that, then putting it in a DB would be a good idea. Quote Link to comment Share on other sites More sharing options...
ducky101 Posted November 25, 2007 Author Share Posted November 25, 2007 How would I go about hard coding it (I'm new to php). Thanks for all the help. Quote Link to comment Share on other sites More sharing options...
janim Posted November 25, 2007 Share Posted November 25, 2007 you can just download any script google for php login script if that what you searching for Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 25, 2007 Share Posted November 25, 2007 http://www.w3schools.com/php/php_mysql_intro.asp read...... Quote Link to comment Share on other sites More sharing options...
ducky101 Posted November 26, 2007 Author Share Posted November 26, 2007 Thank you all for the help you have provided I am new to php, but even now with this short experience I can tell it is a wonderfull community. This will certainly add to the joy of learning to program in php. As for the solution, I have gone with the database option. I created a new table called promo with field promocode In my php script I did: //Connect to db stuff $promocode = $_POST ['promocode]; $PromocodeQuery = mysql_query("SELECT * FROM promo WHERE promocode='$promocode"); $promocode = strtolower ($promocode); $PromocodeExist = mysql_num_rows($PromocodeQuery); // Return 0 if it doesn't exist Then I added logic if ($InlogcodeExist == 0) { print "<p><font size=\"3\" face=\"Myriad Pro, Arial\" color=\"#E08734\"><b>Promocode is not correct!</b></font></p>"; exit; } else { //rest of the script I want to run} And it works like a charm Anyway thanks for the help again. Alex Quote Link to comment Share on other sites More sharing options...
elis Posted November 26, 2007 Share Posted November 26, 2007 If you haven't already, you may want to add some sort of security instead of relying solely on $_POST[promocode] I.E. $promocode = mysql_real_escape_string($_POST['promocode']); Quote Link to comment Share on other sites More sharing options...
ducky101 Posted November 27, 2007 Author Share Posted November 27, 2007 @elis Thanks for the tip. I hadn't, but I have now after reading your post. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.