Forum Moderators: coopster

Message Too Old, No Replies

Warning: mysql num rows():

if (mysql_num_rows($r)) {

         

exposo

6:04 pm on Apr 5, 2007 (gmt 0)

10+ Year Member



Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/domain/public_html/signup.php on line 159

source code:

signup.php
errors on 158,172,179 rows/mentioned after

$string = $username;
// username check
if (Validate_String($string, $return_invalid_chars)!= "true") {
echo "<div class=error>You username contains invalid characters. You can use only alphanumeric lowercase characters(a-z 0-9).</div>";
signup_step1();
return(14);
}
// username check 2
$r=mysql_query("select * from blogusers where username='".mysql_escape_string($username)."'",$link);
158= if (mysql_num_rows($r)) {
echo "<div class=error>Such user has already registered</div>";
signup_step1();
return(15);
}
// email check
if (ValidateEmail($email)!= "true") {
echo "<div class=error>It seems that your email is not valid, please check.</div>";
signup_step1();
return(16);
}
// check email to avoid abuse
$r=mysql_query("select * from blogusers where email='".mysql_escape_string($email)."'",$link);
172= if (mysql_num_rows($r)>3) { // edit here the number of blog allowed for each email address, and edit the text below, too.
echo "<div class=error>This email is already in use 3 times.</div>";
signup_step1();
return(17);
}
// check ip to avoid abuse
$r=mysql_query("select * from blogusers where ip like '".mysql_escape_string($_SERVER['REMOTE_ADDR'])."'",$link);
179= if (mysql_num_rows($r)>3) { // edit here the number of blog allowed for each ip address, and edit the text below, too.
echo "<div class=error>There is a limit of 3 blog per each user in this community.</div>";
signup_step1();
return(18);

Help me, plz

grandpa

6:15 pm on Apr 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The error is telling you that nothing is returned from your query. I'm not at a place where I can test a query, but I would be inclined to try this variation.

$r=mysql_query("select * from blogusers where username='mysql_escape_string($username)'",$link);

If that doesn't work, what you'll need to do is to ensure the query is valid, thus returning a result.

eelixduppy

9:46 pm on Apr 5, 2007 (gmt 0)



You might want to add error handling to your query to see what's going on there:

$query = "select * from blogusers where username='".mysql_real_escape_string($username)."'";
$r = mysql_query($query ,$link) or [url=http://www.php.net/die]die[/url]([url=http://www.php.net/mysql-error]mysql_error[/url]());

This will give you some sort of heads-up as to what is happening with MySQL and why your query is failing.

grandpa

11:19 pm on Apr 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



OK, I've tested this and it worked for me..

$query=sprintf("select * from blogusers where username='%s'" ,mysql_real_escape_string($username));
$result = mysql_query($query, $link);
$r = mysql_num_rows($result);

exposo

9:59 am on Apr 6, 2007 (gmt 0)

10+ Year Member



eelixduppy, I tried that variant previously, it says, no database, but it's ok with it.

grandpa, thank you for helping me, but which part of code should I change, for the code you wrote?

thanks

grandpa

10:28 am on Apr 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might try this.

$query=sprintf("select * from blogusers where username='%s'" ,mysql_real_escape_string($username));
$result = mysql_query($query, $link);
$r = mysql_num_rows($result);
if ($r) {
echo "<div class=error>Such user has already registered</div>";
signup_step1();
return(15);
}

It doesn't appear that you're actually wanting to use the value of mysql_num_rows, just that any value being returned will trigger an action. I can see potential problems with this code, but it should at least get you moving forward.

eelixduppy

1:00 pm on Apr 6, 2007 (gmt 0)




it says, no database

Generally when you are getting an error like this it means that you didn't specify the database correctly using mysql_select_db [php.net]. Take a look at this. I also don't see where you connect to the db server in the first place; maybe it is up above?

exposo

7:22 pm on Apr 6, 2007 (gmt 0)

10+ Year Member



grandpa, it doesn't work:(
thanks,

eelixduppy, thanks, I have created, iii.php
with this code, changed data, and is said, it cannot do the action to my database.

<?php

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>

well
and connection in signup.php code is on 50-88 lines, and the errors are on 170 line.

// starting signup process
include("config.php");

$link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die ("Could not connect");

@mysql_select_db(DB_NAME, $link);

// step one, we collect all the info
function signup_step1() {
include("signup.html");
return(0);
}

// step two, we check all the collected info, and if everything is fine, we send an email with further instructions.
function signup_step2() {

// preparing all the variables
global $link;
global $siteurl;
global $sitename;
global $hostpress_server_path;
global $adminemail;

$username = trim($username);
$password = trim($password);
$password2 = trim($password2);
$email = trim($email);

$username = htmlspecialchars($_POST['username']);
$password = htmlspecialchars($_POST['password']);
$password2 = htmlspecialchars($_POST['password2']);
$email = htmlspecialchars($_POST['email']);