0

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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

i see, so i'm gonna use the $connect from the $configdb page right? thanks! i thought the first parameter was the page itself.. silly me... lemme try that!
omg, that worked.. thank you very much for that... i was rather giggling when i read your name.. i really need that haha! thanks again!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.