开发者

php /mysql coding not working

开发者 https://www.devze.com 2023-01-23 09:46 出处:网络
i seem to be having an error on this coding any help would be appreciated Parse error: parse error in C:\\wamp\\www\\espn.com\\login.php on line 19

i seem to be having an error on this coding any help would be appreciated

Parse error: parse error in C:\wamp\www\espn.com\login.php on line 19

<?php

//Database Information

$dbhost = "localhost";
$dbname = "users";
$dbuser = "root";
$dbpass = "*****";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

session_start();
$username = $_POST[‘username’];
$password = md5($_POST[‘password’]);

$query = “select * FROM users where 'username'=$username and 'password'= $passwo开发者_StackOverflowrd " ;

$result = mysql_query($query);

if (mysql_num_rows($result) != 1) {
$error = “Bad Login”;
    include “login.html”;

} else {
    $_SESSION[‘username’] = “$username”;
    include “memberspage.php”;
}

?>


looks like you have a fancy quote on your query, so it's not a proper string

“ vs "


You are using odd quotes: instead of the proper ".

Probably happened while copying code from a web site.

The only valid string-delimiting quotes in PHP (and most other programming languages) are ' and ".


I want to tell you create a separate file/page for database connection. Suppose your connection file name is db_connection.php. Where you want to check only db_connection.php page will include. It saves your codding.

db_connection.php

<?php

//Database Information

$dbhost = "localhost";
$dbname = "users";
$dbuser = "root";
$dbpass = "*****";

//Connect to database

mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());

session_start();
?>

Now in your login page you include db_connection.php

loginpage:

<?php
include_once('db_connection.php');

if(isset($_POST['submit']) //submit is form button name
{
  $username = $_POST[‘username’];
  $password = md5($_POST[‘password’]);

   $query = mysql_query(“select * FROM users where 'username'=$username and 'password'= $password ") ;

if (mysql_num_rows($result)>0) {

    $_SESSION[‘username’] = “$username”;
    header(location:memberspage.php);

} else {

     $error = “Bad Login”;
    header(location:memberspage.php);

}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号