Please can someone explain what I have done wrong, there may also be further errors. (First attempt at using PHP with a tutorial). The tutorial did not specify a table name. The error is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE userName = ''' at line 1
My Code:
<?php
//MySQL Database Setup
define('DB_HOST', '***');
define('DB_NAME', '***');
$db_table = "emailUser";
define('DB_USER','***');
define('DB_PASSWORD','***');
//Connection
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());
//Connection Checking
//if (mysqli_connect_errno($con)) {
//    echo "Failed to connect to MySQL: " . mysqli_connect_error();
//  }
//else {
//      echo “Successfully connected to the AllColes webmail database…”;
//  }
function webmailNewUser()
{
    $userFullName = $_POST['webmailFullName'];
    $userName = $_POST['webmailUserName'];
    $userExEmail = $_POST['webmailExEmail'];
    $userPhone = $_POST['webmailPhone'];
    $userDOB = $_POST['userDOB'];
    $query = "INSERT INTO $db_table_name (userFullName,userName,userExEmail,userPhone,userDOB) VALUES ('$userFullName','$userName','$userExEmail','$userPhone','$userDOB')";
    $data = mysql_query ($query) or die(mysql_error());
    if ($data)
    {
        echo "Your registration for ColesMail is compleated.";
    }
    else
    {
        echo "Registration for ColesMail has NOT compleated succesfully!";
    }
}
function webmailSignUp()
{
    if(!empty($_POST['webmailUserName'])) 
    {
        $query = mysql_query("SELECT * FROM $db_table_name WHERE userName = '$_POST[user]'") or die(mysql_error()); //checking the same name in the field
        if(!$row = mysql_fetch_array($query) or die(mysql_error()))
        {
            webmailNewUser();
        }
        else
        {
            echo "Sorry someone already has this username";
        }
    }
}
function webmailForgottenPW()
{
                    //Email Requirements
                        $webMaster = 'christophercoles@live.co.uk';
                        $emailSubject = 'Forgotten Password Reset!';
                        $headers = "From: $webMaster\r\n";
                        $headers = "MIME-Version: 1.0\r\n";
                        $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
                        $headers .= "X-Mailer: PHP/".phpversion();
                    //Forgotten Password Fields
                        $fpUserName = $_POST['webmailFPuserName'];
                        $fpContactMethod = $_POST['webmailFPcontactMethod'];
                        $fpDOB = $_POST ['webmailFPDOB'];
                    //Email Body
                        $body = "
                        <html>
                            <head>
                            <title>Password Reset for $fpUserName</title>
                            </head>
                            <body>
                            <h1>Password Reset</h1><hr>
                            Name: $fpUserName <br>
                            Request Password by: $fpContactMethod <br>
                            Date of Birth: $fpDOB
                            </body>
                        </html>";
                    //After Sending
                        mail($webMaster,$emailSubject,$body,$headers);
                        $theResults = "Sucess Email Sent!!!";
                        echo $theResults;
}
if(isset($_POST['webmailRegisterSubmit']))
{
    webmailSignUp();
}
if(isset($_POST['webmailForgottenPWSubmit']))
{
    webmailForgottenPassword();
}
?>
 
     
     
     
     
     
     
     
    