Проблем с mysql_fetch_assoc и mysql_num_rows

C++ JAVA
Post Reply
lqbo123
Турист
Турист
Reactions: 0
Posts: 265
Joined: Mon Nov 30, 2009 6:19 pm

Проблем с mysql_fetch_assoc и mysql_num_rows

Post by lqbo123 » Wed May 26, 2010 8:46 pm

Здравейте значи този проблем за пръв път ми се появява ето вижте:

Code: Select all

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/mvp/login.php on line 21

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/mvp/login.php on line 22
Ето и моят код за login файла:

Code: Select all

<?php
include "include/functions.php";
include "include/config.php";
my_hed&#40;"Вход"&#41;;

if&#40;$potrebitel&#41; &#123;
    header&#40;"Location&#58; index.php"&#41;;
&#125; else &#123;
     echo "<form action='login.php' method='post'><table><tbody>
            <tr><td>Потребителско име&#58; </td><td><input type='text' name='username' /></td></tr>
            <tr><td>Парола&#58; </td><td><input type='password' name='pass' /></td></tr>
            <tr><td><input type='hidden' name='log' value='1' /><input type='submit' name='submit' value='Регистрирай се' /></td>
            <td><input type='reset' value='Изчисти' /></td></tr>
        </tbody></table></form>";

     if&#40;$_POST&#91;'log'&#93;==1&#41; &#123;
        $username = addslashes&#40;trim&#40;$_POST&#91;'username'&#93;&#41;&#41;;
        $pass = md5&#40;$_POST&#91;'pass'&#93;&#41;;

        $proverka = "SELECT * FROM users WHERE username = '$username";
        $broi = mysql_num_rows&#40;$proverka&#41;;
        $row = mysql_fetch_assoc&#40;$proverka&#41;;

        if&#40;$broi == 0&#41; &#123;
            echo "Няма такъв потребител!";
        &#125; else &#123;
            if&#40;$pass != $row&#91;'password'&#93;&#41; &#123;
                echo "Невалидна парола!";
            &#125;
        &#125;
        
     &#125;
&#125;

my_fot&#40;&#41;;
?>
Ето и за регистрация ако е необходимо:

Code: Select all

<?php
include "include/functions.php";
include "include/config.php";
my_hed&#40;"Регистрация"&#41;;

if&#40;$potrebitel&#41; &#123;
    header&#40;"Location&#58; index.php"&#41;;
&#125; else &#123;
    echo "<form action='register.php' method='post'><table><tbody>
            <tr><td>Потребителско име&#58; </td><td><input type='text' name='username' /></td></tr>
            <tr><td>Парола&#58; </td><td><input type='password' name='pass' /></td></tr>
            <tr><td>Повтори паролата&#58; </td><td><input type='password' name='pass2'/></td></tr>
            <tr><td>Email&#58; </td><td><input type='text' name='email' /></td></tr>
            <tr><td><input type='hidden' name='sub' value='1' /><input type='submit' name='submit' value='Регистрирай се' /></td>
            <td><input type='reset' value='Изчисти' /></td></tr>
        </tbody></table></form>";

        if&#40;$_POST&#91;'sub'&#93;== 1&#41; &#123;
            $username = addslashes&#40;trim&#40;$_POST&#91;'username'&#93;&#41;&#41;;
            $pass = md5&#40;$_POST&#91;'pass'&#93;&#41;;
            $pass2 = md5&#40;$_POST&#91;'pass2'&#93;&#41;;
            $email = addslashes&#40;trim&#40;$_POST&#91;'email'&#93;&#41;&#41;;
            $date = date&#40;'d-m-Y'&#41;;

            $act = mysql_query&#40;"SELECT * FROM users WHERE username = '$username'"&#41;;
            $broi = mysql_num_rows&#40;$act&#41;;

            if&#40;$username == NULL && $pass == NULL || $pass2 == NULL && $email == NULL&#41; &#123;
                echo "Моля попълнете всички полета!";
            &#125;
                if&#40;$broi >= 1&#41; &#123;
                    echo "Има вече такъв потребител!";
                &#125; else &#123;
                    if&#40;$pass != $pass2&#41; &#123;
                        echo "Паролите несъвпадата!";
                    &#125; else &#123;
                        if&#40;!ereg&#40;"^&#91;-A-Za-z0-9_&#93;+&#91;-A-Za-z0-9_.&#93;*&#91;@&#93;&#123;1&#125;&#91;-A-Za-z0-9_&#93;+&#91;-A-Za-z0-9_.&#93;*&#91;.&#93;&#123;1&#125;&#91;A-Za-z&#93;&#123;2,5&#125;$", $email&#41;&#41; &#123;
                            echo "Невалиден email адрес!";
                        &#125; else &#123;
                            $insert_user = mysql_query&#40;"INSERT INTO users &#40;username, password, email, date_added&#41; VALUES &#40;'$username',
                                    '$pass','$email','$date'&#41;"&#41;;
                            echo "Вие се регистрирахте успешно <a href='index.php'> Начало</a>";
                            
                        &#125;
                    &#125;
            &#125;
            
        &#125;
&#125;


my_fot&#40;&#41;;
?>
Идей ?

User avatar
Dizasterr
Много Редовен
Много Редовен
Reactions: 0
Posts: 1919
Joined: Thu Nov 05, 2009 9:49 pm
Answers: 52
Contact:

Post by Dizasterr » Wed May 26, 2010 8:50 pm

Трябва на проверката да му сложиш: mysql_query.

php5
Нов
Нов
Reactions: 0
Posts: 14
Joined: Sun May 09, 2010 8:23 am

Post by php5 » Wed May 26, 2010 8:54 pm

А да забравил съм го мерси

Post Reply