Jump to content

[SOLVED] Would this work?


Noskiw

Recommended Posts

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.