[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Warning: mysql_num_rows() expects parameter 1 to be resource....

Asked by seeminglylost in MySQL Server, PHP Scripting Language

I am creating a simple login page using php and MySQL. I am new at this and cannot figure out why I am getting this error:

Warning: mysql_num_rows() expects parameter 1 to be resource, null given in RegisterUser.php on line 53

Unable to execute the query.

Error code 0:

Code that is being referenced is:
[code]
if (mysql_num_rows($QueryResult) > 0) {
[/code]

I am using xampp by apache friends 1.7.2. I have dumped my database and table several times. Everything appears to be as it should but I don't know where I am going wrong.

My table info is:

SQL result

Host: localhost
Database: songorganizer
Generation Time: Nov 07, 2009 at 01:35 AM
Generated by: phpMyAdmin 3.2.0.1 / MySQL 5.1.37
SQL query: show create table registered_users;
Rows: 1
Table registered_users
Create Table
CREATE TABLE `registered_users` (
`ID` smallint(6) NOT NULL AUTO_INCREMENT,
`email` varchar(40) DEFAULT NULL,
`password` varchar(10) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

Any ideas where it is that I am going wrong??
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
<?php
session_start();
if (empty($_GET['email']) || empty($_GET['email_confirm'])
	|| empty($_GET['password']) 
	|| empty($_GET['password_confirm']))
	exit("<p>You must enter values in all fields of the Registration form! Click your browser's Back button to return to the previous page.</p>"); 
else if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_GET['email']))
	exit("<p>You must enter a valid e-mail address! Click your browser's Back button to return to the previous page.</p>"); 
else if ($_GET['email'] != $_GET['email_confirm'])
	exit("<p>You did not enter the same e-mail address! Click your browser's Back button to return to the previous page.</p>"); 
else if ($_GET['password'] != $_GET['password_confirm'])
	exit("<p>You did not enter the same password! Click your browser's Back button to return to the previous page.</p>"); 
else if (strlen($_GET['password']) < 5 || strlen($_GET['password']) > 10)
	exit("<p>Your password must be between 5 and 10 characters! Click your browser's Back button to return to the previous page.</p>"); 
$DBConnect = @mysql_connect("localhost", "root")
	Or die("<p>Unable to connect to the database server.</p>"
	. "<p>Error code " . mysql_connect_errno()
	. ": " . mysql_connect_error()) . "</p>"; 
// select and create database
$DBName = "songorganizer";
if (!@mysql_select_db($DBName)) {
	$SQLstring = "CREATE DATABASE $DBName";
	$QueryResult = @mysql_query($SQLstring)
		Or die("<p>Unable to execute the query.</p>"
		. "<p>Error code " . mysql_errno($DBConnect)
		. ": " . mysql_error($DBConnect)) . "</p>";
	echo "<p>You entered your first song!</p>";
	mysql_select_db($DBName);
} 
$TableName = "registered_users";
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysql_query($SQLstring);
if (!$QueryResult) {
 	$SQLstring = "CREATE TABLE $TableName (ID SMALLINT NOT NULL AUTO_INCREMENT PRIMARY KEY, email VARCHAR(40), password VARCHAR(10))";
 	$QueryResult = @mysql_query($SQLstring)
 		Or die("<p>Unable to create the table.</p>"
 		. "<p>Error code " . mysql_errno($DBConnect)
 		. ": " . mysql_error($DBConnect)) . "</p>";
}
$TableName = "registered_users";
$Email = addslashes($_GET['email']);
$Password = addslashes($_GET['password']);
$SQLstring = "SELECT * FROM $TableName";
$QueryResult = @mysql_query($DBConnect, $SQLstring); 
if (mysql_num_rows($QueryResult) > 0) {
	$Row = mysql_fetch_row($QueryResult);
	do {
		if (in_array($Email, $Row))
			exit("<p>Hi, the e-mail address you entered is already
registered! Click your browser's Back button to
return to the previous page.</p>");
		$Row = mysql_fetch_row($QueryResult);
	} while ($Row);
	mysql_free_result($QueryResult);
} 
$SQLstring = "INSERT INTO $TableName VALUES(NULL, '$Email',
'$Password')";
$QueryResult = @mysql_query($DBConnect, $SQLstring)
	Or die("<p>Unable to execute the query.</p>"
 		. "<p>Error code " . mysql_errno($DBConnect)
 		. ": " . mysql_error($DBConnect)) . "</p>";
$_SESSION['ID'] = mysql_insert_id($DBConnect);
mysql_close($DBConnect);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Song Organizer Site</title><img src="Butterfly/images/header.gif" width="875" height="50" alt="" title="" border="0" align="right" />
<link rel="stylesheet" href="php_styles.css" type="text/css" />
<meta http-equiv="content-type"
      content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Song Organizer</h1>
<h2>User Registration</h2>
<p>Your new user ID is <strong>
<?= $_SESSION['userID'] ?></strong>.</p>
<p><a href="UpdateContactInfo.php">Enter Contact Information</a></p>
</body>
</html>
[+][-]11/07/09 07:21 AM, ID: 25766567Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: MySQL Server, PHP Scripting Language
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 4
Solution Grade: A
 
[+][-]11/06/09 09:54 PM, ID: 25765154Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 11:24 PM, ID: 25765300Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/09 06:39 AM, ID: 25766459Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/09 02:15 PM, ID: 25768303Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/09 02:26 PM, ID: 25768348Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/07/09 03:19 PM, ID: 25768558Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/09 03:50 PM, ID: 25768677Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/07/09 05:31 PM, ID: 25768975Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/09 06:55 PM, ID: 25769237Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/08/09 06:18 AM, ID: 25770545Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625