<?php
mysql_connect("localhost", "root", "");
mysql_select_db("cinema");
if (trim($_POST["username"]) == "") {
echo "Please input Username!";
exit();
}
if (trim($_POST["password"]) == "") {
echo "Please input Password!";
exit();
}
if ($_POST["password"] != $_POST["password"]) {
echo "Password not Match!";
exit();
}
if (trim($_POST["f_name"]) == "") {
echo "Please input Name!";
exit();
}
if (trim($_POST["l_name"]) == "") {
echo "Please input Last Name!";
exit();
}
if (trim($_POST["E-mail"]) == "") {
echo "Please input E-mail!";
exit();
}
$strSQL = "SELECT * FROM account WHERE Username = '" . trim($_POST['username']) . "' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if ($objResult) {
echo "Username already exists!";
} else {
$strSQL = "INSERT INTO 'account' (Username,Password,f_name,l_name,E-mail) VALUES ('" . $_POST["username"] . "',
'" . $_POST["password"] . "','" . $_POST["f_name"] . "','" . $_POST["l_name"] . "','" . $_POST["E-mail"] . "')";
$objQuery = mysql_query($strSQL);
echo "Register Completed!<br>";
echo "<br> Go to <a href='index.php'>Home</a>";
}
mysql_close();
?>
เราสร้าง form สมัครสมาชิก เก็บค่าไว้ในตัวแปรด้านบน หลังจากนั้นให้มันส่งข้อมูลลงใน db ไม่มี error ใดๆทั้งสิ้น ลอง echo ออกปกติ แต่ทำไมข้อมูลไม่ถูกป้อนลง db ครับ TT
สร้าง form สมัครสมาชิก แต่ ข้อมูล ไม่เข้า database
mysql_connect("localhost", "root", "");
mysql_select_db("cinema");
if (trim($_POST["username"]) == "") {
echo "Please input Username!";
exit();
}
if (trim($_POST["password"]) == "") {
echo "Please input Password!";
exit();
}
if ($_POST["password"] != $_POST["password"]) {
echo "Password not Match!";
exit();
}
if (trim($_POST["f_name"]) == "") {
echo "Please input Name!";
exit();
}
if (trim($_POST["l_name"]) == "") {
echo "Please input Last Name!";
exit();
}
if (trim($_POST["E-mail"]) == "") {
echo "Please input E-mail!";
exit();
}
$strSQL = "SELECT * FROM account WHERE Username = '" . trim($_POST['username']) . "' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if ($objResult) {
echo "Username already exists!";
} else {
$strSQL = "INSERT INTO 'account' (Username,Password,f_name,l_name,E-mail) VALUES ('" . $_POST["username"] . "',
'" . $_POST["password"] . "','" . $_POST["f_name"] . "','" . $_POST["l_name"] . "','" . $_POST["E-mail"] . "')";
$objQuery = mysql_query($strSQL);
echo "Register Completed!<br>";
echo "<br> Go to <a href='index.php'>Home</a>";
}
mysql_close();
?>