我的PHP代码中出现了一些语法错误,我无法解决

时间:2018-03-14 09:09:08

标签: php mysql wampserver

我的PHP代码中出现了一些语法错误,我无法解决。 请看看这个并帮我解决这个问题。 Here Is The Screenshot

我附上了第14行的错误屏幕截图。

<?php
    $link = mysqli_connect('localhost','root','','satyam');
    if(isset($_POST['name']))
    {
        $name = $_POST['name'];
        $sql = "SELECT * FROM students WHERE name='".$name."'";
        $sql_run = mysqli_query($link,$sql);
        if($row=mysqli_fetch_array($sql_run))
        {
            $name = $row["name"];
            $roll = $row["roll"];
            $branch = $row["branch"];
            $address = $row["address"];
            echo 'Name: '.$name.' Roll: '.$roll.' Branch: '.$branch.' Address: '.$address';
        } else {
            echo "No Record Found";
        }
    }
?>

5 个答案:

答案 0 :(得分:1)

您添加了额外不必要的单引号(')以下行的结尾

echo 'Name: ' . $name . ' Roll: ' . $roll . ' Branch: ' . $branch . ' Address: ' . $address;

此代码工作正常。

$link = mysqli_connect('localhost','root','','satyam');
if(isset($_POST['name'])) {
    $name    = $_POST['name'];
    $sql     = "SELECT * FROM students WHERE name='" . $name."'";
    $sql_run = mysqli_query($link,$sql);
    if($row = mysqli_fetch_array($sql_run)) {
        $name    = $row["name"];
        $roll    = $row["roll"];
        $branch  = $row["branch"];
        $address = $row["address"];
        echo 'Name: ' . $name . ' Roll: ' . $roll . ' Branch: ' . $branch . ' Address: ' . $address;
    } else {
        echo "No Record Found";
    }
}

答案 1 :(得分:0)

在结尾处有一个额外的'

echo 'Name: '.$name.' Roll: '.$roll.' Branch: '.$branch.' Address: '.$address';
$address

之后

答案 2 :(得分:0)

请检查:

$ echo '2011-03-02' | ssed -Rn 's/\d{4}-\d{2}-\d{2}/2018-03-14/gp'
2018-03-14

你添加了额外的&#39;在这一行:

<?php
$link = mysqli_connect('localhost','root','','satyam');
if(isset($_POST['name']))
{
    $name = $_POST['name'];
    $sql = "SELECT * FROM students WHERE name='".$name."'";
    $sql_run = mysqli_query($link,$sql);
    if($row=mysqli_fetch_array($sql_run))
    {
        $name = $row["name"];
        $roll = $row["roll"];
        $branch = $row["branch"];
        $address = $row["address"];
        echo 'Name: '.$name.' Roll: '.$roll.' Branch: '.$branch.' Address: '.$address;
    } else {
        echo "No Record Found";
    }
}
?>

答案 3 :(得分:0)

这一行:

echo 'Name: '.$name.' Roll: '.$roll.' Branch: '.$branch.' Address: '.$address;

应该是:

echo 'Name: '.$name.' Roll: '.$roll.' Branch: '.$branch.' Address: '.$address';

答案 4 :(得分:0)

删除第14行末尾的引号(')(分号旁边的引号)。