[mysqli_query执行会引发http错误500

问题描述 投票:1回答:1

这里是我的设置,我已经检查了两次,什么也没想到。我目前正在使用LAMP堆栈,并且大多数配置已正确完成。我有两个档案1. connect.php2. registration.php

  1. connect.php的代码如下:
<?php
ini_set('display_errors',1); 
error_reporting(E_ALL);
$hostname="localhost"; //local server name
$username="user_name";  //mysql username
$password="my_password"; //mysql password
$database="my_database";  //database name 

// Create Connection to DB using an Object
$con= mysqli_connect($hostname,$username,$password); //do i need to pass database name also as an argument to this?

//Check Connection 
if(mysqli_connect_errno()){
    echo"Failed to connect! due to : " . mysqli_connect_errno();
} else{
    echo"Connected!";
}
?>
  1. registration.php的代码如下:
<?php     //start php tag
include("/var/www/calculator/connect.php"); //using absolute path to avoid any confusion
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
} else {
    printf("Connected! on Registration Page"); //executes till here with no problems
}

if (mysqli_query($conn, "CREATE table users"))
{
    printf("Query Executed!", mysqli_affected_rows($conn))
}

mysqli_close($link);
?>

有些人建议看看apache服务器日志,这里是日志的最后10条输出

::1 - - [24/Feb/2020:13:14:41 +0530] "GET /registration.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"
::1 - - [24/Feb/2020:13:14:43 +0530] "GET /registration.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"
::1 - - [24/Feb/2020:13:14:44 +0530] "GET /registration.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"
::1 - - [24/Feb/2020:13:14:45 +0530] "GET /registration.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"
::1 - - [24/Feb/2020:13:14:45 +0530] "GET /registration.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"
::1 - - [24/Feb/2020:13:14:45 +0530] "GET /registration.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"
::1 - - [24/Feb/2020:13:14:45 +0530] "GET /registration.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"
::1 - - [24/Feb/2020:13:14:45 +0530] "GET /registration.php HTTP/1.1" 500 185 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36"
::1 - - [24/Feb/2020:13:15:37 +0530] "-" 408 0 "-" "-"
::1 - - [24/Feb/2020:13:15:37 +0530] "-" 408 0 "-" "-"

尽管我的代码没有编码错误或查询结构错误,但为什么我的查询仍无法执行,我需要帮助。

php mysql linux forms mysqli
1个回答
0
投票

您错过了;

if (mysqli_query($conn, "CREATE table users"))
{
    printf("Query Executed!", mysqli_affected_rows($conn))    // <---- here
}

也请阅读mysqli_connect。您应该使用4个参数,但可以在其中一个参数中传递''值。

© www.soinside.com 2019 - 2024. All rights reserved.