doucheng9634 2014-04-01 22:13
浏览 58
已采纳

mysqli_query不接受我的mysqli_connect并正确使用mysqli_query的参数

i have set my configdb.php on a different page and include it on my other php pages..

here is my configdb.php

<?php
$hostname ="localhost";
$username ="root";
$password ="";
$db ="practicedb";
$connect = mysqli_connect($hostname,$username,$password) or die("cannot connect to server");
mysqli_select_db($connect,$db) or die("database not found!");
?>

these are the errors that i get:

Notice: Undefined variable: configdb in /Applications/XAMPP/xamppfiles/htdocs/practicesystem/add.php on line 14

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /Applications/XAMPP/xamppfiles/htdocs/practicesystem/add.php on line 14

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /Applications/XAMPP/xamppfiles/htdocs/practicesystem/add.php on line 15

Notice: Undefined variable: configdb in /Applications/XAMPP/xamppfiles/htdocs/practicesystem/add.php on line 28

this is my add.php where i INSERT items into database from the $_POST method from a previous php page..

<?php
include "configdb.php";



$studid=$_POST['studid'];
$lastname=mysql_real_escape_string($_POST['lastname']);
$firstname= mysql_real_escape_string($_POST['firstname']);
$middlename= mysql_real_escape_string($_POST['middlename']);
$email=$_POST['email'];


$check = "SELECT * from studinfo where stud_id = '".$studid."'";
$qry = mysqli_query($configdb,$check);
$num_rows = mysqli_num_rows($qry); 


if($num_rows > 0){
// Here we are checking if username is already exist or not.

    echo "The person you have entered is already existing. Please try again.";
    echo '<a href="index.php">Try Again</a>';
    exit;
}

$query = "INSERT INTO studinfo (stud_id,lastname,firstname,middlename,email) VALUES ('".$studid."','".$lastname."','".$firstname."','".$middlename."','".$email."');";
//echo $query;
mysqli_query($configdb, $query);
echo "Thank You for Registration.";
echo '<a href="index.php">Click Here</a> to login you account.';
exit;
?>

i don't know and i am not sure what to put on the first parameter of mysqli_query.. i tried putting this code $con=mysqli_connect("localhost","root","","practicedb"); it worked but its not practical putting that on every php page where i should connect to the database...

  • 写回答

1条回答 默认 最新

  • dongwalun2507 2014-04-01 22:15
    关注

    Yet another question on a silly typo...

    $connect = mysqli_connect( ...
    vs. $qry = mysqli_query($configdb,$check);

    so the error message clearly says: Undefined variable: configdb

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案