Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > MySQL
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2006, 09:15 AM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default mysql_num_rows() => Giving Error?

Well when i run this file called edit.php I get following errors:(

mysql_num_rows(): supplied argument is not a valid MySQL result resource

heres the code for the file

--------------code begins--------------

<?php
require "config.php";

function login() {
    echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><form action=\"edit.php\" method=\"POST\">
    <tr><td>Username: </td><td><input type=\"text\" name=\"l_user\" class=box></td></tr><tr>
    <td>Password: </td><td><input type=\"password\" name=\"l_pass\" class=box></td></tr><tr>
    <tr><td></td><td><input type=\"Submit\" value=\"Log In!\" class=box></td></tr></form></table>";
}

function head() {
    echo "<html>\n<head>\n<title>Submissionz.com - Link Exchange</title></head>
<style type=\"text/css\">
A:link {color: #FFffff; text-decoration:none; font-size:8pt; font-family:Verdana}
A:visited {color: #FFffff; text-decoration:none; font-size:8pt; font-family:Verdana}
A:hover {color: #ff0000; text-decoration:underline; font-size:8pt; font-family:Verdana}
.text {color: #ff0000; text-decoration:none; font-size:8pt; font-family:Verdana}
.box {color: #ffffff; border: 1px solid #ff0000; background-color: #991717; font-family:Verdana; font-size:8pt}
table {color: #ffffff; text-decoration:none; font-size:8pt; font-family:Verdana}
</style><body bgcolor=#000000>";
}

function foot() {
    echo "\n</body></html>";
}


function form($err, $val) {
    global $l_user, $l_pass;
    echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">
    <form name=\"le\" action=\"edit.php\" method=\"POST\">
    <tr><td><b>Username: </b></td><td>$l_user</td></tr>
    <tr><td><b>Password: </b></td><td><input class=box type=\"text\" name=\"le[pass]\" max=\"30\" size=\"30\" maxlength=\"15\" value=\"$val[pass]\"> $err[pass]</td></tr>
    <tr><td><b>Email: </b></td><td><input class=box type=\"text\" name=\"le[email]\" max=\"30\" size=\"30\" value=\"$val[email]\" maxlength=\"80\"> $err[email]</td></tr>
    <tr><td><b>Site Name: </b></td><td><input class=box type=\"text\" name=\"le[name]\" max=\"30\" size=\"30\" value=\"$val[name]\" maxlength=\"13\"> $err[name]</td></tr>
    <tr><td><b>Site Url: </b></td><td><input class=box type=\"text\" name=\"le[url]\" max=\"30\" size=\"30\" value=\"$val[url]\" maxlength=\"80\"> $err[url]</td></tr>
    <tr><td></td><td><input class=box type=\"Submit\" value=\"Update!\"></td></tr>
    <input type=\"Hidden\" name=\"l_user\" value=\"".$l_user."\">
    <input type=\"Hidden\" name=\"l_pass\" value=\"".$l_pass."\"></form></table>";
}

if (!$l_pass || !$l_user) {
    head();
    login();
    foot();
} else {
    $err = array();
    $get = mysql_query("SELECT * FROM linker WHERE id = '$l_user' && passord = '$l_pass'");
    if (!mysql_num_rows($get)) {
        head();
        echo "<big><b>Wrong Username or Password!</b></big><br>";
        login();
        foot();
    } else {
        $val = mysql_fetch_array($get);
        $val[pass] = $val[passord];
        $val[name] = $val[navn];
        if ($le) {
            if (!$le[pass] || !$le[email] || !$le[name] || !$le[url]) {
                if (!$le[pass])
                    $err[pass] = "you must enter a password!";
                if (!$le[email])
                    $err[email] = "you must enter your email!";
                if (!$le[name])
                    $err[name] = "you must enter your sites title!";
                if (!$le[url])
                    $err[url] = "what is your sites url?";
                head();
                form ($err, $val);
                foot();
            } else {
                mysql_query("UPDATE linker SET passord='$le[pass]',navn='$le[name]',url='$le[url]',email='$le[email]' WHERE id = '$l_user'");
                head();
                echo "<big><b>Updated!</b></big><br>";
                $l_pass = $le[pass];
                form($err, $le);
                foot();
            }
        } else {
            head();
            form($err, $val);
            foot();
        }
    }
}
?>

--------------code ends--------------

Ps: A small note. I am very new to php but i know few things like how do i edit a code so that i don't recieve an error message
like putting '@' sign for variables and all that. Also this is not my script. I got it from the net somewhere.

i think the line mysql_num_rows($get) is creating errors. please help me to sort out this error. I don't know any technical things bout php but a thing or two and similar is the case with mysql. So please please make sure that when u answer my query, u answer in a lame manner.

Thanx a buch in advance
Hoping to get replies
Cybot:)

 
Old July 8th, 2006, 01:43 PM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I hope this forum is not dead! 7 reads and still no reply

 
Old July 13th, 2006, 03:10 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It seems like your problem isn't with mysql_num_rows, but instead with mysql_query. If mysql_query fails, the PHP documentation actually says you receive a warning, not an error! Therefore the value you receive in $get is not a resource (aka a result set), but the boolean FALSE. When you pass FALSE to mysql_num_rows, it obviously errors out because it's expecting a resource.

So, why is mysql_query failing then? Does config.php connect to your database? If not, how does the database resource link get set up?

And at a basic robustness level, you should be checking the response from mysql_query to make sure it's not false before calling mysql_num_rows() against it.

Jon Emerson
http://www.jonemerson.net/
 
Old July 15th, 2006, 05:12 AM
Registered User
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i just forgot. i had not created the database properly. now its sorted out. i missed some tables initially now its done.

 
Old September 12th, 2006, 12:07 PM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Cybot can you please contact me? I have an important question.

[email protected] <-MSN or email.

Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Error giving when i create the Subdomain Surjit Classic ASP Professional 0 April 18th, 2008 06:17 AM
This piece of code is giving an error sourik C# 2 July 15th, 2006 09:18 AM
This piece of code is giving an error sourik Classic ASP Databases 1 July 14th, 2006 09:10 PM
SHDOCVW giving error on compiled run WarriorKing Pro VB 6 3 December 20th, 2004 12:10 PM
excel export giving memory error msrnivas .NET Web Services 0 September 6th, 2004 12:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.