Noskiw Posted January 2, 2009 Share Posted January 2, 2009 <?php $con = mysql_connect("localhost", "root", ""); $db = mysql_select_db(suscribers, $con); if (!$_POST['submit']) { echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n"; echo "<form action=\"suscribe.php\" method=\"POST\">\n"; echo "<tr><td><input type=\"text\" name=\"name\"></td></tr>\n"; echo "<tr><td><input type=\"text\" name=\"email\"></td></tr>\n"; echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"calculate\"></td></tr>\n"; } $name = $_POST['name']; $email = $_POST['email']; $errors = array(); $sql = "SELECT name FROM suscribers WHERE name='" . $name . "'"; $res = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($res) > 0) { $errors[] = "Name is already in database!"; } else { $sql2 = "SELECT email FROM suscribers WHERE email='" . $email . "'"; $res2 = mysql_query($sql2) or die(mysql_error()); if (mysql_num_rows($res2) > 0) { $errors[] = "Email is already stored in database!"; } } if(count($errors) > 0){ foreach($errors AS $error){ echo "<br>" . $error; } }else{ $sql3 = "INSERT into suscribers (name,email) VALUES ('".$name."','".$email."')"; $res3 = mysql_query($sql3) or die(mysql_errors()); } ?> i want to make a suscribers page and i was just wondering is the code above would work. Link to comment https://forums.phpfreaks.com/topic/139214-solved-would-this-work/ Share on other sites More sharing options...
dennismonsewicz Posted January 2, 2009 Share Posted January 2, 2009 have you tested it? if so, are you getting any errors? Link to comment https://forums.phpfreaks.com/topic/139214-solved-would-this-work/#findComment-728151 Share on other sites More sharing options...
RichardRotterdam Posted January 2, 2009 Share Posted January 2, 2009 looks fine to me. But why why not just try it Link to comment https://forums.phpfreaks.com/topic/139214-solved-would-this-work/#findComment-728158 Share on other sites More sharing options...
Noskiw Posted January 2, 2009 Author Share Posted January 2, 2009 sorry i tried it, it worked. Link to comment https://forums.phpfreaks.com/topic/139214-solved-would-this-work/#findComment-728188 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.