0

I was trying to make a form to insert data into a mysql database and I keep getting the same error:

Parse error: syntax error, unexpected T_STRING in /home/u272231605/public_html/add_reg.php3 on line 20

Here's the code where the error is showed:

<html>
<body>

<?php
if (isset($_POST['Nombre Monstruo']) && !empty($_POST['Nombre Monstruo'])&&
    isset($_POST['Ataque']) && !empty($_POST['Ataque'])&&
    isset($_POST['Defensa']) && !empty($_POST['Defensa'])&&
    isset($_POST['Tipo']) && !empty($_POST['Tipo'])&&
    isset($_POST['Nivel']) && !empty($_POST['Nivel'])&&
    isset($_POST['Efecto']) && !empty($_POST['Efecto'])){
    $nombremonstruo = $_POST['Nombre Monstruo'];
    $ataque = $_POST['Ataque'];
    $defensa = $_POST['Defensa'];
    $tipo = $_POST['Tipo'];
    $nivel = $_POST['Nivel'];
    $efecto = $_POST['Efecto'];
    $db = u272231605_data;
    $host = mysql.hostinger.es;
    $user = u272231605_data;
    $password = 4Ym8ix2A;
    $con = mysql_connect($host,$user,$password)or die('No se ha podido conectar con      la base de datos');
    mysql_select_db($db,$con) or die('No se pudo conectar con la base de datos');
    mysql_query("INSERT INTO (Nombre del monstruo,Ataque,Defensa,Tipo,Nivel,Efecto" values('$nombremonstruo','$ataque','$defensa','$tipo','$nivel','$efecto')");
    echo "Guardado correctamente"
    echo "<a href=index.php"> Registrar otro monstruo </a>;
}
    else
    {
        echo "Han de introducirse todos los datos para que el registro de la   carta se complete.";
    } 

?>
</body>
</html>

Thanks in advance for the help provided :)

1
  • Might be an idea NOT to post your db details (including password) so publicly Commented Jul 26, 2013 at 20:18

6 Answers 6

2

Your problem is here:

$db = u272231605_data;

and on other places. You should put double quotes around them:

$db = "u272231605_data";
Sign up to request clarification or add additional context in comments.

Comments

0

You've forgotten quotes in multiple places:

$db = u272231605_data;
$host = mysql.hostinger.es;
$user = u272231605_data;
$password = 4Ym8iJ2A;

Each of those values should be quoted. As they stand now, they're treated by PHP as undefined constants. But the last one (4Ym8iJ2A) is the cause of the error, because constants cannot start with numbers.

They should probably be:

$db = 'u272231605_data';
$host = 'mysql.hostinger.es';
$user = 'u272231605_data';
$password = '4Ym8iJ2A';

Comments

0

As well as the missing quotes for variables, there are multiple issues with these 4 lines of codes. Please use a smart editor to highlight syntax and etc. Following lines are updated:

mysql_select_db($db,$con) or die('No se pudo conectar con la base de datos');
mysql_query("INSERT INTO (Nombre del monstruo,Ataque,Defensa,Tipo,Nivel,Efecto) values('$nombremonstruo','$ataque','$defensa','$tipo','$nivel','$efecto')");
echo "Guardado correctamente";
echo "<a href='index.php'> Registrar otro monstruo </a>";

Comments

0

you need to wrap your variables in single quotes:

$db = 'u272231605_data';
$host = 'mysql.hostinger.es';
$user = 'u272231605_data';

Comments

0
$password = "4Ym8iJ2A";

The value needs single or double quotes.

Comments

0

You are missing a semi-colon on this line:

echo "Guardado correctamente"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.