看来当我尝试我的代码

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


我得到的错误


  错误:无法执行INSERT INTO MyGuests(用户名,密码,电子邮件,名称)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."')";

10-07 14:07