Jump to content

Query Failed


alvinchua

Recommended Posts

Hello, I have a problem where my script always giving me the error 'Query Failed'. Can anyone help me to figure out what is the problem with my code ? Thanks in advanced

 

 

<?php 
if(!require('connection.php')){

echo "Error in page process!";
}
$name=$_POST['name'];
$country=$_POST['country'];
$address=$_POST['address'];
$email=$_POST['email'];
$inquiry_type=$_POST['inquiry_type'];
$message=$_POST['message'];
$date=$_POST['date'];
$sql = "INSERT INTO inquiry VALUES(NULL,'".$name."','".$country."','".$email."','".$address."','".$inquiry_type."','".$message."','".$date."');";
$result = mysql_query($sql) or die ("Query failed!");
$to = "[email protected]";
$headers = "From:$email";
$sent = mail($to, "New inquiry", "Inquiry type:$inquiry_type\nPlease go to admin page to check the new inquiry.\n http://www.2ndhome-intl.com/admin/", $headers) ;
if(!$sent)
{print "We encountered an error sending your inquiry, please try again!"; }
else
{?>
<script language="javascript" type="text/javascript">
alert("Your inquiry has been submitted, Thank you");
window.location = "index.php";
</script>
<?php 
}?>

Link to comment
https://forums.phpfreaks.com/topic/156480-query-failed/
Share on other sites

Why not get php/mysql to tell you why it failed. Add a mysql_error() statement to your die() statement -

 

$result = mysql_query($sql) or die ("Query failed! " . mysql_error());

 

P.S. A require() statement that fails is a fatal runtime error. Code execution stops at the require() statement and your echo "Error in page process!"; will never be executed if the require() fails.

Link to comment
https://forums.phpfreaks.com/topic/156480-query-failed/#findComment-823994
Share on other sites

Possible case:

 

<?php 
if(!require('connection.php')){

echo "Error in page process!";
}
$name=mysql_real_escape_string($_POST['name']);
$country=mysql_real_escape_string($_POST['country']);
$address=mysql_real_escape_string($_POST['address']);
$email=mysql_real_escape_string($_POST['email']);
$inquiry_type=mysql_real_escape_string($_POST['inquiry_type']);
$message=mysql_real_escape_string($_POST['message']);
$date=mysql_real_escape_string($_POST['date']);
$sql = "INSERT INTO inquiry VALUES(NULL,'".$name."','".$country."','".$email."','".$address."','".$inquiry_type."','".$message."','".$date."');";
$result = mysql_query($sql) or die ("Query failed!");
$to = "[email protected]";
$headers = "From:$email";
$sent = mail($to, "New inquiry", "Inquiry type:$inquiry_type\nPlease go to admin page to check the new inquiry.\n http://www.2ndhome-intl.com/admin/", $headers) ;
if(!$sent)
{print "We encountered an error sending your inquiry, please try again!"; }
else
{?>
<script language="javascript" type="text/javascript">
alert("Your inquiry has been submitted, Thank you");
window.location = "index.php";
</script>
<?php 
}?>

Link to comment
https://forums.phpfreaks.com/topic/156480-query-failed/#findComment-823997
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.