代码看起来很好,但它会引发错误:
“解析错误:语法错误,第7行/home/u924861036/public_html/press.php中的意外T_STRING”
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$type = $_POST['type'];
$data = $_POST['data'];
mysql_connect(“localhost”, “user_name”, “pass”) or
die(“Could not connect: ” . mysql_error());
mysql_select_db(“db_name”);
第二行是第7行,但即使我删除它,错误也是一样的,所以第8行也有一些错误。
答案 0 :(得分:2)
我认为你使用了错误的“而不是”(注意它们是'斜体')
请试试这个:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$type = $_POST['type'];
$data = $_POST['data'];
mysql_connect("localhost", "user_name", "pass") or
die("Could not connect: " . mysql_error());
mysql_select_db("db_name");
?>
编辑:
确认,这会在我的系统上抛出无效的用户/传递:)
答案 1 :(得分:1)
使用双引号或单引号(“/”)代替奇怪的“符号
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$type = $_POST['type'];
$data = $_POST['data'];
mysql_connect("localhost", "user_name", "pass") or die("Could not connect: " . mysql_error());
mysql_select_db("db_name");
答案 2 :(得分:1)
你的双引号看起来很奇怪。
试试这个:
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$type = $_POST['type'];
$data = $_POST['data'];
mysql_connect("localhost", "user_name", "pass") or
die("Could not connect: " . mysql_error());
mysql_select_db("db_name");
请使用mysqli
或PDO
代替mysql_*
个功能。
答案 3 :(得分:1)
<?php
$ip = $_SERVER['REMOTE_ADDR'];
$type = $_POST['type'];
$data = $_POST['data'];
mysqli_connect("localhost", "user_name", "pass") or die("Could not connect: " . mysqli_error());
mysqli_select_db("db_name");
?>
只是为了确保:您知道您使用用户名'user_name'和密码'pass'连接到数据库'db_name'?修正了奇怪的引号。
答案 4 :(得分:-1)
替换: -
mysql_connect(“localhost”, “user_name”, “pass”) or
die(“Could not connect: ” . mysql_error());
mysql_select_db(“db_name”);
与
mysql_connect("localhost", "user_name", "pass") or
die("Could not connect: " . mysql_error());
mysql_select_db("db_name");