0

I am trying to make a simple register form in PHP with a free host not localhost, to send me an activation mail. This is the content of connect.php

<?php

$dburl = "xxxx.freehostxxx.com";  
$dbuser = "xxxx";
$dbpass = "xxxx";

$handle = mysql_connect($dburl,$dbuser,$dbpass);
mysql_select_db("userdb", $handle);

?>

Before I this error, I found a solution on SO for Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in and I added in my every SELECT or die (mysql_error()); and now I keep getting this error. On localhost everything works fine. Database is imported, so I do not think I have a problem at that point.

<?php

if($_POST['registerbtn'])
{
    $getuser = $_POST['user'];
    $getemail = $_POST['email'];
    $getpass = $_POST['pass'];
    $getretypepass = $_POST['retypepass'];

    if($getuser)
    {
      if($getemail)
      {
        if($getpass)
        {
          if($getretypepass)
          {
            if( $getpass === $getretypepass)
            {
              if( (strlen($getemail) >= 7) && (strstr($getemail, "@")) && (strstr($getemail, ".") ) )
              {
                require("./connect.php");
                $query = mysql_query("SELECT * FROM userdb WHERE username =' $getuser '") or die (mysql_error());
                $numrows = mysql_num_rows($query);

                if($numrows == 0)
                { 
                    $query = mysql_query("SELECT * FROM userdb WHERE email = ' $getemail '") or die (mysql_error());
                    $numrows = mysql_num_rows($query);
edwardmp
  • 6,339
  • 5
  • 50
  • 77
user3061587
  • 11
  • 1
  • 4
  • 3
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – Danny Beckett Dec 07 '13 at 23:59
  • Can you change `$handle = mysql_connect($dburl,$dbuser,$dbpass);` into `$handle = mysql_connect($dburl,$dbuser,$dbpass) or die('Could not connect: ' . mysql_error());` - and to `mysql_select_db` similar - and tell if it shows an error (or not)? Also, above comment – Peter van der Wal Dec 08 '13 at 00:02
  • Same error, connect function I think is fine... – user3061587 Dec 08 '13 at 00:09
  • Well, I solved the problem finally! I added an port and I made a new variable $db_name for mysql_select_db and I deleted imported database and I created a new one. – user3061587 Dec 08 '13 at 01:35
  • You haven't solved anything until you throw this code out and use PDO or MySQLi, and fix your **massive** SQL-injection vulnerabilities. – user229044 Dec 08 '13 at 01:51
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – John Conde Dec 19 '13 at 01:47

0 Answers0