Jump to content

Alienn

New Members
  • Posts

    4
  • Joined

  • Last visited

Alienn's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Yea its working now. Thanks
  2. I fixed my problem it was because of this line: mysql_select_db("$db_name") or die ("Can't select database"); I deleted this line and made one line like this: $db = mysqli_connect($host, $username, $password, "portfolio") or die ("Can't connect"); Its connecting now and its working with my database. Only getting this error now: Notice: Undefined index: username in C:\xampp\htdocs\IMP-2\Portfolio\Login.php on line 13 Notice: Undefined index: pwd in C:\xampp\htdocs\IMP-2\Portfolio\Login.php on line 14 Wrong name or Password
  3. Well i am not really learning object orientated at the moment. I changed my code, but it is still not working. Code: <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="portfolio"; // Database name $tbl_name="users"; // Table name mysqli_connect("$host", "$username", "", "$password") or die ("Can't connect"); mysql_select_db("$db_name") or die ("Can't select database"); $myusername=$_POST['username']; $mypassword=$_POST['pwd']; $results = mysqli_query("portfolio", "SELECT * FROM users WHERE username='$myusername' and password='$mypassword'" ); $count = mysqli_num_rows($results); if($count==1){ session_start(); $_SESSION['username'] = $myusername; $_SESSION['pwd'] = $mypassword; header("location:Home.html"); } else { echo "Wrong name or Password"; } ?> <!doctype html> <html> <head> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="css.css"/> <title>Login</title> </head> <body> <div class ="wrapper"> <nav id="nav"> <ul> <li> <a href="Home.html" >Home </a> </li> <li> <a href="OverMij.html" >Over mij </a> </li> <li> <a href="Overzicht.html" >Project overzicht </a> </li> <li> <a href="Voegtoe.html">Project invoer</a> </li> <li> <a href="Details.html" >Project details </a> </li> <li> <a href="Contact.html" >Contact </a> </li> </ul> </nav> <div class ="title"> Login </div> <div id="add-content"> <form method="post" action="login.php" id="form-add"> <p><label>Username:</label> <input type="text" id="Username" name="username" autofocus/></p> <p><label>Password:</label> <input type="password" id="Password" name="pwd"/> </p> <p class="submit"><input type="submit" value="Login" name="submit" /></p> </form> </div> </div> </body> </html>
  4. Hello, I am trying to create a login system, but my code isn't doing anything. (Not even showing a error message) I guess my code can't connect to my database and its something with my mysqli statements. Hope someone can help a php beginner. My code: <?php $host="localhost"; $username=""; $password=""; $db_name="portfolio"; $tbl_name="users"; mysqli_connect("$host", "$username", "$password") or die ("Can't connect"); mysql_select_db("$db_name") or die ("Can't select database"); $myusername=$_POST['username']; $mypassword=$_POST['pwd']; $sql=("SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"); $count = mysqli_num_rows($sql); if($count==1){ session_start(); $_SESSION['username'] = $myusername; $_SESSION['pwd'] = $mypassword; header("location:Home.html"); } else { echo "Wrong name or Password"; } ?> <!doctype html> <html> <head> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="css.css"/> <title>Login</title> </head> <body> <div class ="wrapper"> <nav id="nav"> <ul> <li> <a href="Home.html" >Home </a> </li> <li> <a href="OverMij.html" >Over mij </a> </li> <li> <a href="Overzicht.html" >Project overzicht </a> </li> <li> <a href="Voegtoe.html">Project invoer</a> </li> <li> <a href="Details.html" >Project details </a> </li> <li> <a href="Contact.html" >Contact </a> </li> </ul> </nav> <div class ="title"> Login </div> <div id="add-content"> <form method="post" action="login.php" id="form-add"> <p><label>Username:</label> <input type="text" id="Username" name="username" autofocus/></p> <p><label>Password:</label> <input type="password" id="Password" name="pwd"/> </p> <p class="submit"><input type="submit" value="Login" name="submit" /></p> </form> </div> </div> </body> </html>
×
×
  • 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.