Click here to Skip to main content
14,423,065 members
Rate this:
Please Sign up or sign in to vote.
See more:
Notice: Undefined variable: query in C:\xampp\htdocs\Project\EBY.php on line 87
ErrorINSERT INTO birth(Date, Celeb,Venue,STime,ETime,Guest,Age,Gender,Theme,Letter,Email,First,Last,Contact) VALUES('','','','',','','','','','','','','','')You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '','','','','','','','','','')' at line 2

<?php
$servername = "localhost";
	$username = "root";
	$password = "";
	
    $Date = $_POST['Date'];
	$nc = $_POST['nc'];
	$ven = $_POST['ven'];
	$STime  = $_POST['STime'];
	$ETime = $_POST['ETime'];
	$Gue = $_POST['Gue']; 
	$Gen= $_POST['Gen'];
	$Letter = $_POST['Letter'];
	$Theme = $_POST['Theme'];
    $fir = $_POST['first'];
	$las = $_POST['last'];
	$con = $_POST['con'];
	$email = $_POST['Email'];
	$age = $_POST['Age'];
	
$dbname = "dcprog";
	
	$conn = new mysqli($servername, $username, $password, $dbname);
	
	if($conn -> connect_error){
		
		echo("Connection Failed" . $conn -> connect_error);
	}
	$sql = "INSERT INTO birth(Date, Celeb,Venue,STime,ETime,Guest,Age,Gender,Theme,Letter,Email,First,Last,Contact)   
	VALUES('$Date','$nc','$ven','$STime','$ETime,'$Gue','$age','$Gen','$Theme','$Letter','$email','$fir','$las','$con')"; 
if($conn -> query($sql) === TRUE) {	
	
	if($Gue < 50)
	{

echo"<table align="center" width="700" cellspacing="5" cellpadding="5"><tbody><tr><td><center><h2>Reciept</h2></center></td></tr></tbody></table><hr>";	
echo"<table align="center" width="450" cellspacing="5" cellpadding="5"><tbody><tr><td><center> ";

echo"</center></td></tr></tbody></table><hr>";
echo"<width = 550 cellspacing = 5 cellpadding =5><table align="center" width="550" cellspacing="5" cellpadding="5"><tbody><tr><td>";
echo"</td></tr><tr><td>Day of the Event:</td><td>". $Date;
echo"</td></tr><tr><td>Name of the Celebrant:</td><td>" . $nc;
echo"</td></tr><tr><td>Venue:</td><td>" . $ven;
echo"</td></tr><tr><td>Starting Time of the Venue:</td><td>". $STime ;
echo"</td></tr><tr><td>Ending Time of the Venue:</td><td>". $ETime ;
	}
	if($Gue < 50)
	{
	$pack = 10000;
	$inclu = "Catering, Invitation letters and Location of the Party of the Party";	
	$them = 2000;
		echo"</td></tr><tr><td>Invited Guest:</td><td>". $Gue;
	}
	else if($Gue < 75 )
	{
	$pack = 12000;
	$them = 2000;
	$inclu = "Catering, Invitation letters, Location of the Party of the Party and Band";
		echo"</td></tr><tr><td>Invited Guest:</td><td>" . $Gue;
	}
	else if($Gue < 100)
	{
	$pack = 20000;
	$them = 2000;
	$inclu = "Unli-Catering, Invitation letters, Location of the Party of the Party and Band";	
	}
	else if( $Gue < 150)
	{
	$pack = 22000;
	$them = 2000;
	$inclu = "Unli-Catering, Invitation letters, Location of the Party of the Party, Host and Band";	
		echo"</td></tr><tr><td>Invited Guest:</td><td>" . $Gue;
	}
echo"</td></tr><tr><td>Theme:</td><td>". $evt;
echo"</td></tr><tr><td>Cake Price:</td><td>". $them ."pesos";
echo"</td></tr><tr><td>Wish to create Invitation:</td><td>". $Letter;
echo"</td></tr><tr><td>Package:</td><td>". $pack ."pesos";
echo"</td></tr><tr><td>Includes:</td><td>". $inclu;

$t = $pack + $them;
echo"</td></tr><tr><td>Total Payment :</td><td>". $t . "pesos";	
echo"</td></tr><tr><td>Thank You ". $las ." ". $fir . "We will contact at this No. ". $con . " Or with this email " . $email;
echo"</td></tr><tr><td>For any changes or Questions please contact us 091271304852 or email us Schoolfiles11@gmail.com";
echo"</td></tr></tbody></table>";	
	}
else {
		echo "Error".$query.$sql. $conn -> error;
	
	}
	$conn -> close();
	
	?>


What I have tried:

I dunno what to do I already try to change the db but it didnt work
Posted
Updated 15-Oct-17 1:25am
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

In error message: Did you noticed that there is a missing single quote in values ?
...
VALUES('','','','',','','','','','','','','','')
                   ^ quote missing here


$sql = "INSERT INTO birth(Date, Celeb,Venue,STime,ETime,Guest,Age,Gender,Theme,Letter,Email,First,Last,Contact)   
VALUES('$Date','$nc','$ven','$STime','$ETime,'$Gue','$age','$Gen','$Theme','$Letter','$email','$fir','$las','$con')";


Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
PHP: SQL Injection - Manual[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100