Jump to content

query mysql_num_rows help.


dominic600

Recommended Posts

so heres my error:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a3888506/public_html/register.php on line 96

 

i see some stuff online in searches i have done but idk what to do about it.

 

im guessing it cant connect to the database because of this ? idk..

but heres my code if it would help at all.

<?php require("styles/top.php"); ?>
<div id='content'>
<div id='full'>

<?php

$form = "<form action='register.php' method='post'>
<table>
	<tr>
	<td></td>
	<td>Fields indicating <font color='red'>*</font> are require.</td>
</tr>
<tr>
	<td>First Name:</td>
	<td><input type='text' name='firstname'><font color='red'>*</font></td>
</tr>

	<tr>
	<td>Last Name:</td>
	<td><input type='text' name='lastname'><font color='red'>*</font></td>
</tr>

	<tr>
	<td>Username:</td>
	<td><input type='text' name='username'><font color='red'>*</font></td>
</tr>

	<tr>
	<td>E-mail:</td>
	<td><input type='text' name='email'><font color='red'>*</font></td>
</tr>

	<tr>
	<td>Password:</td>
	<td><input type='password' name='password'><font color='red'>*</font></td>
</tr>

	<tr>
	<td>Confirm Password:</td>
	<td><input type='password' name='repassword'><font color='red'>*</font></td>
</tr>

	<tr>
	<td>Avatar:</td>
	<td><input type='file' name='avatar'></td>
</tr>

	<tr>
	<td>Website:</td>
	<td><input type='text' name='website'></td>
</tr>

	<tr>
	<td>Youtube User Name:</td>
	<td><input type='text' name='youtube'></td>
</tr>

	<tr>
	<td>Bio:</td>
	<td><textarea name='bio' cols='35' rows='5'></textarea></td>
</tr>

	<tr>
	<td></td>
	<td><input type='submit' name='submitbtn' value='Register'></td>
</tr>
</table>

</form>";

if ($_POST['submitbtn']){


$firstname = strip_tags($_POST['firstname']);
$lastname = strip_tags($_POST['lastname']);
$username = strip_tags($_POST['username']);
$email = strip_tags($_POST['email']);
$password = strip_tags($_POST['password']);
$repassword = strip_tags($_POST['repassword']);
$website = strip_tags($_POST['website']);
$youtube = strip_tags($_POST['youtube']);
$bio = strip_tags($_POST['bio']);

$name = $_FILES['avatar'] ['name'];
$type = $_FILES['avatar'] ['type'];
$size = $_FILES['avatar'] ['size'];
$tmpname = $_FILES['avatar']['tmpname'];
$ext = substr($name, strrpos($name, '.'));

if ($firstname && $lastname && $username && $email && $password && $repassword){
	if ($password == $repassword){
		if (strstr($email, "@") && strstr($email, ".") && strlen($email) >= 6){

			require("scripts/connect.php");
			$query=mysql_query("SELECT * FROM users WHERE username='$username' ");
			$numrows=mysql_num_rows($query);
			if ($numrows == 0){

				$query=mysql_query("SELECT * FROM users WHERE email='$email' ");
				$numrows=mysql_num_rows($query);
				if ($numrows == 0){

				$pass = md5(md5($password));
				$date = date("F d, Y");

				if($name){
					move_uploaded_file($tmpname, "avatars/$username.$ext");
					$avatar = "$username.$ext";
				}
				else
					$avatar = "default_avatar.png";

				$code = substr (md5(rand(11111111111, 999999999999999)), 2,  25);

				mysql_query("INSERT INTO users VALUES ('', '$firstname', '$lastname', '$username', '$email', 'pass', '$avatar', '$bio', '$website', '$youtube', '', '0', '$code', '0', '$date')");

						$webmaster = "Admin@trucksite.com";
						$subject = "Activate Your Account!";
						$headers = "From: Admin <$webmaster>";
						$message = "Hello $firstname.\n\nWelcome to trucksite below is a link for you to activate your account!.\n http://tprofiletesting.net23.net/activate.php?code=$code";

						mail($email, $subject, $message, $headers);
						echo "Your activation email has been sent to <b>$email</b>.";
				}
				else
					echo "That email is currently in use.";

			}
			else
				echo "That username is currently in use.";
		}
		else
			echo "You did not enter a vaild email.";
	}
	else
		echo "Your passwords did not match.";
}
else
	echo"You did not fill in all the required fields.";
}
echo "$form";


?>
</div>
<div id='footer'><a href='#'>Link</a><a href='#'>Link</a><a href='#'>Link</a><a href='#'>Link</a><a href='#'>Link</a><a href='#'>Link</a></div>




<body>
</body>
</html>

Link to comment
Share on other sites

Hi Dom,

 

I see your problem arises due to an incomplete query

 

mysql_query("INSERT INTO users VALUES ('', '$firstname', '$lastname', '$username', '$email', 'pass', '$avatar', '$bio', '$website', '$youtube', '', '0', '$code', '0', '$date')");

 

You specified the VALUES, thats good, but you also need to specify the fields.

 

Here's an example to further assist you

 

mysql_query("INSERT INTO example (field1, field2) VALUES('value1', 'value2' ) ") 

Link to comment
Share on other sites

Hi Dom,

 

can you please post your SQL table, I can't guess the column names for you however I can tell you that field1 and field 2 are the columns in your database. Value1 is going inside Field1, and Value2 inside Field2. In your case Field1, Field2 is the columns inside the `users ` table.

 

hope you understand buddy :)

Link to comment
Share on other sites

im hoping thats what it is your wanting to look at.

 

-- Host: localhost
-- Generation Time: Aug 06, 2011 at 06:08 PM
-- Server version: 5.1.57
-- PHP Version: 5.2.17

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `a3888506_user`
--

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(50) COLLATE latin1_general_ci NOT NULL,
  `last_name` varchar(75) COLLATE latin1_general_ci NOT NULL,
  `username` varchar(50) COLLATE latin1_general_ci NOT NULL,
  `email` varchar(250) COLLATE latin1_general_ci NOT NULL,
  `password` varchar(75) COLLATE latin1_general_ci NOT NULL,
  `avatar` varchar(60) COLLATE latin1_general_ci NOT NULL,
  `bio` text COLLATE latin1_general_ci NOT NULL,
  `website` varchar(250) COLLATE latin1_general_ci NOT NULL,
  `youtube` varchar(50) COLLATE latin1_general_ci NOT NULL,
  `last_login` varchar(50) COLLATE latin1_general_ci NOT NULL,
  `active` tinyint(1) NOT NULL,
  `code` varchar(25) COLLATE latin1_general_ci NOT NULL,
  `locked` tinyint(1) NOT NULL,
  `date` varchar(50) COLLATE latin1_general_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

--
-- Dumping data for table `users`
--


Link to comment
Share on other sites

Thank you for making my task of helping you easier :)

 

Your query should look like this now, a total of 14 fields and 14 values.

 

mysql_query("INSERT INTO users (`first_name`,`last_name`,`username`,`email`,`password`,`avatar`,`bio`,`website`,`youtube`,`last_login`,`active`,`code`,`locked`,`date`) VALUES ( '$firstname', '$lastname', '$username', '$email', 'pass', '$avatar', '$bio', '$website', '$youtube', '', '0', '$code', '0', '$date')");

 

I also noticed that date should be a datetime field type not a varchar.

 

  `date` varchar(50) COLLATE latin1_general_ci NOT NULL,

Link to comment
Share on other sites

I see, we still haven't tackled the main error.

 

Dominic, can you please change your SELECT queries and add this at the end of them?

 

$query=mysql_query("SELECT * FROM users WHERE username='$username' ");

 

to

 

$query=mysql_query("SELECT * FROM users WHERE username='$username' ") or die(mysql_error());

Link to comment
Share on other sites

Hi

 

The query looks very simple and not much room for error in it.

 

I would suspect that what has happened is that the connection to the database hasn't worked. Possibly a wrong userid or password in "scripts/connect.php", or possibly an error in that script.

 

All the best

 

Keith

Link to comment
Share on other sites

okay,

just 1 thing tho.. i put in all my information in the connect.php as it is on my hosting service and it still does not work.

 

do you see anything that could be wrong with this?

<?php

$server = "mysql4000webhost.com";
$dbuser = "a38806_dominic";
$dbpass = "1992";
$database = "users";

mysql_connect($server, $dbuser, $dbpass);
mysql_select_db($database);

?>

Link to comment
Share on other sites

I signed up for an account in order to further assist you, I was given this upon providing my own database username password,

 

your password is incorrect

 

$mysql_host = "mysql4.000webhost.com";
$mysql_database = "a8124442_phpsens";
$mysql_user = "a8124442_phpsens";
$mysql_password = "abc1234";

 

should be

 

<?php

$server = "mysql4000webhost.com";
$dbuser = "a38806_dominic";
$dbpass = "a38806_1992";
$database = "users";

mysql_connect($server, $dbuser, $dbpass);
mysql_select_db($database);

?>

Link to comment
Share on other sites

Alright, I believe your main issue has been solved with the queries, ask the web hosting company if there is a problem on their end also. There are downtime and you can always try and make a new mysql username/password.

 

Mark topic solved for now.

why do you tell people to mark the topic as solved so much? I think you have told people to mark as solved in the last 20 posts I have read of yours...once the user says they are content with their issue is when you can direct them to the "Topic Solved" button...

Link to comment
Share on other sites

what website are you making

 

 

LMAO... Just end it man, Topic solved, lets go make some pan cakes, drinks on me 8) AyKay you silly bastard

 

problem solved, what happend was i thought my database name was 'users' turns out it was 'user'

 

lol my site is back on track. thank you for all your help tho phpSensi, hopefully after this website i can come and help people on here!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.