我不知道我做错了什么,但它没有插入我希望它放入数据库的数据。除了我创建的 mysql 错误之外,没有给我任何代码错误,例如“错误插入”和类似的东西。我也做了很多关于登录源的谷歌搜索,并试图看看有什么区别,但没有用。我找不到问题所在!请帮忙。
<?php
include_once('connect.php')
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
if (isset($_POST['dalol'])){
test();
}
function test(){
$sql = "INSERT INTO members (username, email, password) VALUES ('".$GLOBALS['username']."','".$GLOBALS['email']."','".$GLOBALS['password']."')";
if (mysql_query($sql)){
echo '<p>Successfully Executed!</p>';
} else {
echo '<p>Failed!</p>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Insert Test</title>
</head>
<body>
<form>
Username: <input type="text" name="username"/><br>
Email: <input type="email" name="email"/><br>
Password: <input type="password" name="password"/><br>
<input type='submit' name='dalol'/>
</form>
</body>
最佳答案
你可以使用全局变量!
就是这样:
<?php
function test(){
global $username,$email,$password;
$sql = "INSERT INTO members (username, email, password) VALUES ('".$username."','".$email."','".$password."')";
if (mysql_query($sql)){
echo '<p>Successfully Executed!</p>';
} else {
echo '<p>Failed!</p>';
}
} ?>
<?php
$username = mysql_real_escape_string($_POST['username']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
?>
关于php - 错误 : Inserting data into mySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28536254/