0

I attempted PHP and MySQL for the first time today following a tutorial, I was told using $MySQL was outdated and told to use $mysqli which I've attempted. I've uploaded my page to my server on ipage but am only getting a white screen. Its likely there's an error in my code, the server runs sql 5.5.32. The thing is I'm not even getting the echo back messages in Internet Explorer.

Edited with a bind / edited with 'db_table to 'db_table' /added form

<?php

//Database Setup    
$mysqli_db = new mysqli($db_host,$db_name,$db_username,$db_password);

function webmailSignUp()
{
    $webmailFullName = $_POST['webmailFullName'];
    $webmailName = $_POST['webmailUserName'];
    $webmailExEmail = $_POST['webmailExEmail'];
    $webmailPhone = $_POST['webmailPhone'];
    $webmailDOB = $_POST['webmailDOB'];

    //Check that the fields are not empty
    if ((!empty($webmailFullName)) or (!empty($webmailName)) or (!empty($webmailExEmail)) or (!empty($webmailPhone)) or (!empty($webmailDOB)))
    {
        //Check that there is no existing name in the table
        if (checkUser($userName) == false)
        {
            //Adding the person to the Database Query   
            $query = "INSERT INTO '$db_table'(userFullName,userName,userExEmail,userPhone,userDOB) VALUES(?,?,?,?,?)";
            //Binding to Prevent SQL injection                      
            $requery = $mysqli_db->prepare($query);
            $requiry->bind_param($webmailFullName,$webmailName,$webmailExEmail,$webmailPhone,$webmailDOB);
            if ($requery->execute())
            {
                echo "Person has been added";
            }
            else
            {
                echo "bind failed";
            }   
        }
        else
        {
            echo "There is already a user registered with this username.  Please try a different one.";
        }
    }
    else
    {
        echo "One of your fields are blank!  Please try again";
    }
}

function checkUser($userNameCheck)
{
    //Check the field userName is the same as the Posted Username
    $Field = "userName"; //The Field to check
    $query = "SELECT '$Field' WHERE '$Field'='$webmailName' FROM '$db_table' LIMIT 1"; 
    $result = mysqli_query($query, $mysqli_db) or die(mysql_error());

    if (!$row = mysqli_fetch_array($result) or die(mysql_error()))
    {
        return false; //username was not found in the field in the table
    }
    else
    {
        return true; //username was found in the field in the table
    }
}

function close()
{
    $mysqli_db->close();
}


//Main Code Sequence
error_reporting(-1);
ini_set('display_errors',1);

if(isset($_POST['webmailRegisterButton']))
{
    echo("firstbit");
    webmailSignUp();
    close();
    echo "End of Registration";
}
if(isset($_POST['webamilForgottenPWSubmit']))
{
    webmailForgottenPassword();
    close();
    echo "End of Password Reset Request";
}
?>

Form:

<form method="POST" action="../_webmail/mailDB.php">
                    <div class="popupTitleCell"><h3>Name:</h3></div>
                    <div class="popupInputCell"><input type="text" name="webmailFullName" class="popupInputField"></div>
                    <div class="popupSpacer2"><p>Your Full Name (ex. John Coles)</p></div>
                    <div class="popupTitleCell"><h3>UserName:</h3></div>
                    <div class="popupInputCell"><input type="text" name="webmailUserName" value="@allcoles.com" class="popupInputField"></div>
                    <div class="popupSpacer2"><p>Preference email (ex john@allcoles.com)</p></div>
                    <div class="popupSpacer"><hr></div>
                    <div class="popupTitleCell"><h3>Existing Email:</h3></div>
                    <div class="popupInputCell"><input type="text" name="webmailExEmail" class="popupInputField"></div>
                    <div class="popupSpacer2"><p>REQUIRED to recieve SignIn details</p></div>
                    <div class="popupTitleCell"><h3>Phone Number:</h3></div>
                    <div class="popupInputCell"><input type="text" name="webmailPhone" class="popupInputField"></div>
                    <div class="popupSpacer2"><p>(allows for SMS confirmation)</p></div>
                    <div class="popupTitleCell"><h3>Date of Birth:</h3></div>                        
                    <div class="popupInputCell"><input type="text" id="datepickerRegister" name="webmailDOB"></div>
                    <div class="popupSpacer2"><p>Select your DOB from the calender</p></div>
                    <div class="popupSpacer"><hr></div>
                    <div class="popupButtonCell"> 
                     <button type="submit" name="webmailRegisterSubmit" value="register" id="submitButton" class="popupButton">
      <span>Register</span></button></div>
                    </form>

Any help would be appreciated.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Smokey
  • 117
  • 1
  • 11

1 Answers1

1

Can you also put the code of the form you are using to submit data on this file. Because if you directly open this file no code will be execute. Also please try this

<?php
//Main Code Sequence
error_reporting(-1);
ini_set('display_errors',1);

//Database Setup    
$db_host = "localhost";
$db_name = "test";
$db_table = "emailUser";
$db_username = "root";
$db_password = "";
$mysqli_db = new mysqli($db_host,$db_username,$db_password, $db_name);

function webmailSignUp()
{
    $webmailFullName = $_POST['webmailFullName'];
    $webmailName = $_POST['webmailUserName'];
    $webmailExEmail = $_POST['webmailExEmail'];
    $webmailPhone = $_POST['webmailPhone'];
    $webmailDOB = $_POST['webmailDOB'];

    //Check that the fields are not empty
    if ((!empty($webmailFullName)) or (!empty($webmailName)) or (!empty($webmailExEmail)) or (!empty($webmailPhone)) or (!empty($webmailDOB)))
    {
        //Check that there is no existing name in the table
        if (checkUser($userName) == false)
        {
            //Adding the person to the Database Query   
            $query = "INSERT INTO '$db_table(userFullName,userName,userExEmail,userPhone,userDOB) VALUES($webmailFullName,$webmailName,$webmailExEmail,$webmailPhone,$webmailDOB)";
            echo "Person has been added";
        }
        else
        {
            echo "There is already a user registered with this username.  Please try a different one.";
        }
    }
    else
    {
        echo "One of your fields are blank!  Please try again";
    }
}

function checkUser($userNameCheck)
{
    //Check the field userName is the same as the Posted Username
    $Field = "userName"; //The Field to check
    $query = "SELECT '$Field' WHERE '$Field'='$webmailName' FROM '$db_table' LIMIT 1"; 
    $result = mysqli_query($query, $mysqli_db) or die(mysql_error());

    if (!$row = mysqli_fetch_array($result) or die(mysql_error()))
    {
        return false; //username was not found in the field in the table
    }
    else
    {
        return true; //username was found in the field in the table
    }
}

function close()
{
    $mysqli_db->close();
}




if(isset($_POST['webmailRegisterButton']))
{
    echo("firstbit");
    webmailSignUp();
    close();
    echo "End of Registration";
}
if(isset($_POST['webamilForgottenPWSubmit']))
{
    webmailForgottenPassword();
    close();
    echo "End of Password Reset Request";
}
?>
Nitin Kumar Soni
  • 198
  • 2
  • 16