Page 1 of 2
[HELP] query string problem, again
Posted: Thu Aug 11, 2005 5:22 pm
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...
Posted: Thu Aug 11, 2005 5:23 pm
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.
Posted: Fri Aug 12, 2005 5:22 am
by feyd
fillname versus fullname mistype too.
Posted: Fri Aug 12, 2005 12:52 pm
by bla5e
i still get same error
Posted: Fri Aug 12, 2005 1:10 pm
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.
Posted: Fri Aug 12, 2005 1:31 pm
by bla5e
i did the echo thing, and all the variables where there... but i dont understand what u mean with phpmyadmin
Posted: Fri Aug 12, 2005 1:42 pm
by shiznatix
phpmyadmin is a webbased program that allows you to work with databases. you will have it with any standard cPanel
Posted: Fri Aug 12, 2005 1:52 pm
by bla5e
i know what it is, but i dont know what he means by running the echoed line in it
Posted: Sun Aug 14, 2005 10:01 pm
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>";
?>
Posted: Sun Aug 14, 2005 10:20 pm
by feyd
why on earth are you performing a second mysql_query() on the return result from mysql_query() ?
Posted: Sun Aug 14, 2005 10:45 pm
by bla5e
its goin to a different table
Posted: Sun Aug 14, 2005 11:53 pm
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.
Posted: Mon Aug 15, 2005 7:41 am
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
Posted: Mon Aug 15, 2005 7:47 am
by feyd
so which one is erroring? Have you echoed that query string to make sure it's the correct syntax?
Posted: Mon Aug 15, 2005 5:14 pm
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?