Noskiw Posted January 2, 2009 Share Posted January 2, 2009 <link rel="stylesheet" href="style3.css" type="text/css" /> <?php $con = mysql_connect("localhost", "115886", "youtube"); $db = mysql_select_db(115886, $con); $step = $_GET['step']; if (!$step) { echo "<title>Subscribe</title>\n"; echo "<center><h1><font color=\"#CC0000\">Suscribe</font></h1></center>\n"; echo "<center>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form action=\"suscribe.php?step=2\" method=\"POST\">\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Name: </font></td><td><input type=\"text\" name=\"name\"></td></tr>\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Email: </font></td><td><input type=\"text\" name=\"email\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"Continue\"></td></tr>\n"; echo "</div>\n"; echo "</div>\n"; } if($step == '2'){ echo "<title>Subscribe Step 2</title>\n"; echo "<table border=\"0\" cellspacing=\"3\" cellspadding=\"3\">\n"; echo "<form action=\"suscribe.php?step=3\" method=\"post\">\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Type in the country you are from: </font></td><td><input type=\"text\" name=\"country\"></td></tr>\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Age: </font></td><td><input type=\"text\" name=\"age\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"continue\"></td></tr>\n"; echo "</table></form>\n"; } $name = $_POST['name']; $email = $_POST['email']; $country = $_POST['country']; $age = $_POST['age']; $errors = array(); if($step == '3'){ $sql = "SELECT `name` FROM `suscribers` WHERE `name`='" . $name . "'"; $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) > 0) { $errors[] = "<font color=\"#CC0000\" size=\"2\">Name already exists in database!</font>"; } else { $sql2 = "SELECT `email` FROM `suscribers` WHERE `email`='" . $email . "'"; $res2 = mysql_query($sql2) or die(mysql_error()); if (mysql_num_rows($res2) > 0) { $errors[] = "<font color=\"#CC0000\" size=\"2\">Email is already stored in database!</font>"; }else{ if(strlen($country) < 5 || strlen($country) > 40){ $errors[] = "Your country must be between 5 and 40 characters!"; }else{ if(strlen($age) < 1 || strlen($age) > 3){ $errors[] = "Your age must be between 1 and 3 numeric characters!"; }else{ if(!is_numeric($age)){ $errors[] = "Your age is not numeric, Please try entering it again!"; } } } } } echo "<center>\n"; if(count($errors) > 0){ echo "<title>Subscription Failed</title>\n"; echo "<h1><font color=\"#CC0000\">Subscription Failed</font></h1>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; foreach($errors AS $error){ echo "<p align=\"left\"><font color=\"#CC0000\" size=\"2\">".$error."</font></p>"; echo "</div></div>\n"; } }else{ $sql3 = "INSERT INTO `suscribers` (`name`,`email`,`country`,`age`) VALUES ('".$name."','".$email."','".$country."','".$age."')"; $res3 = mysql_query($sql3) or die(mysql_errors()); echo "<title>Thanks</title>\n"; echo "<center><h1><font color=\"#CC0000\">Thanks</font></h1></center>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; echo "<p align=\"left\"><font color=\"#CC0000\" size=\"2\">Thanks for subscribing! Your benefits are a monthly newletter so far!</font></p>\n"; echo "</div>\n"; echo "</div>\n"; echo "</center>\n"; } } ?> this is 100% written by me. i am having trouble. the issue is when the user presses submit, it comes up with the error, Name already exists in database when everything is entered correctly, and i dont know whats wrong. can someone help me. this is how mich i suck at php. EDIT: it was just with one name. anyway, now, the proper thing in the database won't work. it won't show the age and the email. go figure. Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/ Share on other sites More sharing options...
premiso Posted January 2, 2009 Share Posted January 2, 2009 It looks alright to me...are you sure that name is not in the DB? Check by printing out the name that is returned by the DB and the $name being passed to the DB to see what each is. Really this is just a debugging issue. We cannot help you at all cause this is all on your DB and you just need to check the sql statement, check what is being returned from that SQL statement, check what is being put in and verify that it is correct. Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728419 Share on other sites More sharing options...
Maq Posted January 2, 2009 Share Posted January 2, 2009 It's because you have to submit twice before you actually get to the INSERT part. So you're losing name. If you look in your database I bet it's not even INSERTING the name or email... You need to store the name in a hidden field for step 2. $name = $_GET['name']; "'> Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728420 Share on other sites More sharing options...
ratcateme Posted January 2, 2009 Share Posted January 2, 2009 the vars from step 1 are lost in step 2 so never get to step 3 you either need to save the vars from step 1 in $_SESSION or make it one form. Scott. Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728422 Share on other sites More sharing options...
Maq Posted January 2, 2009 Share Posted January 2, 2009 the vars from step 1 are lost in step 2 so never get to step 3 you either need to save the vars from step 1 in $_SESSION or make it one form. Scott. Yes, sessions will work too, probably a better idea. Also make sure you clean your strings with mysql_real_escape_string(). Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728424 Share on other sites More sharing options...
Noskiw Posted January 2, 2009 Author Share Posted January 2, 2009 yea, but i really wanted to experiment, and see if i could make it into two different forms. btw, the hidden input type didn't work. Plus, how would i store it in a session? $_SESSION['name']; ? this is the code i have <link rel="stylesheet" href="style3.css" type="text/css" /> <?php $con = mysql_connect("localhost", "115886", "youtube"); $db = mysql_select_db(115886, $con); $step = $_GET['step']; if (!$step) { echo "<title>Subscribe</title>\n"; echo "<center><h1><font color=\"#CC0000\">Suscribe</font></h1></center>\n"; echo "<center>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form action=\"suscribe.php?step=2\" method=\"POST\">\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Name: </font></td><td><input type=\"text\" name=\"name\"></td></tr>\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Email: </font></td><td><input type=\"text\" name=\"email\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"Continue\"></td></tr>\n"; echo "</div>\n"; echo "</div>\n"; } if($step == '2'){ echo "<title>Subscribe Step 2</title>\n"; echo "<table border=\"0\" cellspacing=\"3\" cellspadding=\"3\">\n"; echo "<form action=\"suscribe.php?step=3\" method=\"post\">\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Type in the country you are from: </font></td><td><input type=\"text\" name=\"country\"></td></tr>\n"; $name = $_GET['name']; echo "<input type='hidden' name='name' value='".$name."'>"; $email = $_GET['email']; echo "<input type=\"hidden\" name=\"email\" value='".$email."'>"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Age: </font></td><td><input type=\"text\" name=\"age\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"continue\"></td></tr>\n"; echo "</table></form>\n"; } $name = $_POST['name']; $email = $_POST['email']; $country = $_POST['country']; $age = $_POST['age']; $errors = array(); if($step == '3'){ $sql = "SELECT `name` FROM `suscribers` WHERE `name`='" . $name . "'"; $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) > 0) { $errors[] = "<font color=\"#CC0000\" size=\"2\">Name already exists in database!</font>"; } else { $sql2 = "SELECT `email` FROM `suscribers` WHERE `email`='" . $email . "'"; $res2 = mysql_query($sql2) or die(mysql_error()); if (mysql_num_rows($res2) > 0) { $errors[] = "<font color=\"#CC0000\" size=\"2\">Email is already stored in database!</font>"; }else{ if(strlen($country) < 5 || strlen($country) > 40){ $errors[] = "Your country must be between 5 and 40 characters!"; }else{ if(strlen($age) < 1 || strlen($age) > 3){ $errors[] = "Your age must be between 1 and 3 numeric characters!"; }else{ if(!is_numeric($age)){ $errors[] = "Your age is not numeric, Please try entering it again!"; } } } } } echo "<center>\n"; if(count($errors) > 0){ echo "<title>Subscription Failed</title>\n"; echo "<h1><font color=\"#CC0000\">Subscription Failed</font></h1>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; foreach($errors AS $error){ echo "<p align=\"left\"><font color=\"#CC0000\" size=\"2\">".$error."</font></p>"; echo "</div></div>\n"; } }else{ $sql3 = "INSERT INTO `suscribers` (`name`,`email`,`country`,`age`) VALUES ('".$name."','".$email."','".$country."','".$age."')"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<title>Thanks</title>\n"; echo "<center><h1><font color=\"#CC0000\">Thanks</font></h1></center>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; echo "<p align=\"left\"><font color=\"#CC0000\" size=\"2\">Thanks for subscribing! Your benefits are a monthly newletter so far!</font></p>\n"; echo "</div>\n"; echo "</div>\n"; echo "</center>\n"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728431 Share on other sites More sharing options...
ratcateme Posted January 2, 2009 Share Posted January 2, 2009 the should be $name = $_POST['name']; echo "<input type='hidden' name='name' value='".$name."'>"; $email = $_POST['email']; but sessions are better like <?php session_start();//must be before any output ?> <link rel="stylesheet" href="style3.css" type="text/css" /> <?php $con = mysql_connect("localhost", "115886", "youtube"); $db = mysql_select_db(115886, $con); $step = $_GET['step']; if (!$step) { echo "<title>Subscribe</title>\n"; echo "<center><h1><font color=\"#CC0000\">Suscribe</font></h1></center>\n"; echo "<center>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form action=\"suscribe.php?step=2\" method=\"POST\">\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Name: </font></td><td><input type=\"text\" name=\"name\"></td></tr>\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Email: </font></td><td><input type=\"text\" name=\"email\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"Continue\"></td></tr>\n"; echo "</div>\n"; echo "</div>\n"; } if($step == '2'){ $_SESSION['name'] = $_POST['name']; $_SESSION['email'] = $_POST['email']; echo "<title>Subscribe Step 2</title>\n"; echo "<table border=\"0\" cellspacing=\"3\" cellspadding=\"3\">\n"; echo "<form action=\"suscribe.php?step=3\" method=\"post\">\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Type in the country you are from: </font></td><td><input type=\"text\" name=\"country\"></td></tr>\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Age: </font></td><td><input type=\"text\" name=\"age\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"continue\"></td></tr>\n"; echo "</table></form>\n"; } $name = $_SESSION['name']; $email = $_SESSION['email']; $country = $_POST['country']; $age = $_POST['age']; $errors = array(); if($step == '3'){ $sql = "SELECT `name` FROM `suscribers` WHERE `name`='" . $name . "'"; $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) > 0) { $errors[] = "<font color=\"#CC0000\" size=\"2\">Name already exists in database!</font>"; } else { $sql2 = "SELECT `email` FROM `suscribers` WHERE `email`='" . $email . "'"; $res2 = mysql_query($sql2) or die(mysql_error()); if (mysql_num_rows($res2) > 0) { $errors[] = "<font color=\"#CC0000\" size=\"2\">Email is already stored in database!</font>"; }else{ if(strlen($country) < 5 || strlen($country) > 40){ $errors[] = "Your country must be between 5 and 40 characters!"; }else{ if(strlen($age) < 1 || strlen($age) > 3){ $errors[] = "Your age must be between 1 and 3 numeric characters!"; }else{ if(!is_numeric($age)){ $errors[] = "Your age is not numeric, Please try entering it again!"; } } } } } echo "<center>\n"; if(count($errors) > 0){ echo "<title>Subscription Failed</title>\n"; echo "<h1><font color=\"#CC0000\">Subscription Failed</font></h1>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; foreach($errors AS $error){ echo "<p align=\"left\"><font color=\"#CC0000\" size=\"2\">".$error."</font></p>"; echo "</div></div>\n"; } }else{ $sql3 = "INSERT INTO `suscribers` (`name`,`email`,`country`,`age`) VALUES ('".$name."','".$email."','".$country."','".$age."')"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<title>Thanks</title>\n"; echo "<center><h1><font color=\"#CC0000\">Thanks</font></h1></center>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; echo "<p align=\"left\"><font color=\"#CC0000\" size=\"2\">Thanks for subscribing! Your benefits are a monthly newletter so far!</font></p>\n"; echo "</div>\n"; echo "</div>\n"; echo "</center>\n"; } } ?> you could also store the step var in $_SESSION it would be more secure so people can't skip sections Scott. Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728433 Share on other sites More sharing options...
9three Posted January 2, 2009 Share Posted January 2, 2009 Suggestion: Since your if statements contain a lot of HTML you can always use if ($foo) { echo <<<HTML Html code can be used here now <<<HTML; } This will help your application run faster in the long run. If you need to use a variable in the html all you need to do is the is the following: if ($foo) { echo <<<HTML <table width="100%" border="0"> <tr> <td>Welcome back $user !</td> </tr> </table> <<<HTML; Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728468 Share on other sites More sharing options...
hobeau Posted January 3, 2009 Share Posted January 3, 2009 Better (and more efficient) is to do: <html> <head> <title>My Title</title> </head> <body> <?php if ($foo) { ?> <!-- html goeth here --> <?= $var_to_be_echoed ?> <?php } else { ?> <!-- html goeth here --> <?= $var_to_be_echoed ?> <?php } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728486 Share on other sites More sharing options...
Noskiw Posted January 3, 2009 Author Share Posted January 3, 2009 the should be $name = $_POST['name']; echo "<input type='hidden' name='name' value='".$name."'>"; $email = $_POST['email']; but sessions are better like <?php session_start();//must be before any output ?> <link rel="stylesheet" href="style3.css" type="text/css" /> <?php $con = mysql_connect("localhost", "115886", "youtube"); $db = mysql_select_db(115886, $con); $step = $_GET['step']; if (!$step) { echo "<title>Subscribe</title>\n"; echo "<center><h1><font color=\"#CC0000\">Suscribe</font></h1></center>\n"; echo "<center>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form action=\"suscribe.php?step=2\" method=\"POST\">\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Name: </font></td><td><input type=\"text\" name=\"name\"></td></tr>\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Email: </font></td><td><input type=\"text\" name=\"email\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"Continue\"></td></tr>\n"; echo "</div>\n"; echo "</div>\n"; } if($step == '2'){ $_SESSION['name'] = $_POST['name']; $_SESSION['email'] = $_POST['email']; echo "<title>Subscribe Step 2</title>\n"; echo "<table border=\"0\" cellspacing=\"3\" cellspadding=\"3\">\n"; echo "<form action=\"suscribe.php?step=3\" method=\"post\">\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Type in the country you are from: </font></td><td><input type=\"text\" name=\"country\"></td></tr>\n"; echo "<tr><td><font color=\"#CC0000\" size=\"2\">Age: </font></td><td><input type=\"text\" name=\"age\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"continue\"></td></tr>\n"; echo "</table></form>\n"; } $name = $_SESSION['name']; $email = $_SESSION['email']; $country = $_POST['country']; $age = $_POST['age']; $errors = array(); if($step == '3'){ $sql = "SELECT `name` FROM `suscribers` WHERE `name`='" . $name . "'"; $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) > 0) { $errors[] = "<font color=\"#CC0000\" size=\"2\">Name already exists in database!</font>"; } else { $sql2 = "SELECT `email` FROM `suscribers` WHERE `email`='" . $email . "'"; $res2 = mysql_query($sql2) or die(mysql_error()); if (mysql_num_rows($res2) > 0) { $errors[] = "<font color=\"#CC0000\" size=\"2\">Email is already stored in database!</font>"; }else{ if(strlen($country) < 5 || strlen($country) > 40){ $errors[] = "Your country must be between 5 and 40 characters!"; }else{ if(strlen($age) < 1 || strlen($age) > 3){ $errors[] = "Your age must be between 1 and 3 numeric characters!"; }else{ if(!is_numeric($age)){ $errors[] = "Your age is not numeric, Please try entering it again!"; } } } } } echo "<center>\n"; if(count($errors) > 0){ echo "<title>Subscription Failed</title>\n"; echo "<h1><font color=\"#CC0000\">Subscription Failed</font></h1>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; foreach($errors AS $error){ echo "<p align=\"left\"><font color=\"#CC0000\" size=\"2\">".$error."</font></p>"; echo "</div></div>\n"; } }else{ $sql3 = "INSERT INTO `suscribers` (`name`,`email`,`country`,`age`) VALUES ('".$name."','".$email."','".$country."','".$age."')"; $res3 = mysql_query($sql3) or die(mysql_error()); echo "<title>Thanks</title>\n"; echo "<center><h1><font color=\"#CC0000\">Thanks</font></h1></center>\n"; echo "<div id=\"holder\">\n"; echo "<div id=\"userInfo\">\n"; echo "<p align=\"left\"><font color=\"#CC0000\" size=\"2\">Thanks for subscribing! Your benefits are a monthly newletter so far!</font></p>\n"; echo "</div>\n"; echo "</div>\n"; echo "</center>\n"; } } ?> you could also store the step var in $_SESSION it would be more secure so people can't skip sections Scott. thx, thats working now. Quote Link to comment https://forums.phpfreaks.com/topic/139254-solved-subscription-php-error/#findComment-728595 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.