gpt4 book ai didi

php 脚本回显 php 的一部分而不是预期的内容

转载 作者:行者123 更新时间:2023-11-29 01:44:04 25 4
gpt4 key购买 nike

<分区>

我在使用我创建的用于将实例插入数据库的 php 脚本时遇到问题,但是我得到了一个微不足道的输出,我不知道如何修复它。代码是:

<?php

try{
$user = 'root';
$pass = null;
$pdo = new PDO('mysql:host=localhost; dbname=divebay', $user, $pass);

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$username = $_POST['username'];
$password = sha1($_POST['password']);
$location = %_POST['location'];
$email = $_POST['email'];
$name = $_POST['fname'] . " " . $_POST['surname'];

$check = $pdo->prepare('SELECT * FROM user WHERE username=?');
$check->bindValue(1, $username);
$check->execute();

if($check->fetch(PDO::FETCH_OBJ)){
echo "Account name already exists";
}
else{

$stmt = $pdo->prepare('INSERT INTO user(username, password, location, email, name)
VALUES(:username, :password, :location, :email, :name)');
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
$stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->bindParam(':location', $location, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':name', $name, PDO::PARAM_STR);

if($stmt->execute()){
echo "Account created";
}
else{
echo "Account could not be created";
}
}

$pdo = null;

}catch(PDOException $e){
echo $e->getMessage();
}


?>

我希望输出类似于“创建帐户”。相反,我收到此错误的输出:

setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $username = $_POST['username']; $password = sha1($_POST['password']);
$location = %_POST['location']; $email = $_POST['email']; $name = $_POST['fname'] . " " . $_POST['surname']; $check = $pdo->prepare('SELECT * FROM user WHERE username=?');
$check->bindValue(1, $username); $check->execute();
if($check->fetch(PDO::FETCH_OBJ)){ echo "Account name already exists"; } else{ $stmt = $pdo->prepare('INSERT INTO user(username, password, location, email, name) VALUES(:username, :password, :location, :email, :name)'); $stmt->bindParam(':username', $username, PDO::PARAM_STR); $stmt->bindParam(':password', $password, PDO::PARAM_STR);
$stmt->bindParam(':location', $location, PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
if($stmt->execute()){ echo "Account created"; } else{ echo "Account could not be created"; } } $pdo = null; }catch(PDOException $e){ echo $e->getMessage(); } ?>

导致此问题的脚本有什么问题?

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