VALUES ARE NOT SENDING TO THE DATABASE TABLE

Problems with the Windows version of XAMPP, questions, comments, and anything related.

VALUES ARE NOT SENDING TO THE DATABASE TABLE

Postby rithik » 24. July 2022 15:16

iT IS RETURNING BLANK VALUE.tHIS IS MY CODE:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['SUBMIT'])){
$conn= mysqli_connect("localhost","root","","user") or die("CONNECTION FAILLED:" .mysqli_connect_error());
if(isset($_POST['un']) && isset($_POST['fn']) && isset($_POST['mn']) && isset($_POST['ln']) && isset($_POST['email']) && isset($_POST['pn']) && isset($_POST['dob']) && isset($_POST['GENDER']) && isset($_POST['state']) && isset($_POST['pincode']) && isset($_POST['pwd'])){
$un=$_POST['un'];
$fn=$_POST['fn'];
$mn=$_POST['mn'];
$ln=$_POST['ln'];
$email=$_POST['email'];
$pn=$_POST['pn'];
$dob=$_POST['dob'];
$GENDER=$_POST['GENDER'];
$state=$_POST['state'];
$pincode=$_POST['pincode'];
$pwd=$_POST['pwd'];
$sql= "INSERT INTO 'user' ('USERNAME','FIRST_NAME','MIDDLE_NAME','LAST_NAME','EMAIL_ID','PHONE_NUMBER','DOB','GENDER','STATE','PINCODE','PASSWORD') VALUES('$un','$fn','$mn','$ln','$email','$pn','$dob','$GENDER','$state','$pincode','$pwd')";
$query = mysqli_query($sql,$conn);
if($query){
echo 'success';
}
else{
echo 'failed';
}
}
}
else{
echo "CONNECTION FAILLED:" .mysqli_connect_error();
}
?>
rithik
 
Posts: 1
Joined: 24. July 2022 15:13
XAMPP version: 2.4.53
Operating System: 10.0.22000

Re: VALUES ARE NOT SENDING TO THE DATABASE TABLE

Postby cb » 25. July 2022 06:04

I believe you have a few syntax errors in your sql statements ...

1) Remove the quotes from the db table and field names in the insert statement -

$sql= "INSERT INTO user (USERNAME,FIRST_NAME,MIDDLE_NAME,LAST_NAME,EMAIL_ID,PHONE_NUMBER,DOB,GENDER,STATE,PINCODE,PASSWORD) VALUES('$un','$fn','$mn','$ln','$email','$pn','$dob','$GENDER','$state','$pincode','$pwd')";

2) Change the order of the parameters to the mysqli_query statement

$query = mysqli_query($conn,$sql);

Give that a go.

(Note - This is NOT actually an issue with XAMPP so would probably would be better submitted to another forum focusing on mysql db queries/php syntax)
cb
cb
 
Posts: 36
Joined: 11. June 2008 22:48

Re: VALUES ARE NOT SENDING TO THE DATABASE TABLE

Postby Altrea » 25. July 2022 09:10

Hi,

cb already did a good reply to your issue.
Here just my 2 cents.

1) using single quotes for database, table and column names is wrong. You can use backticks ( `` ) to wrap them, but that is only neccessary if you are using for example column names matching reserved words. single quotes or double quotes are used for transmitting strings, like for the values you are using in your INSERT Statement.

2) Please read the manual for the function mysqli_query to get to know how and in which order it is used.

3) Please read the manual for the function mysqli_error to get to know how you can output an error message if your query fails.

4) Your last use of mysqli_connect_error is pointless. No database actoins are done at this section.

General hint: learn more about debugging.There is so much more you can do to check at which point your code stopped working, what the content of your variables are at this line line of your code and how you can do it better.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11937
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: VALUES ARE NOT SENDING TO THE DATABASE TABLE

Postby Nobbie » 25. July 2022 09:11

And switch on error reporting in php.ini
Nobbie
 
Posts: 13177
Joined: 09. March 2008 13:04


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 193 guests