Results 1 to 8 of 8
Thread: Need MySQL help
-
10-03-2003, 03:58 PM #1Newbie
- Join Date
- Aug 2003
- Location
- Western Australia
- Posts
- 5
Need MySQL help
Hi everyone,
I need some help with a MySQL/php form, it's complaining about something I've just added and I can't work out what's wrong. Here's the error I got:
You have an error in your SQL syntax near 'bureauinf='0', churchinf='0', financeinf='0', healthinf='0', highinf='0', indust' at line 1** 1064
And here's the code for what I added:
Code:$bureauinf=$data['bureauinf'];$churchinf=$data['churchinf']; $financeinf=$data['financeinf'];$healthinf=$data['healthinf']; $highinf=$data['highinf'];$industryinf=$data['industryinf']; $legalinf=$data['legalinf'];$mediainf=$data['mediainf']; $occultinf=$data['occultinf'];$policeinf=$data['policeinf']; $politicsinf=$data['politicsinf'];$streetinf=$data['streetinf']; $transportinf=$data['transportinf'];$underworldinf=$data['underworldinf']; $universityinf=$data['universityinf']; $sql=$sql."bureauinf='$bureauinf', churchinf='$churchinf', financeinf='$financeinf', healthinf='$healthinf', "; $sql=$sql."highinf='$highinf', industryinf='$industryinf', legalinf='$legalinf', mediainf='$mediainf', "; $sql=$sql."occultinf='$occultinf', policeinf='$policeinf', politicsinf='$politicsinf', streetinf='$streetinf', "; $sql=$sql."transportinf='$transportinf', underworldinf='$underworldinf', universityinf='$unversityinf', "; $result=mysql_query($sql);
Tatha
-
10-03-2003, 04:11 PM #2Junior Guru Wannabe
- Join Date
- Sep 2003
- Posts
- 64
You're ending the SQL query with a comma AND not terminating it with a semicolon, for starters..?
-
10-03-2003, 04:14 PM #3Newbie
- Join Date
- Aug 2003
- Location
- Western Australia
- Posts
- 5
I saw that and fixed it, but it's still giving me grief
-
10-03-2003, 04:17 PM #4Junior Guru Wannabe
- Join Date
- Sep 2003
- Posts
- 64
What is $sql set to before these lines?
-
10-03-2003, 04:21 PM #5Web Hosting Master
- Join Date
- Sep 2002
- Location
- Illinois
- Posts
- 2,307
PHP Code:$sql = "SELECT * FROM table WHERE ";
$bureauinf=$data['bureauinf'];
$churchinf=$data['churchinf'];
$financeinf=$data['financeinf'];
$healthinf=$data['healthinf'];
$highinf=$data['highinf'];
$industryinf=$data['industryinf'];
$legalinf=$data['legalinf'];
$mediainf=$data['mediainf'];
$occultinf=$data['occultinf'];
$policeinf=$data['policeinf'];
$politicsinf=$data['politicsinf'];
$streetinf=$data['streetinf'];
$transportinf=$data['transportinf'];
$underworldinf=$data['underworldinf'];
$universityinf=$data['universityinf'];
$sql .= "bureauinf = '\$bureauinf', churchinf = '\$churchinf', financeinf = '\$financeinf', healthinf = '\$healthinf', ";
$sql .= "highinf = '\$highinf', industryinf = '\$industryinf', legalinf ='\$legalinf', mediainf = '\$mediainf', ";
$sql .= "occultinf = '\$occultinf', policeinf = '\$policeinf', politicsinf = '\$politicsinf', streetinf = '\$streetinf', ";
$sql .= "transportinf = '\$transportinf', underworldinf = '\$underworldinf', universityinf = '\$unversityinf'";
$result=mysql_query($sql);
How's my programming? Call 1-800-DEV-NULL
-
10-03-2003, 04:22 PM #6Newbie
- Join Date
- Aug 2003
- Location
- Western Australia
- Posts
- 5
Code:$sql="Select * from charsheets where name='$charname'";
-
10-03-2003, 05:07 PM #7Junior Guru Wannabe
- Join Date
- Sep 2003
- Posts
- 64
First, scratch those slashes you've added in there before each $.
Second, there is no space between
Code:$sql = "Select * from charsheets WHERE name='$charname'";
Code:$sql .= "bureainf blah blah";
Example:
Code:$sql = "SELECT * FROM charsheets WHERE name='$charname'"; $sql .= " AND bureauinf='$bureauinf' AND churchinf='$churchinf' AND financeinf='$financeinf'";
-
10-03-2003, 05:12 PM #8Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
You don't need a semicolon at the end of your query, iirc, it will not execute with a semicolon at the end. You however do need a semicolon to terminate the statement.
PHP Code:// Not this
$query = "SELECT * FROM table WHERE field = 'value';";
//But this
$query = "SELECT * FROM table WHERE field = 'value'";