Jump to content

can't sign in to mysql using posted $user and $pass1


gloosemo

Recommended Posts

this code is to create a new user based on posted variables. it works fine for creating the necessary tables and granting privileges. but then when i log out as root and try to log back in as the user it's failing. why is it failing? Thanks, G.

 

		<?php
			extract( $_POST );
			include( '../php/userobject.php' );

			@ $db = mysqli_connect('localhost', 'root', 'xxxxxx', 'mealchamp');
			if ( mysqli_connect_errno() ) {
				echo 'Error: could not connect to database as root.<br />';
				exit;
			}
			else
				echo 'Connected to database as root.<br />';

			$query = "SELECT username FROM userlist WHERE username = $uname";
			$result = mysqli_query($db, $query);

			if ($result) 
				echo 'That user name is already taken.<br/>Please hit back on your browser, and try a different user name.<br/>';
			else {
				echo 'That username is available.<br/>';
				echo "$fname<br/>";
				echo "$lname<br/>";
				echo "$add1<br/>";
				echo "$add2<br/>";
				echo "$city<br/>";
				echo "$prov<br/>";
				echo "$ctry<br/>";
				echo "$post<br/>";
				echo "$email<br/>";
				echo "$uname<br/>";
				echo "$pass1<br/>";
				echo "$sex<br/>";
				echo "$birth<br/>";
				echo "$height<br/>";
				echo "$weight<br/>";

				$query = "INSERT INTO userlist 
						(firstname, lastname, address1, address2, city, 	province, country, postal, email, 	username, password, sex, 		birth, 		height, 		weight) VALUES
						('$fname',	'$lname',	'$add1',	'$add2',	'$city','$prov',	'$ctry', '$post','$email','$uname',	'$pass1',	'$sex', '$birth', '$height', 	'$weight')";
				$result = mysqli_query($db, $query);
				if ($result)
					echo "Userlist was updated successfully<br />";
				else
					echo "Could not update userlist";

				$query = "CREATE TABLE ".$uname."_persfood  
					(persfoodid 	INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
					 food			 		VARCHAR(30) NOT NULL)";
				$result = mysqli_query($db, $query);
				if ($result)
					echo "Personal food table was created successfully<br />";
				else
					echo "Could not create personal food table<br />";

				$query = "GRANT select ON mealchamp.userlist TO ".$uname." IDENTIFIED BY '$pass1'";
				$result = mysqli_query($db, $query);
				if ($result)
					echo "User priveleges were granted successfully<br />";
				else
					echo "Could not grant user priveleges<br />";
				$query = "GRANT select, insert, update, delete, index ON mealchamp.".$uname."_persfood TO ".$uname." IDENTIFIED BY '$pass1'";
				$result = mysqli_query($db, $query);
				if ($result)
					echo "User priveleges were granted successfully<br />";
				else
					echo "Could not grant user priveleges<br />";

				mysqli_close($db);

				@ $db = mysqli_connect('localhost', $uname, $pass1, 'mealchamp');
				if ( mysqli_connect_errno() ) {
					echo 'Error: could not connect to database as user.<br />';
					exit;
				}
				else {
					echo 'Connected to database as user.<br />';
?>

Link to comment
Share on other sites

it says at the end the mysqli_connect_errno() message ---> echo 'Error: could not connect to database as user.'

 

Then when i try to do things with the $db resource i get warnings that it is not a valid resource. The $db connection is not being established. Did i miss quotation marks somewhere or something???

 

thanks again, G

Link to comment
Share on other sites

Error: Access denied for user 'pleasework'@'localhost' (using password: YES)

 

that is when

 

$uname = pleasework

$pass = pleasework

 

and this time i queried "FLUSH PRIVILEGES" after doing the grants.

 

does it have something to do with maybe i should be adding @localhost to the usernames somewhere?

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.