0

Hiy guys alot of you have been brilliant over the past few days. I'm creating my own website and I want to let users register and log in, into the site

I'm now getting this error message
Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\submit-form.php on line 19
The following SQL Failed INSERT INTO 'users' (firstname, lastname, username, confirmusername, password, confirmpassword, email ,confirmemail) VALUES ('richard', 'Hemmings', 'hemmo001', 'password', 'password', 'richardgwhemmings@msn.com' , 'richardgwhemmings@msn.com')

<?php

//select your database
//$b=mysql_select_db("database_name",$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', '$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>';
?>

I've been looking at it all day now and I just need some advice

5
Contributors
13
Replies
60
Views
3 Years
Discussion Span
Last Post by iamthwee
Featured Replies
  • 1

    Do NOT use single quotes around column names, use none or backticks instead. Read More

  • 2

    Sorry bro I down repped you - just being anal I guess. Your INITIAL example shows: `INSERT INTO users ('firstname', 'lastname', 'username', 'confirmusername', 'password', 'confirmpassword', 'email' ,'confirmemail')` as being single quotes and NOT backticks, you're above example shows the correction. This is part of why the OP is struggling with … Read More

-1

Have you tried:

$query="INSERT INTO users ('firstname', 'lastname', 'username', 'confirmusername', 'password', 'confirmpassword', 'email' ,'confirmemail') VALUES ('$firstname', '$lastname', '$username', '$password', '$confirmpassword', '$email' , '$confirmemail')";

?

0

i've tried that as you have said and I'm getting the following

Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\submit-form.php on line 19
The following SQL Failed INSERT INTO users ('firstname', 'lastname', 'username', 'confirmusername', 'password', 'confirmpassword', 'email' ,'confirmemail') VALUES ('richard', 'Hemmings', 'hemmo001', 'password', 'password', 'richardgwhemmings@msn.com' , 'richardgwhemmings@msn.com')

Not sure where I'm going wrong

0

Well, in this statement: $result = mysqli_query($connection,$query); where do you define $connection?

0

that must be it, i take it i need to define that at the top of submit-form.php?

something like this $connection = mysqli_connection?

0

when i put this into the submit-form.php it dosent seem to like it

<?php

//select your database
//$b=mysql_select_db("database_name",$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");
$connection = mysqli_connection?

//mysql query to insert value to database
$query="INSERT INTO users ('firstname', 'lastname', 'username', 'confirmusername', 'password', 'confirmpassword', 'email' ,'confirmemail') VALUES ('$firstname', '$lastname', '$username', '$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>';
?>

Its throwning up an error by the $query=INSERT

0

$connection = mysqli_connect("host", "username", "password", "mybd") or die("Error!!");

Try this. You need to connect to a database, before you can do anything. The rest of your code looks to be working fine now. Just need to give the query a valid connection.

peace

1

Do NOT use single quotes around column names, use none or backticks instead.

Edited by pritaeas

0

I take it this has to go into the submit-form.php?

$connection = mysqli_connect("host", "username", "password", "mybd") or die("Error!!");

if so I have put this into that files and I'm still getting the following:

Warning: mysqli_query(): Couldn't fetch mysqli in C:\xampp\htdocs\submit-form.php on line 19
The following SQL Failed INSERT INTO users ('firstname', 'lastname', 'username', 'confirmusername', 'password', 'confirmpassword', 'email' ,'confirmemail') VALUES ('richard', 'Hemmings', 'hemmo001', 'password', 'password', 'richardgwhemmings@msn.com' , 'richardgwhemmings@msn.com')

0

I will do, would it be easier to simplify the query and just to have
-username and
-password?

1

@down-voter

Why did my post get downvoted for suggesting an improvement? I.e.

$query="INSERT INTO 'users' (`firstname`, `lastname`, `username`, `confirmusername`, `password`, `confirmpassword`, `email` ,`confirmemail`) VALUES ('$firstname', '$lastname', '$username', '$password', '$confirmpassword', '$email' , '$confirmemail')";

Notice how the single string quotes are wrong? Don't get click happy and read what the suggestion is before you go ahead and just down-vote. Tyvm

Votes + Comments
still love ya no homo
2

Sorry bro I down repped you - just being anal I guess. Your INITIAL example shows:

INSERT INTO users ('firstname', 'lastname', 'username', 'confirmusername', 'password', 'confirmpassword', 'email' ,'confirmemail')

as being single quotes and NOT backticks, you're above example shows the correction. This is part of why the OP is struggling with a correct solution AND the fact they don't grasp basic PHP as demonstrated by line 15:

$connection = mysqli_connection?

with the question mark.

The real problem is there are 8 variables to insert but the op is only inserting 7.

Edited by iamthwee

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.