gpt4 book ai didi

php - 准备好的陈述 + PDO

转载 作者:太空宇宙 更新时间:2023-11-03 10:45:00 25 4
gpt4 key购买 nike

<分区>

首先,请注意我并不是将其用作真实世界的登录,它纯粹是为了练习。我正在使用 PHP/MySQLi,我试图实现准备好的语句,但我做的不正确。这是我只使用 mysqli_escape_string 的工作代码:

$host="localhost";
$username="login";
$password="password";
$db_name="database";


$link=mysqli_connect("$host", "$username", "$password", "$db_name")or die("cannot connect to server");

$tbl_name=temp_members;

// Random confirmation code to be sent in email
$confirm_code=md5(uniqid(rand()));

//from signup.php
$name=$_POST['name'];
$email=$_POST['email'];
$pwd=$_POST['password'];

$name = mysqli_real_escape_string($link, $name);
$email = mysqli_real_escape_string($link, $email);
$pwd = mysqli_real_escape_string($link, $pwd);

$pwd = password_hash($pwd, PASSWORD_DEFAULT);

// Insert data into temp_members
$sql="INSERT INTO $tbl_name(confirm_code, name, email, password)VALUES('$confirm_code', '$name', '$email', '$pwd')";
$result=mysqli_query($link, $sql);


if($result){

//email
$to=$email;
$subject="(no reply)";
$header="from: Ben Pappas <mrbenpappas@gmail.com>";

// message
$message="Hello ".$name.", Thanks for signing up! \r\n";
$message.="Click on this link to activate your account: \r\n";
$message.="http://www.monger.us/verify/confirmation.php? passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);
}

这是我对 PDO/准备好的语句的(糟糕的)尝试:

$host="localhost";
$username="login";
$password="password";
$db_name="database";


$link = new PDO("mysql:host=$host;dbname=$db_name",$username,$password) or die("cannot connect to server");

$tbl_name=temp_members;

// Random confirmation code to be sent in email
$confirm_code=md5(uniqid(rand()));

//from signup.php
$name=$_POST['name'];
$email=$_POST['email'];
$pwd=$_POST['password'];

$name = mysqli_real_escape_string($link, $name);
$email = mysqli_real_escape_string($link, $email);
$pwd = mysqli_real_escape_string($link, $pwd);

$pwd = password_hash($pwd, PASSWORD_DEFAULT);

// Insert data into temp_members

$statement = $link->prepare("INSERT INTO $tbl_name(confirm_code, name, email, password)VALUES('$confirm_code', '$name', '$email', '$pwd')";
$statement->execute(array(
$confirm_code => 'confirm_code',
$email => 'email',
$name => 'name'
));
$result = ($link, $statement);


if($result){

//email
$to=$email;
$subject="(no reply)";
$header="from: Ben Pappas <mrbenpappas@gmail.com>";

// message
$message="Hello ".$name.", Thanks for signing up! \r\n";
$message.="Click on this link to activate your account: \r\n";
$message.="http://www.monger.us/verify/confirmation.php? passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);
}

我在调用语句变量的行上收到一条错误消息,消息说意外的“;”

请原谅任何明显的错误我是学徒

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