Parse error: syntax error, unexpected 'if' (T_IF) in /hipt/sign.php on line 15

Parse error: syntax error, unexpected 'if' (T_IF) in /hipt/sign.php on line 15

我得到

Parse error: syntax error, unexpected '$username' (T_VARIABLE) in /home/rainlikq/public_html/script/signupt.php on line 17 the username statement....

有人可以给我一个解决方案吗

我将其用于注册目的... 我正在尝试执行它...... 实际上我正在将 json 数据解析到 android 设备...

 <?php

$host="localhost";          //replace with database hostname 
$username="rainlikq_rahul";     //replace with database username 
$password="rahul1";             //replace with database password 
$db_name="rainlikq_rainforest";     //replace with database name

 $con=mysql_connect($host, $username, $password)or die("cannot connect"); 



mysql_select_db($db_name)or die("cannot select DB");

 if(isset($_POST['name'], $_POST['password'], $_POST['password2'], $_POST['username'], $_POST['mobile']))
{
 
$username   =   $_POST['username'];
$password   =   $_POST['password'];     
$password2  =   $_POST['password2'];        
$name       =   $_POST['name'];
$mobile     =   $_POST['mobile'];

$result = mysql_query("insert into user(user_email,user_password,name,mobile) values( '$username','$password','$name','$mobile')");
 

// array for JSON response
$response = array();

if ($result) {
        // successfully inserted into database
        $response["success"] = 1;
        $response["message"] = "Signed up successfully";
        // echoing JSON response
        echo json_encode($response);
    } else 
    {
        // failed to insert row
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";

        // echoing JSON response
        echo json_encode($response);
    }
}

else
     {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
    // echoing JSON response
    echo json_encode($response);
     }





?>

根据您最初发布的问题,未标记为编辑

参见:https://whosebug.com/revisions/28117175/1

您忘记关闭几个 isset() 电话:

if (isset($_POST['name']) && isset($_POST['password']) && isset($_POST['password2'] && isset($_POST['username'] && isset($_POST['mobile'])) {
                                                                                 //^ Here                      ^ And here

就用这个:

if (isset($_POST['name']) && isset($_POST['password']) && isset($_POST['password2']) && isset($_POST['username']) && isset($_POST['mobile'])) {             

此外,由于您使用了 AND 运算符,因此您可以将多个变量放入 isset() 调用中,如下所示:

if(isset($_POST['name'], $_POST['password'], $_POST['password2'], $_POST['username'], $_POST['mobile'])) {

有关 isset() 的更多信息,请参阅手册:http://php.net/manual/en/function.isset.php

引自那里:

If multiple parameters are supplied then isset() will return TRUE only if all of the parameters are set. Evaluation goes from left to right and stops as soon as an unset variable is encountered.

旁注:

1。您使用 $username 2 次,首先是在您的连接中,然后您在 if 语句中将其分配为新的(也许您会遇到麻烦)

2。你用mysql_*API,我推荐你用mysqli_* or PDO。因为:此扩展已从 PHP 5.5.0 开始弃用,不推荐用于编写新代码,因为它将在未来被删除。

3。您使用了运算符 <>,这完全没问题,但对于某些人来说这似乎有点奇怪,我会使用 != 和您可以在 SQL 中使用的另一个运算符声明

4。我还建议您在文件顶部添加错误报告(仅在暂存中):

<?php
    ini_set("display_errors", 1);
    error_reporting(E_ALL);
?>