000webhost with mysql error: Parse error: syntax error, unexpected 'if' (T_IF) in /storage/ssd2/509/5475509/public_html/webhost.php on line 5? [closed]

0
  

Parse error: syntax error, unexpected 'if' (T_IF) in /storage/ssd2/509/5475509/public_html/webhost.php on line 5

 <?php 
 //conectar con el servidor
$conectar=mysql_connect('databases.000webhost.com','id5475509_julian_forus','')

  if (!$conectar){
     echo "No se pudo conectar con el servidor"
 }else{
     $base=mysql_select_db('id5475509_forus');
     if(!$base){
         echo"No se encontro la base de datos";
     }
 }
 //recuperar variables
 $tienda=$_POST['tienda'];
 $descripcion=$_POST['descripcion'];
 $documento=$_POST['documento'];

 //SQL
 $sql="INSERT INTO datos VALUES ('$tienda' ,
                                 '$descripcion' ,          
                                 '$documento')";
//ejecutar sql
$ejecutar=mysql_query($sql);

//verificar ejecucion
if(!$ejecutar){
    echo "Ups... ¡Hubo un error!";
}else{
    echo "Datos guardados correctamente<br><a href='index.html'>volver</a>";
}   
?>

Connection php code on line 5 tells me that it is the error.

    
asked by julian 10.05.2018 в 17:34
source

1 answer

2

Before the IF of line 5 you are missing ; after ) of line 3. And as another colleague has commented below, you also need the semicolon at the end on line 6

He is telling you that when he parses he finds an error, that an IF has been found that was not waiting, almost always, because right before there should be one; as is your case, or maybe we should close a bracket or previous brackets.

<?php 
 //conectar con el servidor
$conectar=mysql_connect('databases.000webhost.com','id5475509_julian_forus','');

  if (!$conectar){
     echo "No se pudo conectar con el servidor";
 }else{
     $base=mysql_select_db('id5475509_forus');
     if(!$base){
         echo"No se encontro la base de datos";
     }
 }
 //recuperar variables
 $tienda=$_POST['tienda'];
 $descripcion=$_POST['descripcion'];
 $documento=$_POST['documento'];

 //SQL
 $sql="INSERT INTO datos VALUES ('$tienda' ,
                                 '$descripcion' ,          
                                 '$documento')";
//ejecutar sql
$ejecutar=mysql_query($sql);

//verificar ejecucion
if(!$ejecutar){
    echo "Ups... ¡Hubo un error!";
}else{
    echo "Datos guardados correctamente<br><a href='index.html'>volver</a>";
}   
?>
    
answered by 10.05.2018 в 17:39