This question already has an answer here:
这个问题已经有了答案:
- PHP parse/syntax errors; and how to solve them? 13 answers
- PHP解析/语法错误;如何解决它们呢?13个答案
I am a beginner in PHP and I can not resolve this error, thank you for your answers.It is a simple connection to a database in MySQL with columns:
我是一个PHP初学者,我无法解决这个错误,谢谢您的回答。这是一个简单的连接到MySQL数据库的列:
Name
Last Name
Email
Parse error:
解析错误:
syntax error, unexpected '""' (T_CONSTANT_ENCAPSED_STRING), expecting variable (T_VARIABLE) or '{' or '$' in C:\xampp\htdocs\Suscribe\registro.php on line 7
语法错误、意外的“”(T_CONSTANT_ENCAPSED_STRING)、预期变量(T_VARIABLE)或“{”或“$”在C:\xampp\htdoc \Suscribe\registro。php在第7行
$db_host="localhost";
$db_user="root";
$db_password="";
$db_name="prueba";
$db_table_name="datos";
$db_connection = mysql_connect("$localhost", "$root","");
if (!$db_connection) {
die('No se ha podido conectar a la base de datos');
}
$Nombre = utf8_decode($_POST['nombre']);
$Apellido = utf8_decode($_POST['apellido']);
$Email = utf8_decode($_POST['email']);
$resultado=mysql_query("SELECT * FROM ".$datos." WHERE Email = '".$Email."'", $db_connection);
if (mysql_num_rows($resultado)>0){
header('Location: Fail.html');
}else{
$insert_value = 'INSERT INTO `' . $prueba. '`.`'.$datos.'` (`nombre` , `apellido` , `email`) VALUES
("' . $Nombre . '", "' . $Apellido . '", "' . $Email . '")';
mysql_select_db($prueba, $db_connection);
$retry_value = mysql_query($insert_value, $db_connection);
if (!$retry_value){
die('Error: ' . mysql_error());
}
header('Location: Success.html');
}
mysql_close($db_connection);
2 个解决方案
#1
0
mysql
is deprecated you should use mysqli
or pdo
不赞成使用mysql或pdo
Change
改变
$db_connection = mysql_connect("$localhost", "$root","");
To
来
$db_connection = mysql_connect($localhost, $root,"");
And one more thing you didn't connect DB
too
还有一件事你没有连接DB
you should write
你应该写
mysql_select_db($db_name);
Just after mysql_connect
后首先
#2
0
try this
试试这个
<?php
$db_host="localhost";
$db_user="root";
$db_password="";
$db_name="prueba";
$db_table_name="datos";
$db_connection = mysql_connect($db_host, $db_user,$db_password);
if (!$db_connection) {
die('No se ha podido conectar a la base de datos');
}
$Nombre = utf8_decode($_POST['nombre']);
$Apellido = utf8_decode($_POST['apellido']);
$Email = utf8_decode($_POST['email']);
$resultado=mysql_query("SELECT * FROM ".$db_table_name." WHERE Email = '".$Email."'", $db_connection);
if (mysql_num_rows($resultado)>0)
{
header('Location: Fail.html');
} else {
$insert_value = 'INSERT INTO `' . $prueba. '`.`'.$datos.'` (`nombre` , `apellido` , `email`) VALUES
("' . $Nombre . '", "' . $Apellido . '", "' . $Email . '")';
mysql_select_db($db_name, $db_connection);
$retry_value = mysql_query($insert_value, $db_connection);
if (!$retry_value) {
die('Error: ' . mysql_error());
}
header('Location: Success.html');
}
mysql_close($db_connection);
i'm change this $db_connection = mysql_connect("$localhost", "$root","");
我将这个$db_connection = mysql_connect(“$localhost”、“$root”、“”);
to $db_connection = mysql_connect($db_host, $db_user,$db_password);
,
$db_connection = mysql_connect($db_host, $db_user,$db_password);
this $resultado=mysql_query("SELECT * FROM ".$datos." WHERE Email = '".$Email."'", $db_connection);
$resultado=mysql_query("SELECT * FROM ".$datos ")。电子邮件= '”。美元电子邮件。“”,db_connection美元);
to $resultado=mysql_query("SELECT * FROM ".$db_table_name." WHERE Email = '".$Email."'", $db_connection);
AND this
到$resultado=mysql_query("SELECT * FROM ".$db_table_name。"电子邮件= '”。美元电子邮件。“”,db_connection美元);这
`mysql_select_db($prueba, $db_connection);`
to mysql_select_db($db_name, $db_connection);
mysql_select_db(db_name,db_connection美元);
#1
0
mysql
is deprecated you should use mysqli
or pdo
不赞成使用mysql或pdo
Change
改变
$db_connection = mysql_connect("$localhost", "$root","");
To
来
$db_connection = mysql_connect($localhost, $root,"");
And one more thing you didn't connect DB
too
还有一件事你没有连接DB
you should write
你应该写
mysql_select_db($db_name);
Just after mysql_connect
后首先
#2
0
try this
试试这个
<?php
$db_host="localhost";
$db_user="root";
$db_password="";
$db_name="prueba";
$db_table_name="datos";
$db_connection = mysql_connect($db_host, $db_user,$db_password);
if (!$db_connection) {
die('No se ha podido conectar a la base de datos');
}
$Nombre = utf8_decode($_POST['nombre']);
$Apellido = utf8_decode($_POST['apellido']);
$Email = utf8_decode($_POST['email']);
$resultado=mysql_query("SELECT * FROM ".$db_table_name." WHERE Email = '".$Email."'", $db_connection);
if (mysql_num_rows($resultado)>0)
{
header('Location: Fail.html');
} else {
$insert_value = 'INSERT INTO `' . $prueba. '`.`'.$datos.'` (`nombre` , `apellido` , `email`) VALUES
("' . $Nombre . '", "' . $Apellido . '", "' . $Email . '")';
mysql_select_db($db_name, $db_connection);
$retry_value = mysql_query($insert_value, $db_connection);
if (!$retry_value) {
die('Error: ' . mysql_error());
}
header('Location: Success.html');
}
mysql_close($db_connection);
i'm change this $db_connection = mysql_connect("$localhost", "$root","");
我将这个$db_connection = mysql_connect(“$localhost”、“$root”、“”);
to $db_connection = mysql_connect($db_host, $db_user,$db_password);
,
$db_connection = mysql_connect($db_host, $db_user,$db_password);
this $resultado=mysql_query("SELECT * FROM ".$datos." WHERE Email = '".$Email."'", $db_connection);
$resultado=mysql_query("SELECT * FROM ".$datos ")。电子邮件= '”。美元电子邮件。“”,db_connection美元);
to $resultado=mysql_query("SELECT * FROM ".$db_table_name." WHERE Email = '".$Email."'", $db_connection);
AND this
到$resultado=mysql_query("SELECT * FROM ".$db_table_name。"电子邮件= '”。美元电子邮件。“”,db_connection美元);这
`mysql_select_db($prueba, $db_connection);`
to mysql_select_db($db_name, $db_connection);
mysql_select_db(db_name,db_connection美元);