gpt4 book ai didi

php - 我的sql代码有什么问题

转载 作者:行者123 更新时间:2023-11-29 19:20:46 25 4
gpt4 key购买 nike

似乎当我尝试我的代码

$sql = 'INSERT INTO MyGuests (username, password, email, name) VALUES("'.$uname.'", "'.$pword.'", "'.$email.'", "'.$name.'")';

我得到的错误是

ERROR: Could not able to execute INSERT INTO MyGuests (username, password, email, name) VALUES("anything", "anything", "anything", "anything").

是否有任何直接的危险信号,我希望得到一些帮助!

这是我的所有代码

    <?php
get_header();
?>
<?php
include('config.php');
mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if (isset($_POST['submit'])) {
$uname = mysqli_real_escape_string($db,$_POST['Nex']);
$pword = mysqli_real_escape_string($db,$_POST['Pex']);
$name = mysqli_real_escape_string($db,$_POST['Naex']);
$email = mysqli_real_escape_string($db,$_POST['Eex']);


$sql = 'INSERT INTO MyGuests (username, password, email, name) VALUES('".$uname."', '".$pword."', '".$email."', '".$name."')';
echo'account created.';
echo"$uname";
echo"$pword";
echo"$name";
echo"$email";
} else { ?>
<style media="screen" type="text/css">

label {
width:180px;
clear:left;
text-align:right;
padding-right:10px;
}

input, label {
float:left;
}
</style>
<h1> Create A Account </h1>
<form method="post" action="">
<label for="Nex">Username:</label>
<input type="text" name="Nex" </input>
<label for="Pex">Password:</label>
<input type="text" name="Pex" </input>
<label for="Eex">Email:</label>
<input type="text" name="Eex" </input>
<label for="Eex">Name of scout:</label>
<input type="text" name="Naex" </input>
<input type="submit" value="OK" name="submit" />
</form>

<?php } ?>

以及我的 config.php(隐藏了登录内容,哈哈)

<?php
define('DB_SERVER', 'dbserver');
define('DB_USERNAME', 'uname');
define('DB_PASSWORD', 'pword');
define('DB_DATABASE', 'uname');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
<?php
//Variables for connecting to your database.
//These variable values come from your hosting account.
$hostname = "dbserver";
$username = "uname";
$dbname = "uname";

//These variable values need to be changed by you before deploying
$password = "pword";
$usertable = "uname";
$yourfield = "MyGuests";

//Connecting to your database
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);

//Fetching from your database table.
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);

if ($result) {
while($row = mysql_fetch_array($result)) {
$name = $row["$yourfield"];
echo "Name $name<br>";
}
}
?>

最佳答案

这只是一个报价问题
试试这个:

 $sql = "INSERT INTO MyGuests (username, password, email, name) VALUES('".$uname."', '".$pword."', '".$email."', '".$name."')"; 

关于php - 我的sql代码有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42463160/

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