Php 这里我得到错误,所以帮助我
我这里出错了,请帮帮我 致命错误:未捕获错误:调用未定义函数 C:\xampp\htdocs\telephasic\action.php:7堆栈中的mysql\u fetch\u对象 跟踪:在上的C:\xampp\htdocs\telephasic\action.php中抛出0{main} 第7行 请尝试使用以下代码:Php 这里我得到错误,所以帮助我,php,mysql,Php,Mysql,我这里出错了,请帮帮我 致命错误:未捕获错误:调用未定义函数 C:\xampp\htdocs\telephasic\action.php:7堆栈中的mysql\u fetch\u对象 跟踪:在上的C:\xampp\htdocs\telephasic\action.php中抛出0{main} 第7行 请尝试使用以下代码: <?php $conn=mysqli_connect("localhost","root","","telephasic"); if(isset($_G
<?php
$conn=mysqli_connect("localhost","root","","telephasic");
if(isset($_GET['role']))
{
$role1=$_GET['role'];
$query = "SELECT * FROM register WHERE id='$role1'";
while($row=mysql_fetch_object($query))
{
$role_var=$row->role;
if($role_var=='1')
{
$role_state="NULL";
} else {
$role_state="0";
}
$update=mysql_query("update register set status='$role_state' where id='$role1' ");
if($update)
{
header("Location:admin.php");
} else {
echo mysql_error();
}
}
?>
<?php } ?>
哪个PHP版本?您应该先查询数据库,然后再获取。您应该使用mysqli\u fetch\u对象而不是mysql\u fetch\u对象。如果您使用mysqli进行连接,请不要使用mysqlafter@AlexandrePainchaud单凭这一点无法使代码正常工作。仍然有mysql\u查询和mysql\u错误。解析错误:语法错误,意外的'while'T\u在C:\xampp\htdocs\telephasic\action.php的第8行重试,我编辑了代码!是的,很有效谢谢你能帮帮我吗?
<?php
$conn=mysqli_connect("localhost","root","","telephasic");
if(isset($_GET['role']))
{
$role1=$_GET['role'];
$query = "SELECT * FROM register WHERE id='$role1'";
$result=mysqli_query($conn,$query); // u need to execute query first!!
while($row=mysqli_fetch_object($result))
{
$role_var=$row->role;
if($role_var=='1')
{
$role_state="NULL";
} else {
$role_state="0";
}
$update=mysqli_query($conn, "update register set status='$role_state' where id='$role1' ");
if($update)
{
header("Location:admin.php");
} else {
echo mysqli_error();
}
}
?>
<?php } ?>