gpt4 book ai didi

PHP 脚本错误

转载 作者:行者123 更新时间:2023-11-29 21:33:02 24 4
gpt4 key购买 nike

我编写了下面的 2 个脚本,用于注册新用户并将数据从 SQL 数据库获取到 Android studio 上的 Java 代码,但是由于解析错误和不正确的参数,我在这两个脚本上都可能出现错误。

有人可以帮忙吗?

提前谢谢您。

警告:mysqli_connect() 期望参数 5 很长,字符串在/home/a1051468/public_html/register.php 第 2 行给出

警告: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);

?>

解析错误:语法错误,第 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);

?>

最佳答案

您在 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。

关于PHP 脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35107699/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com