Current location: Hot Scripts Forums » Programming Languages » PHP » getting: You have an error in your SQL syntax


getting: You have an error in your SQL syntax

Reply
  #1 (permalink)  
Old 10-11-09, 05:20 PM
dyablo687 dyablo687 is offline
New Member
 
Join Date: Oct 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
getting: You have an error in your SQL syntax

I'v developing a small web app and i've started to get the following message:

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 '' at line 1

This had not happend before, it just started happening when i tried to convert my urls from dynamic to friendly urls, using apache mod rewrite.

At first i was getting a mysql_fetch_assoc():sumysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in line 59 and 8

PHP Code:

$sql "SELECT * FROM db WHERE blogID={$_GET['blogID']}";

$run mysql_query($sql);
while(
$fetch mysql_fetch_assoc($run))
{
$blogID $fetch['blogID'];    
$blogTitle $fetch['title'];
$date $fetch['date'];
$post $fetch['post'];
$category $fetch['category'];
$user $fetch['user'];
$tags $fetch['tags']; 
PHP Code:

$sql "SELECT * FROM dbWHERE blogID={$_GET['blogID']}";

$run mysql_query($sql);
while(
$fetch mysql_fetch_assoc($run)){
       
$blogID $fetch['blogID'];    
       
$name $fetch['name'];
       
$email $fetch['email'];
       
$comment $fetch['comment'];
    echo
"
        <h3 class='commentName'>
$name</h3>
        <h3 class='commentDate'>
$date</h3>
        <p>
$comment</p>
                "
;
            } 
I then added this:

PHP Code:

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

and since then i've been getting

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 '' at line 1

Not sure what else to try
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 10-11-09, 07:04 PM
dyablo687 dyablo687 is offline
New Member
 
Join Date: Oct 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
update

I'm not sure if thats the problem anymore....like i said this started happening after i tried converting the urls to friendly urls. But when i access the page using the dynamic url it goes in fine, the problem is when i try to acccess it using the friendly url

here is the code that i have to get the links to change:

PHP Code:

$sql "SELECT * FROM db ORDER BY blogID DESC";

    
$run mysql_query($sql) or die(mysql_error());
        
$num mysql_num_rows($run);
        while(
$fetch mysql_fetch_assoc($run)) {
             
$blogID $fetch ['blogID'];
                    
$blogTitle $fetch['title'];
                    
$date $fetch['date'];
                    
$teaser $fetch['teaser'];
                    
$category $fetch['category'];
                    
$user $fetch['user'];
                    
$tags $fetch['tags'];
                    
$blog_title_url gen_seo_friendly_titles($blogTitle);
                    echo
"
                        <div class='postRoll'>
                            <h1><a href='http://www.domainname.com/blog/
$blog_title_url.html'>$blogTitle</a></h1>
                            <h2>
$date | |User:$user | Category:$category</h2>
                            
$teaser
                            <p><a href='#'>Post Comment</a>&nbsp;&nbsp;&nbsp;Number Of Comments</p>
                        </div>
                        "
;
                }
                
                function 
gen_seo_friendly_titles($title) {
                
$replace_what = array('  '' - '' ',    ', '',');
                
$replace_with = array(' ''-''-'',''-');
                
                
$title strtolower($title);
                
$title str_replace($replace_what$replace_with$title);
                return 
$title;
            } 
Plus have this following code in a .htaccess file on my root folder
Code:
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule ^blog/([^-]+)-([^&]+)\.html$ /blogpost.php?blogId=$blogID

</IfModule>
Both of those sections of code are not on my blogpost.php which is the one that i've having problems with, they are on another file one level up from were the blogpost.php file is in.

Finally, when i look into my error log this is what it tells me thats wrong:

PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result on line 8 and 59 which is where the while($fetech = mysql_fetch_assc($run)) is at

Last edited by dyablo687; 10-11-09 at 07:11 PM. Reason: added some new content
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
errors, mysql, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Error Nikas Database 4 05-15-08 11:48 AM
sql syntax error again zitwep Database 5 07-14-06 04:33 PM
Can't find error in sql syntax. Dr.Jamescook PHP 7 06-14-05 12:45 PM
You have an error in your SQL syntax. Help! SevEre PHP 7 09-08-04 06:05 AM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 12:34 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.