-3

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:

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

$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);
Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
user3815016
  • 1
  • 1
  • 2
  • 1
    Check [this](http://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) out. The very best bookmark for beginners ;) – giorgio Feb 26 '16 at 08:34

2 Answers2

0

mysql is deprecated you should use mysqli or 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

you should write

mysql_select_db($db_name);

Just after mysql_connect

urfusion
  • 5,528
  • 5
  • 50
  • 87
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","");

to $db_connection = mysql_connect($db_host, $db_user,$db_password);,

this $resultado=mysql_query("SELECT * FROM ".$datos." WHERE Email = '".$Email."'", $db_connection);

to $resultado=mysql_query("SELECT * FROM ".$db_table_name." WHERE Email = '".$Email."'", $db_connection); AND this

`mysql_select_db($prueba, $db_connection);`

to mysql_select_db($db_name, $db_connection);

naseeba c
  • 1,040
  • 2
  • 14
  • 30
  • Always try to point out the mistake and then provide the solution. Not like writing the whole script. So better to guide him/her about the mistake he/she done. – Maha Dev Feb 26 '16 at 08:17
  • @naseebac :Insert query is wrong and has syntax error. Select query should be:- $resultado=mysql_query("SELECT * FROM $db_table_name WHERE Email = '$Email'"); – Ravi Hirani Feb 26 '16 at 09:19