TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   hi , a project problem !!!!!!!! (http://www.talkphp.com/absolute-beginners/2225-hi-project-problem.html)

webtuto 02-11-2008 12:27 PM

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 ?

Wildhoney 02-11-2008 12:33 PM

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

Missing periods for concatenation.

webtuto 02-11-2008 12:55 PM

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

Gibou 02-11-2008 03:00 PM

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...)

webtuto 02-11-2008 06:44 PM

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

Gibou 02-11-2008 07:09 PM

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.

Andrial12 02-11-2008 07:11 PM

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.

ReSpawN 02-11-2008 07:22 PM

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

webtuto 02-12-2008 01:10 PM

thanks it works


All times are GMT. The time now is 04:22 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0