UCP problem
#1

I copy UCP from one tutorial from this forum,but isnt working very well..
UCP My

ERROR:
Quote:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\ucp\config.php:5 Stack trace: #0 C:\xampp\htdocs\ucp\login.php(3): include() #1 {main} thrown in C:\xampp\htdocs\ucp\config.php on line 5

Mysql DB:http://prntscr.com/d98z6z

Config.php
Quote:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$connect = mysql_connect($servername, $username, $password);
mysql_select_db("myserver") or die ("I can't find the database!"); //selecting database, change name to your database name!

function sanitize($string) //function for sanitize from xss and mysql and csrf... Thanks to XFlawless
{
$string = strip_tags($string);
$string = mysql_real_escape_string($string);
return $string;
}

?>

Login.php
Quote:

<?php

include("config.php"); //including our config.php where is connecting to mysql...
session_start(); //starting session for profile.php (Dunno how to explain better) look little down
error_reporting(0); //without this we will always get some stupid notice that variable isn't defined....

$submit = $_POST['submit']; //variable for submit button, in this variable we save button that player press in <input type='submit' name="submit" value='Login' />....
$username = sanitize($_POST['username']); //variable for username, in this variable we save text that user type in <input type="text" name="username"....
$password = sanitize($_POST['password']); //variable for password, in this variable we save text that user type in <input type="password" name="password"....

if($submit) //if he press submit button
{
if($username && $password) //if he type both of username and password not just one of them
{
$query = mysql_query("SELECT username, password FROM users WHERE username = '$username'"); //selecting user name and password, change it to your field names, chage users to your table name, $username means username that he type...
if(mysql_num_rows($query) == 1) //if user exists
{
while($row = mysql_fetch_assoc($query)) //loop thought table that we select in mysql_query
{
$dbusername = $row['username']; //setting dbusername as variable from table, change 'username' to your field!
$dbpassword = $row['password']; //setting dbpassword as variable from table, change 'password' to your field!
}
if($username == $dbusername && $password == $dbpassword) //if username is same as one from table and if password is the same as one from table...
{
$_SESSION['username'] = $dbusername; //setting session username to one from table, this is useful if you login, that restart your browser and than you go in url where is your profile.php... Anyway this is useful
echo header('location: profile.php'); //redirecting user to his profile page (profile.php)
}
else echo "Wrong password!"; //else if user type wrong password he will get this...
}
else echo "Username doesn't exist!"; //if username doesn't exist in table user will get this
}
else echo "Type name and password!"; //else if user doesn't type all fields he will get this...
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Basic UCP</title>
//here you can add your design (Remove this line)
<form action='login.php' method='POST'>
<input type="text" name="username" value='<?php echo $username?>'/>
<input type="password" name="password"/>
<input type='submit' name="submit" value='Login' />
</form>
</head>
</html>

Profile.php
Quote:

<?php

include("config.php"); //including our config.php
session_start(); //starting session
error_reporting(0);

if(isset($_SESSION['username'])) //if session is set, so if user is logged in...
{
$username = $_SESSION['username']; //setting variable username as one from session
$query = mysql_query("SELECT * FROM users WHERE username = '$username'"); //selecting all from table users where username is name that your is loged in
echo "Welcome ".$_SESSION['username']; //saying welcome to user!
while($row = mysql_fetch_assoc($query)) //looping thousgt table to get informations
{
$name = $row['username']; //selecting user name, change 'username' to your field name
$money = $row['money']; //selecting user money, change 'money' to your field name
$score = $row['score']; //selecting user score, change 'score' to your field name
$kills = $row['kills']; //selecting user kills, change 'kills' to your field name
$deaths = $row['deaths']; //selecting user deaths, change 'deaths' to your field name
}
echo "<br><br>Name: ".$name."<br> Money: ".$money."<br> Score: ".$score."<br> Kills: ".$kills."<br> Deaths: ".$deaths;
}
else header('location: login.php'); //if user isn't loged in it will redirect him on login.php

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Basic UCP</title>
</head>
</html>

Logout.php
Quote:

<?php

include("config.php"); //including our config.php
session_start(); //starting session
session_destroy(); //destroying it
header('location: login.php'); //redirecting user to login.php

?>

Reply
#2

The PHP "mysql" extension has since long been deprecated and was finally removed in PHP7. Use mysqli or PDO.
Reply
#3

Also, in your checks for username and password, this will return false as you've encrypted your password.

So you're trying to compare a plain text string to an encrypted one.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)