Jump to content

[SOLVED] trying to register problems


9three

Recommended Posts

Every time I hit register, i get 2 errors and one thrown exception.

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Users\9three\Desktop\Server\htdocs\CMS\admin\add.php on line 27

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\Users\9three\Desktop\Server\htdocs\CMS\admin\add.php on line 33

 

Fatal error: Uncaught exception 'Exception' with message 'Unable to query' in C:\Users\9three\Desktop\Server\htdocs\CMS\admin\includes\library\mysql.class.php:40 Stack trace: #0 C:\Users\9three\Desktop\Server\htdocs\CMS\admin\add.php(43): mysql->query('INSERT INTO adm...') #1 {main} thrown in C:\Users\9three\Desktop\Server\htdocs\CMS\admin\includes\library\mysql.class.php on line 40

 

<?php
require('includes/includes.php');

if(isset($_POST['register']))
{
  $connection = new mysql('localhost', 'root', '');
  $connection->select('cms');
  
  /**
   * Sanitize all possible input values 
   * Force first charater in username to be capitilized
   * Force email to be all lowercase
   */

  $username = escape(ucfirst($_POST['username']));
  $password = escape(secure($_POST['password']));
  $email = escape(strtolower($_POST['email']));  
  
  $qusername = "SELECT Username 
                FROM admins 
                WHERE Username = '$username'";
  $qemail = "SELECT Email 
             FROM admins 
             WHERE Email = '$email'";

  //Check if Username is taken
  if (mysql_num_rows($qusername) > 0)
  {
    echo 'Username is taken, please select another';
    exit;
  }
  //Check if Email is taken
  elseif (mysql_num_rows($qemail) > 0)
  {
    echo 'Email is taken, please use another';
    exit;
  }
  else
  {
    $query = "INSERT INTO admins (Username, Password, Email) 
              VALUES ('$username', '$password', '$email')";

    $register = $connection->query($query);
    if ($register)
    {
      echo 'Registration complete. You may now login.';
    }
    else
    {
      echo 'There was a problem during registration, please try again.';
    }
  }
}
?>

 

I have tried echo mysql_error but the only thing that shows up is mysql_num_rows error. I also tried to echo the query and manually put it into my database and it works fine.

Link to comment
https://forums.phpfreaks.com/topic/140329-solved-trying-to-register-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.