Jump to content

What have i done wrong here?


Metorium

Recommended Posts

I am trying to create a log in page but all that comes up is Please enter a username and password

<?php

session_start () ;

$username = $_POST ['username'] ;
$password = $_POST ['passowrd'] ;

if ($username&&$password) 
{

define ('DB_HOST' , 'localhost') ;
define ('DB_USER' , 'root')  or die ("Could not connect!") ;
define ('DB_PASSWORD', "")  or die ("Could not find DB!") ;
define ('DB_DATABASE', 'joke') ; 

}
else
   die ("Please enter a username and password") ;
$query = mysql_query ("SELECT * FROM Joke WHERE username = '$username'") ;
$numrow = mysql_num_rows ($query) ;

if ($numrows!=0)
{	
	//code to login

   While ($row= mysql_fetch_assoc($query))
   {
   		$dbusername = $row ['username'] ;
   		$dbusername = $row ['password'] ;
   }	

   //check if they match

   if ($username==$dbusername&&$password==$dbpassword)
   {
   		echo "You're inn! <a href=member.php> Click here to enter member page" ;
   		$_SESSION['username']=$dbusername ;
   	}
   		else
   			echo "incorrect password!" ;
}
else
	die("That user does'nt exist") ;
echo $numrows;

?>

Link to comment
Share on other sites

You have defined the host, user etc but you still need to connect to the database before you can execute any queries.

 

And you should not be creating new code using the mysql_xxxx functions, use mysqli_xxxx or PDO functions.

 

@KillerOz, the {} are advisable but not essential for a single statement

Link to comment
Share on other sites

Hey barand thank you for helping me
I am a college student and i want to do website production when im older. I learnt HTML at school but want to try and teach myself some PHP
You said i need to define the host, how do i go about doing that?
also i am useing 000webhost at the moment (not permanent) and i dont think they support mysqli

Link to comment
Share on other sites

 

 

You said i need to define the host, how do i go about doing that?

Go back and read Barand's post again.   :tease-03:

 

 

 

also i am useing 000webhost at the moment (not permanent) and i dont think they support mysqli

To find out of they do support mysqli run phpinfo. IMO it would be better to install the AMP stack locally on your computer. You can either install it manually or use packages such as XAMPP, WAMP or MAMP

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.