[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Easy Q: Error in SQL Syntax

Posted on 2005-05-08
6
Medium Priority
?
258 Views
Last Modified: 2013-12-12
 $sql = "select d.pictype, d.title, d.joke, d.hits, d.rating, d.userid, d.type, c.category from jokes d, categories c

where d.jokeid = $jokeid and c.catid = d.catid";

What's the error?

{ Moved to PHP & Databases - Diablo84/PHP Page Editor }
0
Comment
Question by:benwiggy
  • 3
  • 3
6 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 500 total points
ID: 13953842
The only possible error I can find is the use of $jokeid. What I mean is that the query will fail if $jokeid is empty.

Make sure that $jokeid is set, and maybe change your query to this:

 $sql = "select d.pictype, d.title, d.joke, d.hits, d.rating, d.userid, d.type, c.category from jokes d, categories c
where d.jokeid = '$jokeid' and c.catid = d.catid";

Batalf
0
 
LVL 6

Author Comment

by:benwiggy
ID: 13953854
Lol that did it!
0
 
LVL 6

Author Comment

by:benwiggy
ID: 13953859
Can I ask why do the quotes make a difference?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 32

Expert Comment

by:Batalf
ID: 13953870
It means that $jokeid was empty

it would generate a query like this:

select d.pictype, d.title, d.joke, d.hits, d.rating, d.userid, d.type, c.category from jokes d, categories c
where d.jokeid =  and c.catid = d.catid
                         ^
          ------------|

where d.jokeid= and

is not correct sql syntax. With the quote the query is changed to this:

select d.pictype, d.title, d.joke, d.hits, d.rating, d.userid, d.type, c.category from jokes d, categories c
where d.jokeid = ''  and c.catid = d.catid

Another option could be to make sure that this query isn't executed if $jokeid is not set, something like

if(!empty($jokeid)){
   $sql = "select d.pictype, d.title, d.joke, d.hits, d.rating, d.userid, d.type, c.category from jokes d, categories c
   where d.jokeid = '$jokeid' and c.catid = d.catid";
   ----
   ----
   More code
   ----
}

Batalf
0
 
LVL 6

Author Comment

by:benwiggy
ID: 13953923
Found the problem thanks to your help! Thanks.
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13953929
No problem:-)

Batalf
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month17 days, 21 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question