我被反复告知我需要停止使用sql所以我想把我在mysql中的遗骸翻译成mysqli。但是,我正在努力使用这段代码。我想知道是否有人可以帮我翻译它。以下教程,视频和翻译人员都有这样的问题,想知道是否有人有时间为我翻译。我不想问,但我真的很感激。感谢。
include 'check.php';
$user = $_SESSION['username'];
if ($user) {
//user is logged in
if (isset($_POST['submit'])) {
//check fields
$oldpassword = md5($_POST['oldpassword']);
$newpassword = md5($_POST['newpassword']);
$repeatnewpassword = md5($_POST['repeatnewpassword']);
// Connect to server and select databse.
$host = 'localhost';
// Host name
$username = '';
// Mysql username
$password = '';
// Mysql password
$db_name = '';
// Database name
mysqli_connect("{$host}", "{$username}", "{$password}") or die('cannot connect');
//STRUGGLING HERE!
}
while ($row = mysqli_fetch_array($queryget)) {
$oldpassworddb = $row['password'];
}
//check passwords
if ($oldpassword == $oldpassworddb) {
//check new passowrds
if ($newpassword == $repeatnewpassword) {
//success
//change password in db
$querychange = mysqli_query($link, "UPDATE members SET password='{$newpassword}' WHERE username ='{$user}'");
header('refresh:2;url=logout.php');
die('Your password has successfully been changed.');
} else {
die('Your new passwords do not match');
}
} else {
die('Password doesn\'t match');
}
} else {
echo "Some text";
}
}
?>
我正在努力与我说过,这就是我试图进入的那个没有工作
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$queryget = mysql_query("SELECT password FROM members WHERE username='$user'");
if($queryget === FALSE) {
die(mysql_error()); // TODO: better error handling
}
我想。
答案 0 :(得分:-3)
这没有明显的测试,但我认为会有效
<?php
include('check.php');
$user = $_SESSION['username'];
if($user)
{
//user is logged in
if (isset($_POST['submit']))
{
//check fields
$oldpassword = md5($_POST['oldpassword']);
$newpassword = md5($_POST['newpassword']);
$repeatnewpassword = md5($_POST['repeatnewpassword']);
// Connect to server and select databse.
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$mysqli = new mysqli($host,$username,$password,$db_name);
if (mysqli_connect_errno()) {
printf("Falló la conexión failed: %s\n", $mysqli->connect_error);
exit();
}
$queryget = $mysqli->query("SELECT password FROM members WHERE
username='$user'");
if($queryget === FALSE) {
die($mysqli->error()); // TODO: better error handling
}
while($row = $mysqli->fetch_array(MYSQLI_NUM){
$oldpassworddb = $row['password'];
}