gpt4 book ai didi

javascript - ExtJS/PHP/MySQL : Uncaught SyntaxError: Unexpected token ILLEGAL

转载 作者:行者123 更新时间:2023-11-29 22:06:13 25 4
gpt4 key购买 nike

我试图找出为什么下面的 $sql echo 语句在 JavaScript 中抛出此错误。是来自 $sql 赋值语句吗?为什么会这样呢?我只是浏览了一些用 PHP 编写的书籍示例。

Uncaught SyntaxError: Unexpected token ILLEGAL

<?php
session_start();
if (isset($_POST["exec"]) && $_POST["exec"] == "1") {
$url = "127.0.0.1";
$user = "root";
$pass = "root";
$db = "book1";

$message = "1";
echo "<script type='text/javascript'>alert('$message');</script>";

$link = mysql_connect($url, $user, $pass) or die("cannot connect.");
$sdb = mysql_select_db($db, $link) or die("faild select db");

$message = "2";
echo "<script type='text/javascript'>alert('$message');</script>";

$sql = implode("\n", array(
"SELECT",
" COUNT(id) as auth,",
" book1.users.email,",
" book1.users.firstname,",
" book1.users.lastname",
"FROM",
" book1.users",
"WHERE",
" book1.users.email = 'k'",
"AND",
" book1.users.passwd = SHA1(MD5('k'))",
"AND",
" book1.users.status = 1;"
));


echo "<script type='text/javascript'>alert('$sql');</script>";


$result = mysql_query($sql, $link) or die("faild query<hr/>SQL:" . $sql);
$row = mysql_fetch_assoc($result);
$auth = $row["auth"];
mysql_free_result($result);
mysql_close($link) or die("faild disconnect");
if ($auth == "1") {
$_SESSION["USERINFO"] = array(
"email" => $row["email"],
"firstname" => $row["firstname"],
"lastname" => $row["lastname"]
);
header("Location: ./index.php");
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<form action="login.php" method="post">
E-Mail:<input type="text" name="email" value=""/><br/>
Password:<input type=password" name="passwd" value="" /><br/>
<input type="submit" value="Login"/>
<input type="hidden" name="exec" value="1"/>
</form>
</body>
</html>

编辑:

这就是代码过去的样子,但在浏览器控制台窗口中抛出相同的错误。

$sql = implode("\n", array(
"SELECT",
" COUNT(id) as auth,",
" users.email,",
" users.firstname,",
" users.lastname",
"FROM",
" users",
"WHERE",
" users.email = '" . mysql_real_escape_string($_POST['email']) . "'",
"AND",
" users.passwd = SHA1(MD5('" . mysql_real_escape_string($_POST['passwd']) . "'))",
"AND",
" users.status = 1;"
));

最佳答案

看起来作者忘记了输入字段中 type 属性的值(“密码”)之前的引号。我可能是唯一一个使用 Packtpub.com 上出版的《Ext JS 数据驱动应用程序设计》一书的实际代码尝试过此示例的人。这让我感觉很特别。

我创建了一个名为“book1”的架构(PHP $db 变量 - MySQL 架构类似于数据库),并在代码中将数据库凭据更改为 root/root 以匹配我在 Windows 上安装的 MySQL 设置。然后我必须向“users”表中添加一个状态为 1 的用户才能正常工作。

也许我使用的版本(6.3)在MySQL上编写脚本是不同的,但创建表时语法也一直失败。我必须忽略除 CREATE 语句之外的所有行。我还排除了以“ENGINE”开头的代码。

第一章的原始代码:

SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0;

DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`status` tinyint(1) NOT NULL DEFAULT '1',
`email` varchar(255) NOT NULL,
`passwd` char(40) NOT NULL,
`lastname` varchar(20) NOT NULL,
`firstname` varchar(20) NOT NULL,
`modified` datetime DEFAULT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

SET FOREIGN_KEY_CHECKS = 1;

新代码:

CREATE TABLE `users` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`status` tinyint(1) NOT NULL DEFAULT '1',
`email` varchar(255) NOT NULL,
`passwd` char(40) NOT NULL,
`lastname` varchar(20) NOT NULL,
`firstname` varchar(20) NOT NULL,
`modified` datetime DEFAULT NULL,
`created` datetime NOT NULL,
PRIMARY KEY (`id`)
);

关于javascript - ExtJS/PHP/MySQL : Uncaught SyntaxError: Unexpected token ILLEGAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32132150/

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