使用mysqli转换PHP代码。 [英] Convert the PHP code using the mysqli.
本文介绍了使用mysqli转换PHP代码。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以告诉我为什么php 7.0.8在运行以下php代码时显示错误,并且任何人都可以在mysqli中更改以下php代码吗?
Can anyone tell me why php 7.0.8 shows error while running the following php code and can anyone change the following php code in mysqli?
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="forum_answer"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get value of id that sent from hidden field
$id=$_POST['id'];
// Find highest answer number.
$sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
// add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1
if ($rows) {
$Max_id = $rows['Maxa_id']+1;
}
else {
$Max_id = 1;
}
// get values that sent from form
$a_name=$_POST['a_name'];
$a_email=$_POST['a_email'];
$a_answer=$_POST['a_answer'];
$datetime=date("d/m/y H:i:s"); // create date and time
// Insert answer
$sql2="INSERT INTO $tbl_name(question_id, a_id, a_name, a_email, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_email', '$a_answer', '$datetime')";
$result2=mysql_query($sql2);
if($result2){
echo "Successful<BR>";
echo "<a href='view_topic.php?id=".$id."'>View your answer</a>";
// If added new answer, add value +1 in reply column
$tbl_name2="forum_question";
$sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'";
$result3=mysql_query($sql3);
}
else {
echo "ERROR";
}
// Close connection
mysql_close();
?>
我有什么尝试过:
我试图在php 7.0.8版本中运行这个php代码,但它显示错误。那么,现在我正在尝试将此代码转换为mysqli,任何人都可以帮助我吗?
What I have tried:
I tried to run this php code in php 7.0.8 Version but it shows the error in it. So, now I am trying to convert this code into the mysqli, can anyone help me ?
推荐答案
host = localhost; // 主机名
host="localhost"; // Host name
username = ; // Mysql用户名
username=""; // Mysql username
password = ; // Mysql密码
password=""; // Mysql password
这篇关于使用mysqli转换PHP代码。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文