gpt4 book ai didi

PHP Forms不在MySQL中插入数据

转载 作者:行者123 更新时间:2023-11-30 22:32:13 24 4
gpt4 key购买 nike

我在数据未保存到表格时遇到问题,我在名为 Register.php 的文件中获得了以下代码,我启用了 error_reporting 以查看任何错误,但没有显示任何错误。我的数据库名为 Registration,表名为 users,托管在 GoDaddy 上

<?php
require 'Connections/Connections.php';
?>

<?php
if(isset($_Post['Register'])) {

session_start();
$FName = $_POST['First_Name'];
$LName = $_POST['Last_Name'];
$Username = $_POST['Username'];
$Email = $_POST['Email'];
$PW = $_POST['Password'];

$sql = $con->query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('{$Fname}', '{$LName}', '{$Username}', '{$Email}', '{$PW}')");

}
?>

<!doctype html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<link href="Style/Master.css" rel="stylesheet" type="text/css" />
<title>Register</title>
</head>
<body>
<form action="" method="post" name="RegisterForm" id="RegisterForm">

<div class="FormElement">
<input name="First_Name" type="text" required="required" class="TField" id="First_Name" placeholder="First Name">
</div>

<div class="FormElement">
<input name="Last_Name" type="text" required="required" class="TField" id="Last_Name" placeholder="Last Name">
</div>

<div class="FormElement">
<input name="Username" type="text" required="required" class="TField" id="Username" placeholder="Username">
</div>

<div class="FormElement">
<input name="Email" type="text" required="required" class="TField" id="Email" placeholder="Email">
</div>

<div class="FormElement">
<input name="Password" type="text" required="required" class="TField" id="Password" placeholder="Password">
</div>

<div class="FormElement">
<input name="Register" type="submit" class="button" id="Register" placeholder="Register">
</div>
</body>
</html>

这是 Connections.php 中的代码,只是没有我的真实用户名和密码

<?php

$con = mysql_connect("localhost", "USERNAME", "PASSWORD", "Registration");

?>

任何帮助将不胜感激!

最佳答案

您需要编辑 Connection.php

mysql_connect("localhost", "USERNAME", "PASSWORD"); 
mysql_select_db("Registration"); //your data base name

而且你还必须编辑

 mysql_query("INSERT INTO users (Fname, Lname, Username, Email, Password)Values('$Fname', '$LName', '$Username', '$Email', '$PW')") or die(mysql_error());

关于PHP Forms不在MySQL中插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33566626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com