[HELP] query string problem, again

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

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

[HELP] query string problem, again

Post by bla5e »

Code: Select all

<?php
mysql_connect(localhost, -usn- , -pw- ) or die ('I cannot connect to the database because: ' . mysql_error()); 
mysql_select_db(-db-);
$sql = mysql_query("INSERT INTO `members` (id, shortname, fullname, age, car, location, state, body, engine, brag, future) VALUES ('', '".$_POST['shortname']."','".$_POST['fullname']."','".$_POST['age']."','".$_POST['car']."','".$_POST['location']."','".$_POST['state']."', '".$_POST['body']."','".$_POST['engine']."','".$_POST['brag']."','".$_POST['future']."')") or die(mysql_error());

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

$contact = mysql_query("INSERT INTO `contact` (id, fullname, age, location, phone, email) VALUES ('', '".$_POST['fillname']."', '".$_POST['age']."', '".$_POST['location']."', '".$_POST['phone']."', '".$_POST['email']."')") or die(mysql_error());
mysql_query($contact) or die(mysql_error());
	
echo "Added '".$_POST['fullname']."' to the members list on the website <br><br>";
echo "Added '".$_POST['fullname']."' to the contact list on the Damian Contact site<br><br>";
?>

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
help please.. i hate these dumb errors...
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You most likely have an apostrophe in one of your variables.

call mysql_real_escape_string on all of your variables before you put them into the query.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

fillname versus fullname mistype too.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

i still get same error
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

as per usual, echo out the query string you are sending to MySQL. Try running that echoed line in phpMyAdmin. If you are confused about the line output, post it here.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

i did the echo thing, and all the variables where there... but i dont understand what u mean with phpmyadmin
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

phpmyadmin is a webbased program that allows you to work with databases. you will have it with any standard cPanel
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

i know what it is, but i dont know what he means by running the echoed line in it
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

heres updated code.. still wont work:

Code: Select all

<?php
	
	$engine = nl2br ("'".$_POST['engine']."'");
	$body = nl2br ("'".$_POST['body']."'");
	$brag = nl2br ("'".$_POST['brag']."'");
	$future = nl2br ("'".$_POST['future']."'");	
		
	mysql_connect(localhost, -user- , -password- ) or die ('I cannot connect to the database because: ' . mysql_error()); 
	mysql_select_db(-database-);
	$sql = mysql_query("INSERT INTO `members` (id, shortname, fullname, age, car, location, state, body, engine, brag, future) VALUES ('', '".$_POST['shortname']."','".$_POST['fullname']."','".$_POST['age']."','".$_POST['car']."','".$_POST['location']."','".$_POST['state']."',$body, $engine, $brag, $future") or die(mysql_error());
	mysql_query($sql) or die(mysql_error()); 
	$contact = mysql_query("INSERT INTO `contact` (id, fullname, age, location, phone, email, car) VALUES ('', '".$_POST['fullname']."', '".$_POST['age']."', '".$_POST['location']."', '".$_POST['phone']."', '".$_POST['email']."', '".$_POST['car']."')") or die(mysql_error());
	mysql_query($contact) or die(mysql_error());
	
	echo "Added '".$_POST['fullname']."' to the members list on the website <br><br>";
	echo "Added '".$_POST['fullname']."' to the contact list on the Damian Contact site<br><br>";
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

why on earth are you performing a second mysql_query() on the return result from mysql_query() ?
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

its goin to a different table
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

uhm... you have four (count them, four) mysql_query() calls in your code. I was talking about the first pair and second pair as seperate entities. I realize that is/was your intention.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

Code: Select all

<?php
	
	$engine = nl2br ("'".$_POST['engine']."'");
	$body = nl2br ("'".$_POST['body']."'");
	$brag = nl2br ("'".$_POST['brag']."'");
	$future = nl2br ("'".$_POST['future']."'");	
		
	mysql_connect(localhost, members, yessir) or die ('I cannot connect to the database because: ' . mysql_error()); 
	mysql_select_db(members);
	mysql_query("INSERT INTO `members` (id, shortname, fullname, age, car, location, state, body, engine, brag, future) VALUES ('', '".$_POST['shortname']."','".$_POST['fullname']."','".$_POST['age']."','".$_POST['car']."','".$_POST['location']."','".$_POST['state']."',$body, $engine, $brag, $future") or die(mysql_error());
	mysql_query("INSERT INTO `contact` (id, fullname, age, location, phone, email, car) VALUES ('', '".$_POST['fullname']."', '".$_POST['age']."', '".$_POST['location']."', '".$_POST['phone']."', '".$_POST['email']."', '".$_POST['car']."')") or die(mysql_error());
	
	
	echo "Added '".$_POST['fullname']."' to the members list on the website <br><br>";
	echo "Added '".$_POST['fullname']."' to the contact list on the Damian Contact site<br><br>";
?>
there should only be 2 now...
still same error about line 1 or whatever though
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

so which one is erroring? Have you echoed that query string to make sure it's the correct syntax?
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

ok heres the new code:

Code: Select all

<?php
	
	$engine = nl2br ("'".$_POST['engine']."'");
	$body = nl2br ("'".$_POST['body']."'");
	$brag = nl2br ("'".$_POST['brag']."'");
	$future = nl2br ("'".$_POST['future']."'");	
	
	$server = "localhost";
	$user = "-hidden-";
	$password = "-hidden-";	
                $database = "-hidden-";	

	mysql_connect($server, $user, $password) or die ('I cannot connect to the database because: ' . mysql_error()); 
	mysql_select_db($database);
	mysql_query("INSERT INTO `members` (id, shortname, fullname, age, car, location, state, body, engine, brag, future) VALUES ('', '".$_POST['shortname']."','".$_POST['fullname']."','".$_POST['age']."','".$_POST['car']."','".$_POST['location']."','".$_POST['state']."', '$body', '$engine', '$brag', '$future') or die(mysql_error()");
	mysql_query("INSERT INTO `contact` (id, fullname, age, location, phone, email, car) VALUES ('', '".$_POST['fullname']."', '".$_POST['age']."', '".$_POST['location']."', '".$_POST['phone']."', '".$_POST['email']."', '".$_POST['car']."')") or die(mysql_error());	
	
	echo "Added '".$_POST['fullname']."' to the members list on the website <br><br>";
	echo "Added '".$_POST['fullname']."' to the contact list on the Damian Contact site<br><br>";
?>
It will only execute the last query (the contact table one)... how do i get it to run both?
Post Reply