0

As a task my teacher has given me (highschool year 10) to create a login form using html and php as we have just started to learn PHP i have made progress and this is my first attempt. I will go into more secure options later.

<?PHP

//Create the connection…
//("where the database is", 'Database login' , 'database password' , "Database name")
$con=mysqli_connect("", 'root', 'root', "Social");

//Check our connection…
if (mysqli_connect_errno($con))
{
    echo " Sorry Mate";
}
$username = $_POST[username];
$password = $_POST[pawd];

$result = mysqli_query($con, "SELECT * FROM User_info");
$row = mysqli_fetch_array($result);
$value = $row['username'];
if($value == "$username")
{
    $result = mysqli_query($con, "SELECT * FROM User_info");
    $row = mysqli_fetch_array($result);
    $value = $row['password'];
    if($value == "$password")
        {
        $sql=("UPDATE user_check SET user = '1' ");
        $sql=("UPDATE user_check SET name = '$username' ");
        header( 'Location: feed.php' ) ;
        }
        else
        {
        header( 'Location: social.php' ) ;
        }
}
else
{
header( 'Location: social.php' ) ;
}

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
mysqli_close($con);
?>

Where it says

        $sql=("UPDATE user_check SET user = '1' ");
    $sql=("UPDATE user_check SET name = '$username' ");

The first one will work and update the database to 1 however the second one doesn't i have checked the name of the column changed the name of the variable $sql and $username and it still won't work is there any suggestions? Thankyou in advance :D

4

2 回答 2

0

您首先与结果$_POST['username']中的username列进行比较,然后尝试更新name数据库中的列。我的猜测是:

$sql = ("UPDATE user_check SET name = '$username' ");

应该:

$sql = ("UPDATE user_check SET username = '$username' ");
于 2013-08-11T06:05:25.190 回答
0

这看起来很奇怪:

    $sql=("UPDATE user_check SET user = '1' ");
    $sql=("UPDATE user_check SET name = '$username' ");

第二行将覆盖前一个第一行中存储的值。

试试掷骰子($sql)

在你调用 SQL 的那一行之前,看看你认为你正在运行的是否就是你正在运行的。

于 2013-08-11T06:11:52.917 回答