我今天第一次尝试使用PHP和MySQL教程,我被告知使用$ MySQL已经过时并被告知要使用我尝试过的$ mysqli。我已将我的页面上传到ipage上的服务器,但我只得到一个白色的屏幕。可能我的代码中有错误,服务器运行sql 5.5.32。问题是我甚至没有在Internet Explorer中收到回显消息。
使用带有'db_table to'db_table'/添加表单
的绑定/编辑进行编辑<?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 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>
任何帮助都将不胜感激。
答案 0 :(得分:1)
您是否还可以使用您使用的表单代码在此文件上提交数据。因为如果直接打开此文件,则不会执行任何代码。也请尝试这个
<?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";
}
?>