Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > Database & Database Programming

Database & Database Programming MySQL, Oracle, SQL, PL/SQL, ABAP, Smart Forms, and other databases and languages. A database is an organized body of related information used in many websites (including CC).

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-2008, 08:33 PM
phpforfun's Avatar   
phpforfun phpforfun is online now
Programming God
 
Join Date: Feb 2008
Posts: 514
Last Blog:
ubuntu... do not upgra...
Rep Power: 5
phpforfun will become famous soon enough
Default My SQL Noob at work

So I just started MySQL and SQL today, using SQLyog. Pretty cool stuff. Using a tutorial I found online, however im getting an error.. Here is the code.
PHP Code:
<?
    $host        
=    'localhost';
    
$user        =    'root';
    
$pass        =    'password';
    
$database    =    'roscripts';
    
$connect = @mysql_connect $host$user$pass ) ;

    
$sql "SELECT * FROM `articles` WHERE `ID` = " mysql_real_escape_string $_GET['ID'] );

    
mysql_select_db $database$connect );
    if ( @
mysql_query $sql ) )
    {
        
$query mysql_query $sql );
        
$row mysql_fetch_assoc $query );

        echo 
$row['ID'] . '<br />' $row['article_title'] . '<br />' $row['article_content'];
    }
    else {
        die ( 
mysql_error () );
    }
?>
When I put that in the page, I get this error..

Quote:
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
Whats the right suntax? I have the latest version of everything, I am using Apache2triad.

Thanks guys!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 02-22-2008, 12:26 AM
phpforfun's Avatar   
phpforfun phpforfun is online now
Programming God
 
Join Date: Feb 2008
Posts: 514
Last Blog:
ubuntu... do not upgra...
Rep Power: 5
phpforfun will become famous soon enough
Default

Anyone wanna take a shot?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-22-2008, 09:31 AM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,346
Last Blog:
PHP Function Overloadi...
Rep Power: 50
John is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of light
Send a message via AIM to John
Default

PHP Code:
$sql "SELECT * FROM `articles` WHERE `ID` = '" mysql_real_escape_string $_GET['ID'] ) . "'"
If that doesn't work, remove the error suppression operator [ @ ]
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-22-2008, 05:36 PM
Jordan's Avatar   
Jordan Jordan is online now
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 25
Posts: 4,524
Last Blog:
PHP: Variable variable...
Rep Power: 50
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

With MySQL I generally leave out most of the ` symbols:

PHP Code:
$sql "SELECT * FROM articles WHERE ID= '" mysql_real_escape_string $_GET['ID'] ) . "'"
If that doesn't work do

PHP Code:
echo $sql
right after that line. Then copy/paste that info into MySQL directly. You will generally get a more descriptive error (you can use PHPMyAdmin or MySQL from the console for this).
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-22-2008, 07:00 PM
phpforfun's Avatar   
phpforfun phpforfun is online now
Programming God
 
Join Date: Feb 2008
Posts: 514
Last Blog:
ubuntu... do not upgra...
Rep Power: 5
phpforfun will become famous soon enough
Default

Now it doesnt show anything when I do any of the above :-\
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 02-22-2008, 07:12 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,346
Last Blog:
PHP Function Overloadi...
Rep Power: 50
John is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of light
Send a message via AIM to John
Default

I find the back ticks [ ` ] to be a good practice. Prior to using back ticks I had a problem with one of my SQL queries, which took me several hours to debug. The problem ended up being that one of the column names in my query was a reserved word, using the back ticks solved the problem. So thats why I find it a good practice...
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-23-2008, 10:47 AM
phpforfun's Avatar   
phpforfun phpforfun is online now
Programming God
 
Join Date: Feb 2008
Posts: 514
Last Blog:
ubuntu... do not upgra...
Rep Power: 5
phpforfun will become famous soon enough
Default

How does a back tick solve it? Is it a substitute for something?

Go to this:

http://ffe.no-ip.org/mysql/

Selecting.php is the one were looking at. It now wont show.. anything
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-23-2008, 05:49 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 19
Posts: 2,346
Last Blog:
PHP Function Overloadi...
Rep Power: 50
John is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of lightJohn is a glorious beacon of light
Send a message via AIM to John
Default

The back tick explicitly says "whats between me is a column name."


Have you removed the @ symbol yet?...
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-23-2008, 08:11 PM
phpforfun's Avatar   
phpforfun phpforfun is online now
Programming God
 
Join Date: Feb 2008
Posts: 514
Last Blog:
ubuntu... do not upgra...
Rep Power: 5
phpforfun will become famous soon enough
Default

Quote:
Originally Posted by John View Post
The back tick explicitly says "whats between me is a column name."


Have you removed the @ symbol yet?...
Yes sir.

PHP Code:
<?PHP
    $host        
=    'localhost';
    
$user        =    'root';
    
$pass        =    'private1';
    
$database    =    'roscripts';
    
$connect = @mysql_connect $host$user$pass ) ;

    
$sql "SELECT * FROM `articles` WHERE `ID` = '" mysql_real_escape_string $_GET['ID'] ) . "'";    

    
mysql_select_db $database$connect );
    if ( @
mysql_query $sql ) )
    {
        
$query mysql_query $sql );
        
$row mysql_fetch_assoc $query );

        echo 
$row['ID'] . '<br />' $row['article_title'] . '<br />' $row['article_content'];
    }
    else {
        die ( 
mysql_error () );
    }
?>
Thats the code now, which will output nothing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-24-2008, 10:31 PM
phpforfun's Avatar   
phpforfun phpforfun is online now
Programming God
 
Join Date: Feb 2008
Posts: 514
Last Blog:
ubuntu... do not upgra...
Rep Power: 5
phpforfun will become famous soon enough
Default

So then, what code do you guys use to echo whats in a db?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Tutorials Jordan Database & Database Programming 7 02-23-2008 03:20 AM
Make a script vulnerable to SQL injection? shibbythestoner PHP Forum 7 12-15-2007 08:56 PM
Best program for SQL database manipulation Rhadamanthys Database & Database Programming 3 07-02-2007 02:32 PM
Executing SQL Server 2k DTS Package via Visual Basic Joemama Visual Basic Programming 0 04-09-2007 06:21 PM
Oracle has more Flaws than MS SQL? Jordan Database & Database Programming 9 12-05-2006 09:39 AM


All times are GMT -5. The time now is 02:21 PM.

Contest Stats

John ........ 87.50000
dargueta ........ 75.00000
Xav ........ 50.00000
MeTh0Dz ........ 20.00000
gaylo565 ........ 18.00000
Johnnyboy ........ 3.00000

Contest Rules

Ads