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


MySQL syntax error

Reply
  #1 (permalink)  
Old 07-11-05, 04:57 PM
HairySpider's Avatar
HairySpider HairySpider is offline
Newbie Coder
 
Join Date: Jan 2005
Location: Herts, UK
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Question MySQL syntax error

Hi, I have made a simple script that gets some data from another website (phpbbhacks.com) and inserts it into my own database. Don't worry, I am aloud to do this

My Script:
PHP Code:

<?php

// This is version 2

if (isset($_GET['phpbbhacks_id']))
{
    
$phpbbhacks_id $_GET['phpbbhacks_id'];
    
$phpbbhacks_url 'http://www.phpbbhacks.com/download/' $phpbbhacks_id;
} else {
echo 
"You did not set the starting phpbbhacks_id!";
exit;    
};

function 
GetNextMod($phpbbhacks_id) {
    
$phpbbhacks_old_id $phpbbhacks_id;
    
$phpbbhacks_id $phpbbhacks_id 1;
    echo 
'<h1>The hack (ID:' $phpbbhacks_old_id 'has been taken from phpbbhacks and inserted correctly into the scripthackers database, you will be re-directed and the next one shall start in 3 seconds...</h1>';
    
header"refresh: 3; url=http://scripthackers.com/Get_Mods2/phpbbhacks.php?phpbbhacks_id=$phpbbhacks_id);
    exit;
};


if (
$phpbbhacks_id <= 6000) {
   
//
   // Get the information and put it into short tags: $string = $datastring[5];
   //
   
$page_data file_get_contents($phpbbhacks_url);
   
   
// Download Title:
    
$string eregi('<h2>(.*)</h2>'$page_data$data);
    
$title $data[1];
    
    
$title addslashes($title);
    
    
// Website URL:
    
if (eregi("View Demo"$page_data)) {
        
// There is a demo link
       
$string preg_match_all('/href="(.*)">View Demo/'$page_data$data);
  for (
$i=0$icount($data[0]); $i++) {
  
$url $data[1][$i];
       };

    } else {
        
// There is no demo link
$url "http://www.phpbb.com";
    }
    
    
// Download URL:
    
$string eregi('title="(.*)">Download</a>'$page_data$data);
    
$dl_url $data[1];
        
// Get filename
        
$filename_parts explode("/"$dl_url);
        
$filename $filename_parts[4];
        
/* e.g for this url the array would be: [url]http://www.phpbbhacks.com/downloads/2925.zip[/url]
                [0] => http:
                [1] =>
                [2] => [url]www.phpbbhacks.com[/url]
                [3] => downloads
                [4] => 2925.zip )
        */
    
    // Version & other info:
    
$string eregi('<h3>Download Information</h3>(.*)<div class="smallnavlinks"><a href="/forums/">'$page_data$data);
    
$version_info $data[1];
    
    
$parts explode('<div class="smalltext">'$version_info);
// print_r($parts);
    
$version $parts[2];
    
$file_size $parts[4];
    
$phpbb_version $parts[6];
    
$author $parts[8];
        
    
$parts_of_author explode("="$author);
    
    
$author explode('">'$parts_of_author[2]);
    
    
$author $author[1];

    
// Category:
    
$string eregi('<a href="category/(.*)">'$page_data$data);
    
$category_id $data[1];
    
$category_parts explode('"'$category_id);
    
$category_id $category_parts[0];
    
    if (
$category_id == 1){
        
$category 283;
    } elseif (
$category_id == 2){
        
$category 284;
    } elseif (
$category_id == 17){
        
$category 285;
    } elseif (
$category_id == 18){
        
$category 286;
    } elseif (
$category_id == 39){
        
$category 287;
    } elseif (
$category_id == 41){
        
$category 288;
    } elseif (
$category_id == 38){
        
$category 289;
    } elseif (
$category_id == 5){
        
$category 290;
    } elseif (
$category_id == 3){
        
$category 291;
    } elseif (
$category_id == 15){
        
$category 292;
    } elseif (
$category_id == 8){
        
$category 293;
    } elseif (
$category_id == 11){
        
$category 294;
    } elseif (
$category_id == 23){
        
$category 295;
    } elseif (
$category_id == 37){
        
$category 296;
    } elseif (
$category_id == 35){
        
$category 297;
    } elseif (
$category_id == 28){
        
$category 298;
    } elseif (
$category_id == 34){
        
$category 299;
    } elseif (
$category_id == 7){
        
$category 300;
    } elseif (
$category_id == 32){
        
$category 301;
    } elseif (
$category_id == 36){
        
$category 302;
    } elseif (
$category_id == 33){
        
$category 303;
    } elseif (
$category_id == 10){
        
$category 304;
    } elseif (
$category_id == 31){
        
$category 305;
    } elseif (
$category_id == 24){
        
$category 306;
    } elseif (
$category_id == 4){
        
$category 307;
    } elseif (
$category_id == 40){
        
$category 280;
    } elseif (
$category_id == 30){
        
$category 319;
    } elseif (
$category_id == 42){
        
$category 321;
    } elseif (
$category_id == 19){
        
$category 322;
    } elseif (
$category_id == 29){
        
$category 323;
    } elseif (
$category_id == 21){
        
$category 324;
    } elseif (
$category_id == 26){
        
$category 325;
    } elseif (
$category_id == 20){
        
$category 326;
    } elseif (
$category_id == 25){
        
$category 327;
    } elseif (
$category_id == 27){
        
$category 328;
    } else {
        
//
        // Do the category not found code :-)
        //
        
GetNextMod($phpbbhacks_id);
    };
    
    
    
// Description: 
    
$string eregi('<div class="bodytext"> (.*)<TD vAlign=top width=150>'$page_data$data);
    
$desc_raw $data[1];
    
    
$desc_code strip_tags($desc_raw'<br><strong><p><i><u><font><img><a>');
    
    
$desc addslashes($desc_code);
    
    
//
    // Make a MySQL Connection
    //
    
mysql_connect("localhost""**USER**""**PASS**") or die(mysql_error());
    
mysql_select_db("**DATABASE**") or die(mysql_error());
   
   
//
   // Insert download into database
   //
    
mysql_query("INSERT INTO cms_downloads_downloads (cid, active, access, title, screen, desc_short, date, updated, name, submitter, filesize, version, homepage, compat, pick, licence) VALUES ($category, '1', '0', $title, '0', $desc, '1120011242', '0', $author, '5', $file_size$version$url$phpbb_version, '0', 'GNU GPL') ")
    or die(
mysql_error()); 
   
    
// Get the scripthackers ID
    
$gettingshid mysql_query("SELECT lid FROM cms_downloads_downloads WHERE title=$title && cid=$category")
    or die(
mysql_error()); 
    
    
$gettingshidrow mysql_fetch_array($gettingshid);
    
$scripthackers_id $gettingshidrow['lid'];
    
    
// Insert the mirror part into the database :-)
    
mysql_query("INSERT INTO cms_downloads_mirrors (did, url, filename, filesize, uploaded) VALUES ($scripthackers_id$dl_url$filename$file_size, '0') ")
    or die(
mysql_error()); 
    
    
//
    // Insert download version and ID into the update DB
    //
    
mysql_query("INSERT INTO othersites_phpbbhacks (scripthackers_version, phpbbhacks_id, scripthackers_id) VALUES ($version$phpbbhacks_id$scripthackers_id) ")
    or die(
mysql_error());
    
   
//
   // Start again!
   //
   
GetNextMod($phpbbhacks_id);

} else{
    echo 
"All phpbbhacks resources with IDs below 6000 have not been added to the database";
    exit;
};

?>
When I execute it on: http://phpbbhacks.com/download/1, I get the followin 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 'Topic, '0', This hack changes the topic of your posts from \"Vi.

The part which I think is giving it problems is:
This hack changes the topic of your posts from "View Topic" to the actual topic of the thread. This is not only better looking, but is better for search engines.
As it has "s in it, I do use
PHP Code:

$desc addslashes($desc_code); 

Though, so I would have thought this would have sorted it. As it is not sent through get/post/cookie then magic quotes thingy is not the problem (I don't think).

I would be very greatful if someone can help me

Many Thanks, Luke
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 07-12-05, 07:38 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
i would check the columns, make sure the values your passing are the correct type, as in dont be passing text to a int column, after that, try run those queries in a mysql shell ... you could take out the listing of the columns, i.e., INSERT INTO table ( column, column2) VALUES ( 'value' , 'value' ) ., take out the ( column, column2) to make INSERT INTO table VALUES ('value', 'value' ) ,
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-12-05, 07:43 AM
HairySpider's Avatar
HairySpider HairySpider is offline
Newbie Coder
 
Join Date: Jan 2005
Location: Herts, UK
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
OK, thanks very much... will try that when I can.

Luke
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare 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
Can't find error in sql syntax. Dr.Jamescook PHP 7 06-14-05 12:45 PM
MySQL Error: Warning: mysql_fetch_array(): supplied argument not valid MySQL zibykid PHP 10 03-30-05 09:37 AM
You have an error in your SQL syntax. Help! SevEre PHP 7 09-08-04 06:05 AM
wanting advice / custom mysql error page tylerc PHP 2 05-07-04 01:41 PM
php or mysql parse error ( ? ) jrave PHP 8 03-09-04 02:14 PM


All times are GMT -5. The time now is 10:02 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.