当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - Error's With Signup & Login PHP with Hostinger

问题描述:

So I have been Building A Forum With A Friend & He Has Challenged Me To Do A Lot Of The Server Side Stuff As He Tries Designing & I receive a lot of these error's

DISCLAIMER: I KNOW ALOT OF THIS HAS BEEN POSTED BUT I FIND IT HARD TO UNDERSTAND FOR ME.

DISCLAIMER: I AM INTERMEDIATE SO I AM NOT EXPERT AT PHP AND HAVE DEBUGGED FOR HOURS ON THIS.

Here is my login.php

<?php

//This page let log in

include('config.php');

if(isset($_SESSION['username']))

{

unset($_SESSION['username'], $_SESSION['userid']);

setcookie('username', '', time()-100);

setcookie('password', '', time()-100);

?>

<!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" />

<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />

<title>Login</title>

</head>

<body>

<div class="header">

<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Forum" /></a>

</div>

<div class="message">You have successfully been logged out.<br />

<a href="<?php echo $url_home; ?>">Home</a></div>

<?php

}

else

{

$ousername = '';

if(isset($_POST['username'], $_POST['password']))

{

if(get_magic_quotes_gpc())

{

$ousername = stripslashes($_POST['username']);

$username = mysql_real_escape_string(stripslashes($_POST['username']));

$password = stripslashes($_POST['password']);

}

else

{

$username = mysql_real_escape_string($_POST['username']);

$password = $_POST['password'];

}

$req = mysql_query('select password,id from users where username="'.$username.'"');

$dn = mysql_fetch_array($req);

if($dn['password']==sha1($password) and mysql_num_rows($req)>0)

{

$form = false;

$_SESSION['username'] = $_POST['username'];

$_SESSION['userid'] = $dn['id'];

if(isset($_POST['memorize']) and $_POST['memorize']=='yes')

{

$one_year = time()+(60*60*24*365);

setcookie('username', $_POST['username'], $one_year);

setcookie('password', sha1($password), $one_year);

}

?>

<!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" />

<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />

<title>Login</title>

</head>

<body>

<div class="header">

<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Forum" /></a>

</div>

<div class="message">You have successfully been logged.<br />

<a href="<?php echo $url_home; ?>">Home Page</a></div>

<?php

}

else

{

$form = true;

$message = 'The username or password you entered are not good.';

}

}

else

{

$form = true;

}

if($form)

{

?>

<!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" />

<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />

<title>Login</title>

</head>

<body>

<div class="header">

<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Forum" /></a>

</div>

<?php

if(isset($message))

{

echo '<div class="message">'.$message.'</div>';

}

?>

<div class="content">

<?php

$nb_new_pm = mysql_fetch_array(mysql_query('select count(*) as nb_new_pm from pm where ((user1="'.$_SESSION['userid'].'" and user1read="no") or (user2="'.$_SESSION['userid'].'" and user2read="no")) and id2="1"'));

$nb_new_pm = $nb_new_pm['nb_new_pm'];

?>

<div class="box">

<div class="box_left">

<a href="<?php echo $url_home; ?>">Forum Index</a> &gt; Login

</div>

<div class="box_right">

<a href="list_pm.php">Your messages(<?php echo $nb_new_pm; ?>)</a> - <a href="profile.php?id=<?php echo $_SESSION['userid']; ?>"><?php echo htmlentities($_SESSION['username'], ENT_QUOTES, 'UTF-8'); ?></a> (<a href="login.php">Logout</a>)

</div>

<div class="clean"></div>

</div>

<form action="login.php" method="post">

Please, type your IDs to log:<br />

<div class="login">

<label for="username">Username</label><input type="text" name="username" id="username" value="<?php echo htmlentities($ousername, ENT_QUOTES, 'UTF-8'); ?>" /><br />

<label for="password">Password</label><input type="password" name="password" id="password" /><br />

<label for="memorize">Remember</label><input type="checkbox" name="memorize" id="memorize" value="yes" /><br />

<input type="submit" value="Login" />

</div>

</form>

</div>

<?php

}

}

?>

<div class="foot"><a href="http://www.anmolb.esy.es">Developers Site</a> - Developed By LivingLife_</div>

</body>

</html>

Here are the error's I receive with the login page.

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/config.php on line 9

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/config.php on line 9

Deprecated: mysql_select_db(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/config.php on line 10

Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/config.php on line 10

Warning: mysql_select_db(): A link to the server could not be established in /home/u134164949/public_html/forum/config.php on line 10

Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/login.php on line 38

Warning: mysql_real_escape_string(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/login.php on line 38

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/u134164949/public_html/forum/login.php on line 38

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/login.php on line 41

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/login.php on line 41

Warning: mysql_query(): A link to the server could not be established in /home/u134164949/public_html/forum/login.php on line 41

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/u134164949/public_html/forum/login.php on line 42

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/login.php on line 102

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/login.php on line 102

Warning: mysql_query(): A link to the server could not be established in /home/u134164949/public_html/forum/login.php on line 102

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/u134164949/public_html/forum/login.php on line 102

Here is the signup.php code

<?php

//This page let users sign up

include('config.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" />

<link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" />

<title>Sign Up</title>

</head>

<body>

<div class="header">

<a href="<?php echo $url_home; ?>"><img src="<?php echo $design; ?>/images/logo.png" alt="Espace Membre" /></a>

</div>

<?php

if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['avatar']) and $_POST['username']!='')

{

if(get_magic_quotes_gpc())

{

$_POST['username'] = stripslashes($_POST['username']);

$_POST['password'] = stripslashes($_POST['password']);

$_POST['passverif'] = stripslashes($_POST['passverif']);

$_POST['email'] = stripslashes($_POST['email']);

$_POST['avatar'] = stripslashes($_POST['avatar']);

}

if($_POST['password']==$_POST['passverif'])

{

if(strlen($_POST['password'])>=6)

{

if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))

{

$username = mysql_real_escape_string($_POST['username']);

$password = mysql_real_escape_string(sha1($_POST['password']));

$email = mysql_real_escape_string($_POST['email']);

$avatar = mysql_real_escape_string($_POST['avatar']);

$dn = mysql_num_rows(mysql_query('select id from users where username="'.$username.'"'));

if($dn==0)

{

$dn2 = mysql_num_rows(mysql_query('select id from users'));

$id = $dn2+1;

if(mysql_query('insert into users(id, username, password, email, avatar, signup_date) values ('.$id.', "'.$username.'", "'.$password.'", "'.$email.'", "'.$avatar.'", "'.time().'")'))

{

$form = false;

?>

<div class="message">You have successfully been signed up. You can now log in.<br />

<a href="login.php">Log in</a></div>

<?php

}

else

{

$form = true;

$message = 'An error occurred while signing you up.';

}

}

else

{

$form = true;

$message = 'Another user already use this username.';

}

}

else

{

$form = true;

$message = 'The email you typed is not valid.';

}

}

else

{

$form = true;

$message = 'Your password must have a minimum of 6 characters.';

}

}

else

{

$form = true;

$message = 'The passwords you entered are not identical.';

}

}

else

{

$form = true;

}

if($form)

{

if(isset($message))

{

echo '<div class="message">'.$message.'</div>';

}

?>

<div class="content">

<div class="box">

<div class="box_left">

<a href="<?php echo $url_home; ?>">Forum Index</a> &gt; Sign Up

</div>

<div class="box_right">

<a href="signup.php">Sign Up</a> - <a href="login.php">Login</a>

</div>

<div class="clean"></div>

</div>

<form action="signup.php" method="post">

Please fill this form to sign up:<br />

<div class="center">

<label for="username">Username</label><input type="text" name="username" value="<?php if(isset($_POST['username'])){echo htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');} ?>" /><br />

<label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" /><br />

<label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" /><br />

<label for="email">Email</label><input type="text" name="email" value="<?php if(isset($_POST['email'])){echo htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');} ?>" /><br />

<label for="avatar">Avatar<span class="small">(optional)</span></label><input type="text" name="avatar" value="<?php if(isset($_POST['avatar'])){echo htmlentities($_POST['avatar'], ENT_QUOTES, 'UTF-8');} ?>" /><br />

<input type="submit" value="Sign Up" />

</div>

</form>

</div>

<?php

}

?>

<div class="foot"><a href="http://www.anmolb.esy.es">Developers Site</a> - Developed By LivingLife_</div>

</body>

</html>

Here are the error that i have with this code

 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/config.php on line 9

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/config.php on line 9

Deprecated: mysql_select_db(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/config.php on line 10

Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/config.php on line 10

Warning: mysql_select_db(): A link to the server could not be established in /home/u134164949/public_html/forum/config.php on line 10

Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/signup.php on line 33

Warning: mysql_real_escape_string(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/signup.php on line 33

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/u134164949/public_html/forum/signup.php on line 33

Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/signup.php on line 34

Warning: mysql_real_escape_string(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/signup.php on line 34

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/u134164949/public_html/forum/signup.php on line 34

Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/signup.php on line 35

Warning: mysql_real_escape_string(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/signup.php on line 35

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/u134164949/public_html/forum/signup.php on line 35

Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/signup.php on line 36

Warning: mysql_real_escape_string(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/signup.php on line 36

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/u134164949/public_html/forum/signup.php on line 36

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/signup.php on line 37

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/signup.php on line 37

Warning: mysql_query(): A link to the server could not be established in /home/u134164949/public_html/forum/signup.php on line 37

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/u134164949/public_html/forum/signup.php on line 37

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/signup.php on line 40

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/signup.php on line 40

Warning: mysql_query(): A link to the server could not be established in /home/u134164949/public_html/forum/signup.php on line 40

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/u134164949/public_html/forum/signup.php on line 40

Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/u134164949/public_html/forum/signup.php on line 42

Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory") in /home/u134164949/public_html/forum/signup.php on line 42

Warning: mysql_query(): A link to the server could not be established in /home/u134164949/public_html/forum/signup.php on line 42

Thank you for any other information, This is kinda a first experience for me :)

网友答案:

try putting mysqli_connect... replace all instances of mysql to mysqli.. you're using procedural approach... and mysqli offers that approach....

mysqli is the improve version of mysql.. don't use mysql anymore.

分享给朋友:
您可能感兴趣的文章:
随机阅读: