我尝试了很多不同的事情,并且进行了很多搜索,但都没有解决方案.我正在尝试使用html表单将数据提交到sql表.这是我的register.php文件的代码.$con = mysqli_connect(localhost, database_name, password datab...
我尝试了很多不同的事情,并且进行了很多搜索,但都没有解决方案.我正在尝试使用html表单将数据提交到sql表.
这是我的register.php文件的代码.
$con = mysqli_connect("localhost", "database_name", "password" "database_user");
if($con === false) {
die("ERROR Could not Connect." . mysqli_connect_error());
}
$lasty= mysqli_real_escape_string($_POST['laz']);
$namez=mysqli_real_escape_string($_POST['namer']);
$emailAddr=mysqli_real_escape_string($_POST['emaila']);
$userName=mysqli_real_escape_string($_POST['usrn']);
$passwo=mysqli_real_escape_string($_POST['passw']);
$sqql = "INSERT INTO 'database_name' . table' (UserID, FirstName, LastName, Email, UserName, Password)
VALUES (NULL, '$namez', '$lasty', '$emailAddr', '$userName', '$passwo')";
if (mysqli_query($con, $sqql)) {
echo "Successfull";
} else {
echo "Did not work!" . $con->error;
}
mysqli_close($con);
我的HTML文件是:
<form action="register.php" method="POST">
First Name: <input type="text" name="namer" placeholder="First Name"/> <br>
Last Name: <input type='text' name='laz' /> <br>
Email Address: <input type='text' name='emaila' /> <br>
UserName: <input type='text' name='usrn' />
Password: <input type='password' name='passw' />
<input type='submit' id='button' value='Submit' name='login' />
</form>
我为那些奇怪的命名变量提前道歉,我担心其他文件会打扰我在这里试图做的事情.
解决方法:
$con = mysqli_connect("localhost", "database_name", "password" "database_user"); //open connection
if (mysqli_connect_errno()) { //if connection failed
die("Connect failed: ", mysqli_connect_error());
exit();
}
$lasty = mysqli_real_escape_string($con, $_POST['laz']); //added $con needs two parameter (connection, input)
$namez = mysqli_real_escape_string($con, $_POST['namer']);
$emailAddr = mysqli_real_escape_string($con, $_POST['emaila']);
$UserName = mysqli_real_escape_string($con, $_POST['usrn']);
$password = mysqli_real_escape_string($con, $_POST['passw']);
$sqql = "INSERT INTO `table_name`(UserID, FirstName, LastName, Email, UserName, Password)
VALUES (NULL, '$namez', '$lasty', '$emailAddr', '$userName', '$passwo')";
if (mysqli_query($con, $sqql)) {
echo "Row inserted";
}else{
die("Error: ". mysqli_sqlstate($con));
}
mysqli_close($con);
沃梦达教程
本文标题为:尝试使用来自注册表的PHP / HTML将数据输入到SQL表中
基础教程推荐
猜你喜欢
- ajax三级联动下拉菜单效果 2023-01-31
- 小程序实现Token生成与验证 2023-08-11
- 深入了解JavaScript中正则表达式的使用 2023-08-11
- Ajax请求二进制流进行处理(ajax异步下载文件)的简单方法 2023-02-14
- 详解ajax跨域问题解决方案 2023-02-14
- Vue中使用Ant框架在form表单中使用输入框或数字输入框且用v-decorator取当前值 2023-10-08
- 编写轻量ajax组件02--浅析AjaxPro 2022-10-17
- 关于javascript:有没有办法将svg容器塑造成它的内 2022-09-21
- Vue 实现轮播图功能的示例代码 2023-07-10
- Layui数据表格模型 2022-12-14