<?php

 $login = $_POST['login'];
 $nickname = $_POST['nickname'];
 $senha = $_POST['senha'];
 $email = $_POST['email'];



 $conexao = mysql_pconnect("localhost","rodrigue_incub","xxx24df") or die (mysql_error());
 $banco = mysql_select_db("rodrigue_incubadora");

 //Utilizando o  mysql_real_escape_string voce se protege o seu codigo contra SQL Injection.
 $login = mysql_real_escape_string($login);
 $nickname = mysql_real_escape_string($nickname);
 $senha = mysql_real_escape_string($senha);
 $email = mysql_real_escape_string($email);


	$consulta = mysql_query("SELECT * FROM usuarios WHERE login = '$login'");
    $NumeroLinhas = mysql_num_rows($consulta);
	if ($NumeroLinhas < 1) {


    $consulta2 = mysql_query("SELECT * FROM usuarios WHERE nickname = '$nickname'");
    $NumeroLinhas2 = mysql_num_rows($consulta2);
	if ($NumeroLinhas2 < 1) {


 $insert = mysql_query("insert into usuarios (login,nickname,senha,email) values ('{$login}','{$nickname}','{$senha}','{$email}')");
 mysql_close($conexao);
 if($insert) {
     print "Cadastro Realizado!";
 }else {
     print "Erro ao Cadastrar!";
 }
 }else{
 print "Nickname ja esta em uso!";
 }
 }else{
 print "Login ja esta em uso!";
 }
 ?>

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/rodrigue/public_html/dmo/enviar.php on line 21

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/rodrigue/public_html/dmo/enviar.php on line 26

Help me please =(((

Dani AI

Generated

The two warnings mean mysql_num_rows() was given FALSE instead of a valid result resource — in other words the SELECT calls failed. Common reasons are: the database wasn't selected correctly, the query had an error, the DB user lacks privileges, or a non-SELECT result was passed to mysql_num_rows(). In this thread 's errors at lines 21 and 26 show both queries returned FALSE, so the next step is to see the actual MySQL error.

Quick debugging checklist

  • Turn on error reporting while debugging (locally only): error_reporting(E_ALL); ini_set('display_errors', 1);.
  • Check the return value of mysql_select_db() and every mysql_query(); if a query returns FALSE call mysql_error() immediately to get the server message.
  • Confirm POST data is arriving (use var_dump($_POST) or log $login/$nickname) so the WHERE clause isn't malformed or empty.
  • Verify the table exists and the DB user has SELECT privileges (SHOW TABLES / check privileges).
  • Don’t rely on count($result) on a raw query result — it can be misleading when the query failed. Always check the query result for FALSE first.

A safer, modern approach (replace the old mysql_* stack)

$mysqli = new mysqli('localhost','dbuser','dbpass','rodrigue_incubadora');
if ($mysqli->connect_errno) { die('Connect error: '.$mysqli->connect_error); }

$stmt = $mysqli->prepare('SELECT id FROM usuarios WHERE login = ?');
$stmt->bind_param('s', $login);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows === 0) {
    // insert using prepared statement; hash passwords with password_hash()
}

Notes and best practices: as suggested, verify the exact query string; as warned, count() can hide the real problem; ' FAQ pointer is useful. For long-term stability migrate to mysqli or PDO, use prepared statements and password_hash() for passwords, and enforce uniqueness at the database level with UNIQUE indexes instead of doing two separate SELECT checks.

Recommended Answers

All 8 Replies

I prefer you to first check whether you are able to fetch data from database using mysql_fetch_array....
Because there is error in the query.....
Check this....It might work...

$consulta = mysql_query("SELECT * FROM usuarios WHERE login = '".$login."'");

If this works then it's ok...
otherwise give the complete database and i will help u to find the solution

Didn't worked =/

CREATE TABLE IF NOT EXISTS `usuarios` (
  `login` varchar(15) NOT NULL default '',
  `nickname` varchar(15) NOT NULL default '',
  `senha` varchar(20) NOT NULL default '',
  `email` varchar(40) NOT NULL default '',
  `id` int(10) unsigned NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ;

easier method is using count($result); then echo it out on screen

oh and remove all the if/else statements, use the following instead:

switch ($i) {
    case 0:
        echo "i equals 0";
        break;
    case 1:
        echo "i equals 1";
        break;
    case 2:
        echo "i equals 2";
        break;
}

easier method is using count($result); then echo it out on screen

Worked but it give me result = 1 but haven't no one register in DB...

Oh My God,what's wrong, --.--''''

mysql_num_rows is only if u want to retreive back 1 row from the database, i would use mysql_fetch_array.

Go through the "Read Me: FAQ:" post on the top of the php posts and follow the steps mentioned in that post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.