rich_hemmo Posted April 22, 2014 Share Posted April 22, 2014 Hi guys I know this might be a repeated post, someone has looked at the code and they seem to think that it all look fine, but I'm getting this following message againWarning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\submit-form.php on line 19The following SQL Failed INSERT INTO 'users' ('firstname', 'lastname', 'username', 'confirmusername', 'password', 'confirmpassword', 'email' ,'confirmemail') VALUES ('richard', 'Hemmings', 'hemmo001', 'hemmo001', 'password', 'password', 'richardgwhemmings@msn.com' , 'richardgwhemmings@msn.com')I just cant seem to see where I'm going wrong, at first there was a single quote missing from firstname' this I have now addressed, I've been woriking on this now for 2 weeks today!Config.php <?php $connection = mysqli_connect("localhost","root","","registration"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_close($connection); ?> submit-form.php <?php $connection = mysqli_connect("localhost", "root", "", "registration") or die("Error!!"); //select your database //$b=mysql_select_db("Registration",$a); $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $username=$_POST['username']; $confirmusername=$_POST['confirmusername']; $password=$_POST['password']; $confirmpassword=$_POST['confirmpassword']; $email=$_POST['email']; $confirmemail=$_POST['confirmemail']; //Database connection require_once("config.php"); //mysql query to insert value to database $query = "INSERT INTO `users` (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email`, `confirmemail`) VALUES ('$firstname', '$lastname', '$username', '$confirmusername', '$password', '$confirmpassword', '$email', '$confirmemail')"; $result = mysqli_query($connection,$query); //if value inserted successyully disply success message if(!$result) { die("The following SQL Failed $query"); } echo 'Registred successfully..!!</div>'; ?> Any help would be appreciatedĀ Quote Link to comment https://forums.phpfreaks.com/topic/287930-mysqli_query-couldnt-fetch-mysqli/ Share on other sites More sharing options...
mac_gyver Posted April 22, 2014 Share Posted April 22, 2014 the error is because you have closed the mysqli connection at the end of your config.php file. Quote Link to comment https://forums.phpfreaks.com/topic/287930-mysqli_query-couldnt-fetch-mysqli/#findComment-1476919 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.