473,387 Members | 3,684 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

mysql error: You have an error in your SQL syntax;

My old problem is solved, but im running into a new error. I figured I would start a new topic, sorry if this was incorrect to do.

mysql 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 'AND A.ID = P.ID' at line 4

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. /* Display a vote form. */
  3. require_once("vote_config.php");
  4. $poll = $_GET['poll'];
  5.  
  6. /*if (!is_numeric($poll)) 
  7.   {
  8.     die("Invalid poll");
  9.   }*/
  10.  
  11. /* Look up the poll in the database. */
  12. $sql = "SELECT P.question, A.answer, A.answer_ID
  13.           FROM poll P, answer A
  14.          WHERE P.ID = $poll
  15.            AND A.ID = P.ID";
  16.  
  17. $result = mysql_query($sql, $db) or die ("mysql error: " . mysql_error());
  18.  
  19. if (mysql_num_rows($result) == 0) 
  20.   {
  21.     die('Invalid poll.');
  22.   }
  23.  
  24. /* If the user has already voted, show the results. */
  25. if ($_COOKIE["poll_voted_$poll"]) {
  26.     header("Location: vote_tally.php?poll=$poll");
  27.     exit;
  28. }
  29.  
  30. /* Vote form */
  31. $question_list = "";
  32. while($row = mysql_fetch_array($result)) {
  33.     $question = $row['question'];
  34.     $question_list .= '<li><input name="answer" type="radio" value="' .
  35.                       $row['answer_ID'] . '"> ' . $row['answer'] .
  36.                       '</li>';
  37. }
  38. ?>
  39. <html>
  40. <head></head>
  41. <body>
  42. <span style="font-size: 12px;">
  43. <span style="font-weight: bold; font-size: 14px;">
  44.     Poll #<?php print $poll; ?>
  45. </span><br />
  46. <span style="font-weight: bold"><?php print $question; ?></span>
  47. <form action="vote_process.php" method="post">
  48. <ul style="list-style-type: none;">
  49. <?php print $question_list; ?>
  50. </ul>
  51. <input name="poll" type="hidden" value="<?php print $poll; ?>">
  52. <input name="" type="submit" value="Vote!">
  53. </form>
  54. </span>
  55. </body></html
The part I commented out:
Expand|Select|Wrap|Line Numbers
  1. /*if (!is_numeric($poll)) 
  2.   {
  3.     die("Invalid poll");
  4.   }*/
Kept returning invalid poll, even though it is not invalid, and the table is populated. How do I get rid of these errors? Thanks in advance.

EDIT: on line 14 I put ' ' around $poll and commented out:

Expand|Select|Wrap|Line Numbers
  1. /*if (!is_numeric($poll)) 
  2.   {
  3.     die("Invalid poll");
  4.   }*/
and

Expand|Select|Wrap|Line Numbers
  1. /*if (mysql_num_rows($result) == 0) 
  2.   {
  3.     die("Invalid poll.");
  4.   }*/
the code runs, but the poll isnt populated. You can check it out at http://www.ruckusinc.net/projects/vote_form.php
Feb 18 '10 #1
3 2743
Atli
5,058 Expert 4TB
Hey.

The part you commented out is there to validate the $_GET['poll'] value. If it keeps telling you it is invalid, odds are that it is invalid. Commenting the validation code out won't make the input valid :)

Try un-commenting that and adding a var_dump() before the die().
Expand|Select|Wrap|Line Numbers
  1. if (!is_numeric($poll))
  2. {
  3.     var_dump($poll);
  4.     die("Invalid poll");
  5. }
Also, when a SQL query fails and you can't spot the problem, it is always a good idea to print the query, just to see what is really going on.
Feb 18 '10 #2
I put in the var_dump($poll); and uncommented that section and it returned NULL.
That's weird because I have information in that table I am trying to get

EDIT: Its gotta be something with the line

Expand|Select|Wrap|Line Numbers
  1. $poll = $_GET['poll'];
  2.  
that is goofing up the code.
Feb 18 '10 #3
Atli
5,058 Expert 4TB
That line simply fetches the poll variable from the URL.

Your URL should be looking something like:
- http://example.com/page.php?poll=1

If you leave out the ?poll=1 part the $poll variable will be NULL and the die("Invalid poll"); statement is executed. - I assumed that was the reason you put it there; to let you know the poll ID was missing.
Feb 18 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Morten Gulbrandsen | last post by:
Hi programmers, I try to investigate some of the basics behind schemas and cataloges, Which is part of SQL2 Language this is the error message I get:
0
by: Fatt Shin | last post by:
Hi, I'm running MySQL 4.0.13, connecting from PowerBuilder 9 using ODCB Connector 3.51. I'm facing a problem where whenever I issue a SELECT COUNT(*) statement from PowerBuilder, I always get SQL...
0
by: Mario Ohnewald | last post by:
Hello! I want to import a MySQL 3.x Databse to my new shiny MySQL4.x. I did a backup with /usr/local/mysql-standard-4.0.14-pc-linux-i686/bin/mysqldump -u root -p --opt -A > mysql_lamp_backup.`date...
4
by: Adam Smith | last post by:
I have a dedicated server running 'FreeBSD 4.9 STABLE' at a hosting site. They have done some default installations, presumably from the CVS ports package ??. Herein lies the problem, "I do not...
13
by: wideangle | last post by:
Hello there! I know it's stupid, but when creating a table in a mysql (win32) database, it won't let me create this "mytable". Here goes my ER_PARSE_ERROR. mysql> CREATE TABLE `mytable` ( ->...
2
by: speralta | last post by:
My tired old eyes may be failing me, but the following insert statements look correct to me, but I can't seem to get a clean insert from a fairly large text file database into mysql. I was...
1
by: Ike | last post by:
Recently, I began using a different MySQL verver (i.e. different machine as well as different version#, going from 4.12a to 4.1.9 max). The following query used to work: select firstname,...
1
by: ajos | last post by:
hi evrybdy, the problem is:- i had this running before in jsp but when i changed the jsp page using struts tags there occoured a problem... when i enter values in the 2 text boxes and click enter...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
5
by: gsaray101 | last post by:
I am trying to set up one server with multiple mysql dbs. This script will get the mysqldump files from the ftp server and based on the name of the server in the file, it will create the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.