Code problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Code problem

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

bla5e, you're not echoing out the query string... :?
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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;
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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());
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

i got it to work, but thanks for the help everyone! greatly appriciated
Post Reply