TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-11-2008, 12:27 PM   #1 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default hi , a project problem !!!!!!!!

hi im working on a project and when i write this code

PHP Code:
 $res mysql_query('SELECT * FROM video where group='$_GET[cat]' ORDER BY id DESC LIMIT ' $premierMessageAafficher ', ' $nombreDeMessagesParPage); 
it gives me this error

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\pal\listvid.php on line 43

whats wrong ?
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 02-11-2008, 12:33 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

php Code:
$res = mysql_query('SELECT * FROM video where group=' . $_GET['cat'] . ' ORDER BY id DESC LIMIT ' . $premierMessageAafficher . ', ' . $nombreDeMessagesParPage);

Missing periods for concatenation.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-11-2008, 12:55 PM   #3 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

but it still give this error in this code

PHP Code:
 $res mysql_query("SELECT * FROM `video` where group='"$_GET[cat] ."' ORDER BY `id` DESC LIMIT "$premierMessageAafficher .", "$nombreDeMessagesParPage);
while(
$row=mysql_fetch_array($res)){

//MORE CODES HERE 

it give this error

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\pal\listvid.php on line 44
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 02-11-2008, 03:00 PM   #4 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

Tiens, un français Désolé, pour que tout le monde comprenne, je vais écrire en anglais ;)

So,

First, use the "or die" postfix statement at the end of your SQL query. It'll give you more details on your error.

PHP Code:
$res mysql_query("SELECT * FROM `video` where group='"$_GET[cat] ."' ORDER BY `id` DESC LIMIT "$premierMessageAafficher .", "$nombreDeMessagesParPage)or die(mysql_error());

Then, verify that your $_GET["cat"] is well formated (alpha, alphanum, etc...)
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Old 02-11-2008, 06:44 PM   #5 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

wé j px parler francais lol
well it gives this problem

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\pal\listvid.php on line 44
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 02-11-2008, 07:09 PM   #6 (permalink)
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

pfff, I haven't seen it before -_-

You have forgotten the quotes before "cat".

Try with that:

PHP Code:
$res mysql_query("SELECT * FROM `video` where group='"$_GET["cat"] ."' ORDER BY `id` DESC LIMIT "$premierMessageAafficher .", "$nombreDeMessagesParPage)or die(mysql_error()); 
Without quotes, the php interpretor looks for the global variable cat. This one doesn't exists so, error.

If there are still errors, do this:

Verify that $_GET["cat"] is well formated (alphanumeric). Idem for $premierMessageAafficher and $nombreDeMessagesParPage. Both must be numerics without coma.
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote
Old 02-11-2008, 07:11 PM   #7 (permalink)
The Wanderer
 
Join Date: Feb 2008
Location: Blackpool, England
Posts: 16
Thanks: 2
Andrial12 is on a distinguished road
Default

Group is a MySQL Keyword, you need to put it into quotes IE.

Code:
$res = mysql_query("
	SELECT *
	FROM `video`
	WHERE `group` = '" . $_GET[cat] . "'
	ORDER BY `id` DESC
	LIMIT ". $premierMessageAafficher .", ". $nombreDeMessagesParPage
) or die(mysql_error());
OR

Code:
$res = mysql_query("
	SELECT *
	FROM video v
	WHERE v.group = '" . $_GET[cat] . "'
	ORDER BY v.id DESC
	LIMIT ". $premierMessageAafficher .", ". $nombreDeMessagesParPage
) or die(mysql_error());

In future you'd probably be best entering your query into phpMyAdmin if available, this will give a more detailed response.
Andrial12 is offline  
Reply With Quote
The Following User Says Thank You to Andrial12 For This Useful Post:
webtuto (02-12-2008)
Old 02-11-2008, 07:22 PM   #8 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

PHP Code:
<?php

// First, check wether CAT has been defined.
if ( !empty ( $_GET['cat'] ) ) {

    
// Second, check if both vars are numeric. If not, it won't work either way.
    
if ( ( is_numeric($premierMessageAafficher) ) && ( is_numeric($nombreDeMessagesParPage) ) ) {
        
        
// If all just checks out, you can engage the querie and do with it as you please.
        
$resQuery mysql_query('    SELECT * FROM `video` 
                                    WHERE `group` = "' 
$_GET['cat'] . '" 
                                    ORDER BY `id` DESC 
                                    LIMIT "' 
$premierMessageAafficher '", "' $nombreDeMessagesParPage "'"
                                    or die (
'MySQL returned an error. \'<i>' .mysql_error(). '\'</i>.'); 
    } else {
    
        echo 
'I am sorry. One or both of the values are not numeric.';
        
    }  
# End Numeric Checks
    
} else {

    echo 
'You should really SET the GET variable called "cat" before you init the script.';
    
# End Cat-Check

// Good luck darklord of the sith.

?>
If you type EVERY mySQL table keyword with the backquote (`word`), you should do that with everyone. Also you must be careful to not name every word the same or use keywords that mySQL uses itself. Words like "group" are predefined mySQL keywords used to perform actions on the query, inside it. (same as NOW() and stuff).

Also make a NOTE in your PHP diary if you have one, to finish up quotes before you type a var between them. Zend Studio or phpDesigner2008 will also auto-correct or display the errors for you. (no clue on other programs tho)

IF you are using DreamWeaver, I should suggest to ONLY use it for HTML and CSS scripting. Use a PHP editor for all the other work. My vote goes out to phpDesigner and Zend, as I initially said.

Good luck and please DO read the comments. I haven't tried it but it is my most common way (without using sprinf()) so it should work.

Have a good one.

Mark
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
The Following User Says Thank You to ReSpawN For This Useful Post:
webtuto (02-12-2008)
Old 02-12-2008, 01:10 PM   #9 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

thanks it works
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
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

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


All times are GMT. The time now is 02:45 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design