tqla Posted June 28, 2007 Share Posted June 28, 2007 Hi. The code below is a form that looks at a promotional code and sees if it exists in a database. If it does they move on to a survey. There are only 2 types of 10 digit promotional codes - codes that start with 'L' and codes that start with 'S'. Right now they both go to 'survey.php'. How can I make 'L' codes go to 'l-survey.php and 'S' codes go to 's-survey.php'? <?php require_once('db/db.php'); session_start(); if (isset($_POST['submit'])) { $promocode = $_POST['promocode']; $sql = "SELECT code FROM promocode WHERE code = '$promocode'"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { header("Location: survey.php"); } else { echo "<font color=\"#FF0000\">The Promotional code that you have entered does not exists or has already been redeemed.</FONT><BR><BR>"; } } ?> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p>Promotional Code: <input name="promocode" type="text" id="promocode"> </p> <p> <input type="reset" name="Reset" value="Reset"> <input type="submit" name="submit" value="submit"> </p> </form> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 Try this: <?php require_once('db/db.php'); session_start(); if (isset($_POST['submit'])) { $promocode = $_POST['promocode']; $sql = "SELECT code FROM promocode WHERE code = '$promocode'"; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); if (substr($row['code'], 0, 1) == 'L'){ header("Location: l-survey.php"); } else if (substr($row['code'], 0, 1) == 'S'){ header("Location: s-survey.php"); } } else { echo "<font color=\"#FF0000\">The Promotional code that you have entered does not exists or has already been redeemed.</FONT><BR><BR>"; } } ?> <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> <p>Promotional Code: <input name="promocode" type="text" id="promocode"> </p> <p> <input type="reset" name="Reset" value="Reset"> <input type="submit" name="submit" value="submit"> </p> </form> ?> EDIT: I just edited the code, so if you just tried it and it didn't work...try it again =] Quote Link to comment Share on other sites More sharing options...
tqla Posted June 29, 2007 Author Share Posted June 29, 2007 Hi pocobueno1388! Thanks. This works perfectly. You're a genius! yeah!!!! 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.