Current location: Hot Scripts Forums » Programming Languages » PHP » MySQL Syntax error

MySQL Syntax error

Reply
  #1 (permalink)  
Old 04-18-06, 03:14 AM
gigafare gigafare is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
MySQL Syntax error

Problem: A syntax error occurs when creating a page where the link is not shown in the menu. It's an MySQL syntax error so it should be here somewhere.

Error: Error In Execution
MYSQL Said: DB Error: syntax error

AddPage.php
PHP Code:
<?php
$no_need_to_display
=0;
if( isset(
$_POST["submit"]) )
{
    if( 
is_array($_POST) )
    {
        while( list(
$k$v) = each($_POST) )
        {
            $
$k=$v;
        }
        @
reset($_POST);
    }
    if( empty(
$name)  )
    {
        
$error_messages[]=$smarty->get_config_vars('pagenamemiss');
    }
    if( empty(
$title)  )
    {
        
$error_messages[]=$smarty->get_config_vars('titlemiss');
    }

    if( empty(
$content)  )
    {
        
$error_messages[]=$smarty->get_config_vars('bodytextmiss');
    }

    if( 
count($error_messages) == )
    {
            
$now   time();
            
$query"insert into ".$prefix."_pages (name,title,content,priv,parentid,view) values
            ('$name','$title','$content',$priv,$parentid,$view)"
;
            
$res $db->query($query);
            if (
DB::isError($res) )
            {
                
$error_messages[]="Error In Execution<br>MYSQL Said: ".$res->getMessage() ;
                
$smarty->assign('error_messages'$error_messages);
                
$smarty->assign('width'"50%");
                
$smarty->display("errors_table.tpl");
            }
            else
            {
                
$message_title $error_messages[]=$smarty->get_config_vars('success');
                
$messages[] = $error_messages[]=$smarty->get_config_vars('opsuccess');        
                
$smarty->assign('message_title'$message_title);
                
$smarty->assign('messages'$messages);
                
$smarty->assign('width'"50%");
                
$smarty->display("admin_messages.tpl");
                
$no_need_to_display=1;
            }
    }
    else
    {
        
$smarty->assign('error_messages'$error_messages);
        
$smarty->assign('width'"50%");
        
$smarty->display("errors_table.tpl");
    }
}

if(
$no_need_to_display==0)
{
$query"SELECT * FROM ".$prefix."_pages WHERE parentid = 0";
$pages $db->getAll($query);
$smarty->assign('pages'$pages);            
$smarty->display("addpage.tpl");
}
else
{
$smarty->display("default.tpl");
}
?>

AddPage.tpl (snippet)

Code:
<tr>
<td align="right">
<input type="checkbox" name="view" value="1" {if 1 eq $smarty.request.view|default:$cat.view}checked="checked"{/if} />
</td>
<td align="left">
Link tonen in het menu
</td>
</tr>
SQL

Code:
CREATE TABLE be_pages ( 
ID bigint(20) unsigned NOT NULL auto_increment,
parentid bigint(20) unsigned NOT NULL ,
name varchar(255) NOT NULL ,
title varchar(255) NOT NULL ,
content text NOT NULL ,
views bigint(20) unsigned NOT NULL ,
priv smallint(2) unsigned NOT NULL ,
view tinyint(1) unsigned NOT NULL ,
sortorder int(11) unsigned NOT NULL ,
PRIMARY KEY (ID)
);

Last edited by Christian; 04-18-06 at 06:04 PM. Reason: Please use [PHP][/PHP] when posting PHP code!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-18-06, 06:28 AM
nova912's Avatar
nova912 nova912 is offline
Code Guru
 
Join Date: Sep 2004
Location: Traverse City, MI, USA
Posts: 821
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by gigafare
PHP Code:
$query"insert into ".$prefix."_pages (name,title,content,priv,parentid,view) values
            ('$name','$title','$content',$priv,$parentid,$view)"

should look like this...

PHP Code:
$query"insert into ".$prefix."_pages (name,title,content,priv,parentid,view) values
            ('"
.$name."','".$title."','".$content."','".$priv."','".$parentid.'","'.$view."')"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-18-06, 12:31 PM
gigafare gigafare is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
Different kind of error this time:

• Error In Execution
MYSQL Said: DB Error: value count on row
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-18-06, 12:47 PM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
Can you echo out the problematic query?

Also, is there any way to make your DB class give more verbose errors? These error descriptions aren't very useful...I've never used PEAR DB (I'm assuming that's what you're using?)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-19-06, 02:03 AM
gigafare gigafare is offline
Newbie Coder
 
Join Date: Oct 2005
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
I think this is the problem, if there's no need to display (a checkbox) is selected the link to this page isn't supposed to show in the menu. But see what happens: only SELECT * FROM ...?? Shouldn't this be Insert Into etc...?

if($no_need_to_display==0)
{
$query= "SELECT * FROM ".$prefix."_pages WHERE parentid = 0";
$pages = $db->getAll($query);
$smarty->assign('pages', $pages);
$smarty->display("addpage.tpl");
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


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 phpprobid frankic PHP 6 05-20-06 12:33 AM
MySQL Syntax error when using a variable for table name lppa2004 PHP 4 08-04-05 12:24 AM
MySQL syntax error HairySpider PHP 2 07-12-05 06:43 AM
Can't find error in sql syntax. Dr.Jamescook PHP 7 06-14-05 11:45 AM
You have an error in your SQL syntax. Help! SevEre PHP 7 09-08-04 05:05 AM


All times are GMT -5. The time now is 02:17 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.