Page 1 of 1

Code problem

Posted: Thu Aug 04, 2005 5:17 pm
by bla5e

Code: Select all

if (!$name) {echo "You must enter your full name."; } else {
if (!$email) {echo "We need your Email"; } else {
if (!$phone) {echo "We must know your phone number to get back to you."; } else {
if (!$location) {echo "Please fill out the location section."; } else {
if (!$other ) {
    if (!$yr) {echo "Please fill out the year of your car."; } else {
    if (!$make) {echo "Please fill out the make of your car"; } else {
    if (!$model) {echo "Please fill out the model of your car"; } else {
		}
		}
		}
}
if (!$car) {echo "Please include a link to a picture of your car."; } else {
if (!$self) {echo "Please include a link to a picture of your self."; } else {
include ("join/config.php");
mysql_connect($server, $user, $password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error()); 
$sql = mysql_query("INSERT INTO `join` (id, name, email, phone, location, yr, make, model, car, self) VALUES ('', '".$_POST['name']."','".$_POST['email']."','".$_POST['phone']."','".$_POST['location']."','".$_POST['yr']."','".$_POST['make']."','".$_POST['model']."','".$_POST['car']."','".$_POST['self']."')") or die(mysql_error());		   
mysql_query($sql) or die(mysql_error()); 
echo ("Thank you for your request to Join our Team.<br> We will get back to you as soon as possible.<br> ");

$SiteName = "Team Exile";
$SiteEmail = "hondavtecdriver@gmail.com";
$ThankYouMessage = "Thank you from Team Exile";
$SiteUserName = "Team Exile";	
$AdminMessage .= "Another Request to Join the Team \n";
mail("$SiteEmail", "Team Exile", $AdminMessage, "From: $email"); 
}
}		
}
}	
}
}


The Error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
But the thing is, it will still submit it to the database... It also will not email me.


help please? i cant figure out whats wrong

Posted: Thu Aug 04, 2005 5:56 pm
by feyd
echo out the query string to determine where in the query it's failing, and check visually if you see anything wrong.. I'm guessing an input may contain a quote mark.

Posted: Fri Aug 05, 2005 11:01 am
by bla5e

Code: Select all

<?php
case '4b':
	if (!$name) {echo "You must enter your full name."; } else {
	if (!$email) {echo "We need your Email"; } else {
	if (!$phone) {echo "We must know your phone number to get back to you."; } else {
	if (!$location) {echo "Please fill out the location section."; } else {
	if (!$other ) {
		if (!$yr) {echo "Please fill out the year of your car."; } else {
		if (!$make) {echo "Please fill out the make of your car"; } else {
		if (!$model) {echo "Please fill out the model of your car"; } else {
		}
		}
		}
	}
	if (!$car) {echo "Please include a link to a picture of your car."; } else {
	if (!$self) {echo "Please include a link to a picture of your self."; } else {
		echo mysql_error();
		include ("join/config.php");
		echo mysql_error();
		mysql_connect($server, $user, $password) or die(mysql_error());
		mysql_select_db($database) or die(mysql_error()); 
		echo mysql_error();
		$sql = mysql_query("INSERT INTO `join` (id, name, email, phone, location, yr, make, model, car, self) VALUES ('', '".$_POST['name']."','".$_POST['email']."','".$_POST['phone']."','".$_POST['location']."','".$_POST['yr']."','".$_POST['make']."','".$_POST['model']."','".$_POST['car']."','".$_POST['self']."')") or die(mysql_error());		   
		mysql_query($sql) or die(mysql_error()); 
		echo ("Thank you for your request to Join our Team.<br> We will get back to you as soon as possible.<br> ");
		echo mysql_error();
		$SiteName = "Team Exile";
		$SiteEmail = "hondavtecdriver@gmail.com";
		$ThankYouMessage = "Thank you from Team Exile";
		$SiteUserName = "Team Exile";	
		$AdminMessage .= "Another Request to Join the Team \n";
		mail("$SiteEmail", "Team Exile", $AdminMessage, "From: $email"); 
		echo mysql_error();
	}
	}		
	}
	}	
	}
	}	
	
break;	
?>
still same error
please help!

Posted: Fri Aug 05, 2005 11:06 am
by s.dot
Usually when I get errors at line 1 I have a single quote in my SQL syntax

something like

Code: Select all

$var = "don't tell me";

$SQL = "INSERT INTO table (col) VALUES('$var')";
This will give me that kind of error.

Posted: Fri Aug 05, 2005 11:24 am
by feyd
bla5e, you're not echoing out the query string... :?

Posted: Fri Aug 05, 2005 12:09 pm
by bla5e
ok i echod it and this is what i get now
mysql_query(1,Resource id #3) or die(mysql_error())
Thank you for your request to Join our Team.
We will get back to you as soon as possible.

Posted: Fri Aug 05, 2005 12:19 pm
by s.dot
You're echoing out the result, not the query it's self, which is why you get "result resource"

Separate your sql from the query

Code: Select all

$SQL = "INSERT INTO foo(col) VALUES bar('$value')";

echo $SQL;

Posted: Fri Aug 05, 2005 12:27 pm
by shiznatix
you are inserting a blank value into a auto incrementing fiend (your id)
you cant do that, just take out id and take out the
'' that you have for its value other than that i dont see a
problem in your sql.

plus it is a good idea to seperate your sql

Code: Select all

$sql = '
  select
    *
  from
    table_name
  where
    stuff = "'.$stuff.'"
';

$do_query = mysql_query($sql) or die(mysql_error());

Posted: Fri Aug 05, 2005 1:03 pm
by bla5e
i got it to work, but thanks for the help everyone! greatly appriciated