我使用 HTML、JS 和 CSS 工作了多年,現(xiàn)在需要進(jìn)一步使用 MySql(我使用 localhost phpMyAdmin)和 PHP。我正在嘗試將數(shù)據(jù)發(fā)送到我的數(shù)據(jù)庫(kù)。但我沒(méi)有收到任何錯(cuò)誤,而且我不知道出了什么問(wèn)題。這是我的register.php: <?php include('classes/db.php'); if (isset($_POST['createaccount'])) { $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; db::query('INSERT INTO users VALUES (\'\', :username, :email, :password)', array(':username'=>$username, ':email'=>$email, ':password'=>$password)); echo "Success!"; } ?> <h1>REGISTER</h1> <form action="register.php" method="post"> <input type="text" name"username" vlaue="" placeholder="Username"> <input type="email" name"email" vlaue="" placeholder="E-Mail"> <input type="password" name"password" vlaue="" placeholder="Password"> <input type="submit" name"createaccount" vlaue="Register"> </form>這是我的 db.php,位于classes/db.php 下:<?phpclass db { private static function connect() { //db inf, username, pwd $pdo = new PDO('mysql:host=127.0.0.1;dbname=emergencybase;charset=utf8', 'root', ''); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return $pdo; } public static function query($query, $params = array()) { $statement = self::connect()->prepare($query); $statement->execute($params); //$data = $statement->fetchAll(); //return $data; }}我沒(méi)有收到任何錯(cuò)誤,并且在我的數(shù)據(jù)庫(kù)中絕對(duì)沒(méi)有出現(xiàn)任何內(nèi)容:數(shù)據(jù)庫(kù)用戶(hù):希望有人能幫助我解決這個(gè)問(wèn)題。
無(wú)法寫(xiě)入mysql數(shù)據(jù)庫(kù)
慕桂英4014372
2024-01-19 10:19:00