Hi, I'm quite new to PHP and MYSQL, but I have chosen to do an A-level project in it. This is just a basic registering page, which I've copied and modified from one out of a book. That one works, but this doesn't, saying that "mysql_numrows(): supplied argument is not a valid MySQL result resource". I hope that makes sense to someone.

<?php #Script 8.7 - register.php
//SEND NOTHING TO BROWSER BEFORE HEADER()

//Check if form is sumbitted
if (isset($_POST['submitted'])) {
    
    require_once('../mysql_pp_connect.php');
    
    $errors = array();
    
    //Validate crap
    if (empty($_POST['title'])) {
        $errors[] = 'You forgot to enter your first name.';
    } else {
        $t = escape_data($_POST['title']);
    }
    
    if (empty($_POST['first_name'])) {
        $errors[] = 'You forgot to enter your first name.';
    } else {
        $fn = escape_data($_POST['first_name']);
    }
    
    if (empty($_POST['last_name'])) {
        $errors[] = 'You forgot to enter your last name.';
    } else {
        $ln = escape_data($_POST['last_name']);
    }
    
    if (empty($_POST['addressline1'])) {
        $errors[] = 'You forgot to enter your address.';
    } else {
        $al1 = escape_data($_POST['addressline1']);
    }
    
    $al2 = escape_data($_POST['addressline2']);
    $al3 = escape_data($_POST['addressline3']);
    
    if (empty($_POST['postcode'])) {
        $errors[] = 'You forgot to enter your postcode.';
    } else {
        $pc = escape_data($_POST['postcode']);
    }
    
    if (empty($_POST['email'])) {
        $errors[] = 'You forgot to enter your email address.';
    } else {
        $e = escape_data($_POST['email']);
    }
    
    if (empty($_POST['phone_number'])) {
        $errors[] = 'You forgot to enter your phone number.';
    } else {
        $pn = escape_data($_POST['phone_number']);
    }
    
    if(!empty($_POST['password1'])) {
        if($_POST['password1'] != $_POST['password2']) {
            $errors[] = "Your passwords didn't match";
        } else {
            $p = escape_data($_POST['password1']);
        }
    } else {
        $errors[] = "You didn't enter a password!";
    }
    
    if (empty($errors)) {
        
        $query = "SELECT user_id FROM users WHERE email='$e'";
        $result = mysql_query ($query);
        if (mysql_num_rows($result) == 0) {        
        
             //Make query
             $query = "INSERT INTO customers (Title, FirstName, LastName, AddressLine1, AddressLine2, Addressline3, Postcode, EmailAddress, PhoneNumber, Password) VALUES ('$t', '$fn', '$ln', '$al1', '$al2', '$al3', '$pc', '$e', '$pn', SHA('$p'))";
             $result = @mysql_query ($query); //Run query
        
             if ($result) {
        
                  //send email blah blah
            
                    //redirect to thanks.php page
                    //start defining url
                    $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
            
                    if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\')) {
                        $url = substr($url, 0, -1); //chop off slashah.
                    }
            
                    $url .= '/thanks.php';
            
                    header("Location: $url");
                    exit();
        
            } else {
                $errors[] = 'You could not be registered due to a system error. oops. sorry!';
                $errors[] = mysql_error() . '<p>Query ' . $query;
            }
        
    } else {
        $errors = 'The email address has already been registered!';
    }
        
}
mysql_close();

}else{
    $errors = NULL;
} //end of submit conditional
$page_title = 'Register';
include ('./header.html');

if(!empty($errors)){
    echo '<h1 id="mainhead">Error!</h1><p class="error">The following errors occurred:<br><ul>';
    foreach ($errors as $msg) {
        echo "<li>$msg</li><br>";
    }
    echo '</ul><p>Please try again';
} //end of if empty errrors if
 ?>

Cheers

Your query probably fails, try debugging:

$result = mysql_query ($query) or die(mysql_error());

Yay, thanks. That was it, I'd forgotten my table was called something different. Thanks again.

Your query probably fails, try debugging:

$result = mysql_query ($query) or die(mysql_error());

I have the same problem and I check all the things and precautions. My code is ok. But I dont know what is the problem. My battery is gone down and I just want to post it to get answers when I came again. So please help I also debug it, and that's ok. Help it mess up my time.

Thanks

Member Avatar for spthorn

I have the same problem and I check all the things and precautions. My code is ok. But I dont know what is the problem.

Chand, your code is obviously NOT ok. :-) Please paste your code in this or another thread for us to review.

I have the same problem and I check all the things and precautions. My code is ok. But I dont know what is the problem. My battery is gone down and I just want to post it to get answers when I came again. So please help I also debug it, and that's ok. Help it mess up my time.

Thanks

Read the FAQ dealing with this problem instead of reviving 2 year old threads.

Chand, your code is obviously NOT ok. :-) Please paste your code in this or another thread for us to review.

//index.php

<! DOCTYPE HTML PUBLIC "W3C//DTD// HTML 4.01//TRANSITIONAL//EN">

<HTML>
<HEAD>
<TITLE>Wish to visualize!</TITLE>
</HEAD>

<BODY>

<form action="wishlist.php" method="GET" name="wishList">
      Show wish list of: <input type="text" name="user"/>
		<input type="submit" value="Go" />
</form>

<?php


?>
</BODY>

</HTML>

//wishlist.php

<! DOCTYPE HTML PUBLIC "W3C//DTD// HTML 4.01//TRANSITIONAL//EN">


<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
    <body>
        Wish List of <?php echo  $_GET["user"]."<br/>";?>
        
		<?php

		$con = mysql_connect("localhost", "root", "");
		if(!$con){
			die('Could not connect!' .mysql_error());
		}else{
			echo("connected!");
		}
		mysql_query("SET NAMES 'utf8'");   
		
		if(mysql_select_db("wishlist", $con)){
			echo("DB is selected.<del>");
		}
		
		$wisher = mysql_query("SELECT id FROM wishes WHERE description = '".mysql_real_escape_string($_GET["user"])."'");
		
		if(!($wisher)){
			die(mysql_error());
		}
		
		if(mysql_num_rows(($wisher)<1)){
			die("The specified person".$_GET["user"]. "is not exist here");
		}
		
		$wisherId = mysql_result($wisher, 0);
	

		
		       
        
        ?>
        
    </body>
    </html>
Member Avatar for spthorn

The following line has parenthesis issues: if(mysql_num_rows(($wisher)<1)){ It should be: if(mysql_num_rows($wisher)<1){

Thank you so much for your help. I'm very grateful to you. I'm a novice could you tell me about good learning resources for php.

Thanks

Member Avatar for spthorn

Since your bug was a syntax one, you might consider an IDE. See http://www.ibm.com/developerworks/library/os-php-ide/index.html for a list of suggestions. However, there can be a tendency to rely on the IDE to fix your mistakes. I personally use a simple text editor to write code, which forces me to learn and memorize syntax and base library calls, which I think is a good thing. I can focus more on writing good code than on language technicalities

There are many ways to learn. Online I often recommend http://www.w3schools.com/PHP/DEfaULT.asP as a starter, but a good book would work as well. code, code, code.

hey i get this error Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in XXXXXXXXXXXX and this is my PHP codes wen im doing a account (thats the page is for) this error come ups what shell i do ?

my PHP codes --------->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
if($_POST)
{
    $con = mysql_connect("127.0.0.1", "root", "mangos");
    if(!$con)
        $msg = "Unable to create a Database connection.";
    if($con)
    {
        mysql_select_db("realmd", $con);
        $user = $_POST['login'];
        $pass = $_POST['password'];
        $email = $_POST['email'];
        $pack = $_POST['formselect1'];

        if(!$user)
            $msg = "Please fill out your Username.";
        else if(!$pass)
            $msg = "Please fill out your Password.";
        else if(!$email)
            $msg = "Please fill out your E-Mail Address.";
        else
        {
            $check = mysql_query("realmd=\"".$user."\" LIMIT 1", $con);
            if(mysql_numrows($check) > 0)
                $msg = "This account already exists.";
            else
            {
                $query = "INSERT INTO accounts (login, password, email, flags) VALUES ('" . 

mysql_real_escape_string($user) . "', '" . mysql_real_escape_string($pass) . "', '" . mysql_real_escape_string

($email) . "', '" . mysql_real_escape_string($pack) . "');";

                if(!mysql_query($query, $con))
                    $msg = "Creation of ".$user." has failed.";
                else
                    $msg = "Account ".$user." has been created.";
            }
        }
        @mysql_close($con);
    }
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Account Creation</title>

<style type="text/css">
/*----------Text Styles----------*/
.ws6 {font-size: 8px;}
.ws7 {font-size: 9.3px;}
.ws8 {font-size: 11px;}
.ws9 {font-size: 12px;}
.ws10 {font-size: 13px;}
.ws11 {font-size: 15px;}
.ws12 {font-size: 16px;}
.ws14 {font-size: 19px;}
.ws16 {font-size: 21px;}
.ws18 {font-size: 24px;}
.ws20 {font-size: 27px;}
.ws22 {font-size: 29px;}
.ws24 {font-size: 32px;}
.ws26 {font-size: 35px;}
.ws28 {font-size: 37px;}
.ws36 {font-size: 48px;}
.ws48 {font-size: 64px;}
.ws72 {font-size: 96px;}
.wpmd {font-size: 13px;font-family: 'Arial';font-style: normal;font-weight: normal;}
/*----------Para Styles----------*/
DIV,UL,OL /* Left */
{
 margin-top: 0px;
 margin-bottom: 0px;
}
</style>

<style type="text/css">
div#container
{
    position:relative;
    width: 895px;
    margin-top: 0px;
    margin-left: auto;
    margin-right: auto;
    text-align:left; 
}
body {text-align:center;margin:0}
</style>

</head>

<body Text="#FFFFFF" bgColor="#000000">

<div id="container">
<div id="image1" style="position:absolute; overflow:hidden; left:0px; top:150px; width:895px; height:587px; z-

index:0"><img src="images/skin-wow.jpg" alt="" border=0 width=895 height=587></div>

<div id="text1" style="position:absolute; overflow:hidden; left:495px; top:333px; width:247px; height:208px; z-

index:1"><div class="wpmd">
<div><font class="ws14" color="#008000" face="Tahoma">Select Expansion !</font></div>
<div><font class="ws14" color="#008000" face="Tahoma"><BR></font></div>
<div><font color="#000000" face="Tahoma">Select your WoW Expansion :</font></div>
<div><font color="#000000" face="Tahoma"><BR></font></div>
<div><font color="#000000" face="Tahoma">World of Warcraft</font></div>
<div><font color="#000000" face="Tahoma">The Burning Crusade</font></div>
<div><font color="#000000" face="Tahoma">Wrath of the Lich King <small>(Includes TBC)</small></font></div>
</div></div>

<div id="text2" style="position:absolute; overflow:hidden; left:232px; top:367px; width:48px; height:14px; z-

index:5"><div class="wpmd">
<div><font class="ws7" color="#000000" face="Tahoma">Username</font></div>
</div></div>

<div id="text3" style="position:absolute; overflow:hidden; left:231px; top:409px; width:48px; height:14px; z-

index:6"><div class="wpmd">
<div><font class="ws7" color="#000000" face="Tahoma">Password</font></div>
</div></div>

<div id="text4" style="position:absolute; overflow:hidden; left:231px; top:447px; width:48px; height:14px; z-

index:8"><div class="wpmd">
<div><font class="ws7" color="#000000" face="Tahoma">E-Mail</font></div>
</div></div>

<form method="POST" action="">
<select name="formselect1" style="position:absolute;left:512px;top:496px;width:200px;z-index:2">
<option value="0">World of Warcraft</option>
<option value="8">The Burning Crusade</option>
<option value="32">Wrath of the Lich King</option>
</select>

<input name="login" type="text" style="position:absolute;width:200px;left:232px;top:380px;z-index:3">
<input name="password" type="password" style="position:absolute;width:200px;left:231px;top:422px;z-index:4">
<input name="email" type="text" style="position:absolute;width:200px;left:231px;top:460px;z-index:7">
<input name="submit" type="image" src="images/reg.png" style="position:absolute;left:288px;top:492px;z-index:11">
</form>

<div id="text5" style="position:absolute; overflow:hidden; left:147px; top:606px; width:599px; height:16px; z-

index:10"><div class="wpmd">
<div align=center><font class="ws7" face="Tahoma"><B>YourServer &copy; 2008. All rights 

reserved.</B></font></div>
</div></div>

<html>
<head>
<style>

body { background-color: black; }

 }

</div></body>
</html>

hey i get the same error. wen im doing a account that the codes shell do but wen im trying to do a account so come this error up. whaat shell i do?

my codes---->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
if($_POST)
{
    $con = mysql_connect("127.0.0.1", "root", "mangos") or die(mysql_error());
    if(!$con)
        $msg = "Unable to create a Database connection.";
    if($con)
    {
        mysql_select_db("realmd", $con);
        $user = $_POST['login'];
        $pass = $_POST['password'];
        $email = $_POST['email'];
        $pack = $_POST['formselect1'];

        if(!$user)
            $msg = "Please fill out your Username.";
        else if(!$pass)
            $msg = "Please fill out your Password.";
        else if(!$email)
            $msg = "Please fill out your E-Mail Address.";
        else
        {
            $check = mysql_query("realmd=\"".$user."\" LIMIT 1", $con);
            if(mysql_numrows($check) > 0)
                $msg = "This account already exists.";
            else
            {
                $query = "INSERT INTO accounts (login, password, email, flags) VALUES ('" . mysql_real_escape_string($user) . "', '" . mysql_real_escape_string($pass) . "', '" . mysql_real_escape_string($email) . "', '" . mysql_real_escape_string($pack) . "');";

                if(!mysql_query($query, $con))
                    $msg = "Creation of ".$user." has failed.";
                else
                    $msg = "Account ".$user." has been created.";
            }
        }
        @mysql_close($con);
    }
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Account Creation</title>

<style type="text/css">
/*----------Text Styles----------*/
.ws6 {font-size: 8px;}
.ws7 {font-size: 9.3px;}
.ws8 {font-size: 11px;}
.ws9 {font-size: 12px;}
.ws10 {font-size: 13px;}
.ws11 {font-size: 15px;}
.ws12 {font-size: 16px;}
.ws14 {font-size: 19px;}
.ws16 {font-size: 21px;}
.ws18 {font-size: 24px;}
.ws20 {font-size: 27px;}
.ws22 {font-size: 29px;}
.ws24 {font-size: 32px;}
.ws26 {font-size: 35px;}
.ws28 {font-size: 37px;}
.ws36 {font-size: 48px;}
.ws48 {font-size: 64px;}
.ws72 {font-size: 96px;}
.wpmd {font-size: 13px;font-family: 'Arial';font-style: normal;font-weight: normal;}
/*----------Para Styles----------*/
DIV,UL,OL /* Left */
{
 margin-top: 0px;
 margin-bottom: 0px;
}
</style>

<style type="text/css">
div#container
{
    position:relative;
    width: 895px;
    margin-top: 0px;
    margin-left: auto;
    margin-right: auto;
    text-align:left; 
}
body {text-align:center;margin:0}
</style>

</head>

<body Text="#FFFFFF" bgColor="#000000">

<div id="container">
<div id="image1" style="position:absolute; overflow:hidden; left:0px; top:150px; width:895px; height:587px; z-index:0"><img src="images/skin-wow.jpg" alt="" border=0 width=895 height=587></div>

<div id="text1" style="position:absolute; overflow:hidden; left:495px; top:333px; width:247px; height:208px; z-index:1"><div class="wpmd">
<div><font class="ws14" color="#008000" face="Tahoma">Select Expansion !</font></div>
<div><font class="ws14" color="#008000" face="Tahoma"><BR></font></div>
<div><font color="#000000" face="Tahoma">Select your WoW Expansion :</font></div>
<div><font color="#000000" face="Tahoma"><BR></font></div>
<div><font color="#000000" face="Tahoma">World of Warcraft</font></div>
<div><font color="#000000" face="Tahoma">The Burning Crusade</font></div>
<div><font color="#000000" face="Tahoma">Wrath of the Lich King <small>(Includes TBC)</small></font></div>
</div></div>

<div id="text2" style="position:absolute; overflow:hidden; left:232px; top:367px; width:48px; height:14px; z-index:5"><div class="wpmd">
<div><font class="ws7" color="#000000" face="Tahoma">Username</font></div>
</div></div>

<div id="text3" style="position:absolute; overflow:hidden; left:231px; top:409px; width:48px; height:14px; z-index:6"><div class="wpmd">
<div><font class="ws7" color="#000000" face="Tahoma">Password</font></div>
</div></div>

<div id="text4" style="position:absolute; overflow:hidden; left:231px; top:447px; width:48px; height:14px; z-index:8"><div class="wpmd">
<div><font class="ws7" color="#000000" face="Tahoma">E-Mail</font></div>
</div></div>

<form method="POST" action="">
<select name="formselect1" style="position:absolute;left:512px;top:496px;width:200px;z-index:2">
<option value="0">World of Warcraft</option>
<option value="8">The Burning Crusade</option>
<option value="32">Wrath of the Lich King</option>
</select>

<input name="login" type="text" style="position:absolute;width:200px;left:232px;top:380px;z-index:3">
<input name="password" type="password" style="position:absolute;width:200px;left:231px;top:422px;z-index:4">
<input name="email" type="text" style="position:absolute;width:200px;left:231px;top:460px;z-index:7">
<input name="submit" type="image" src="images/reg.png" style="position:absolute;left:288px;top:492px;z-index:11">
</form>

<div id="text5" style="position:absolute; overflow:hidden; left:147px; top:606px; width:599px; height:16px; z-index:10"><div class="wpmd">
<div align=center><font class="ws7" face="Tahoma"><B>YourServer &copy; 2008. All rights reserved.</B></font></div>
</div></div>

<html>
<head>
<style>

body { background-color: black; }

 }

</div></body>
</html>
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.