PHP脚本错误

时间:2016-01-30 22:02:52

标签: php mysql

我已经编写了下面的2个脚本来注册新用户并从SQL数据库中获取数据到Android Studio上的Java代码,但由于解析错误和参数不正确,我可能会出错。

有人可以帮忙吗?

提前谢谢你。

警告:mysqli_connect()期望参数5为long,第2行的/home/a1051468/public_html/register.php中给出了字符串

警告:mysqli_prepare()要求参数1为mysqli,在第9行/home/a1051468/public_html/register.php中给出为null

警告:mysqli_stmt_bind_param()要求参数1为mysqli_stmt,在第10行的/home/a1051468/public_html/register.php中给出为null

警告:mysqli_stmt_execute()要求参数1为mysqli_stmt,在第11行的/home/a1051468/public_html/register.php中给出为null

警告:mysqli_stmt_close()要求参数1为mysqli_stmt,在第13行的/home/a1051468/public_html/register.php中给出为null

警告:mysqli_close()期望参数1为mysqli,在第15行的/home/a1051468/public_html/register.php中给出null

<?php
$con=mysqli_connect("localhost","my_user","my_user","my_password","my_db");

$name = $_POST["name"];
$age = $_POST["age"];
$password = $_POST["password"];
$username = $_POST["username"];

$statement = mysqli_prepare($con, "INSERT INTO User (name, age, username, password) VALUES (?, ?, ?, ?) ");
mysqli_stmt_bind_param($statement, "siss", $name, $age, $username, $password);
mysqli_stmt_execute($statement);

mysqli_stmt_close($statement);

mysqli_close($con);

&GT;

解析错误:语法错误,第2行/home/a1051468/public_html/FetchUserData.php中的意外T_STRING

<?php
$con=mysqli_connect('localhost','my_user','my_user','my_password','my_db');

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

$statement = mysql_prepare($con, "SELECT * FROM User WHERE username = ? AND password = ?");

mysqli_stmt_bind_param($statement, "ss", $username, $password);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $userID, $name, $age, $username, $password);

$user = array();

while(mysqli_stmt_fetch($statment)){
    $user[name] = $name;
    $user[age] = $age;
    $user[username] = $username;
    $user[password] = $password;
}

echo json_encode($user);

    mysqli_stmt_close($statement);

mysqli_close($con);

&GT;

1 个答案:

答案 0 :(得分:0)

你在mysqli_connect中有两次用户名:mysqli_connect("localhost","my_user","my_user","my_password","my_db");应为mysqli_connect("localhost", "my_user", "my_password", "my_db");

同样在你的第二个脚本中,你在第7行有mysql_prepare而不是mysqli_prepare。