0

While i was working in my PC (local) everything works fine but when i uploaded my project to a server all the querys doesn´t work and i don´t know why.

I use querys like this one:

header('Content-Type: text/html; charset=UTF-8');
include_once '../includes/db_connect.php';
include_once '../includes/psl-config.php';
$mysqli->query("SET NAMES 'utf8'");

$fechaRecibo = mysql_real_escape_string( $_POST["fechaRecibo"] );
$nombre = mysql_real_escape_string( $_POST["nombre"] );
$recibiDe = mysql_real_escape_string( $_POST["recibiDe"] );
$monto = mysql_real_escape_string( $_POST["monto"] );
$comentario = mysql_real_escape_string( $_POST["comentario"] );
$idUser = mysql_real_escape_string( $_POST['idUser'] );

$sql = "INSERT INTO vales (fecha, nombre, recibiDe, monto, comentario, created_by) values ('$fechaRecibo','$nombre','$recibiDe','$monto','$comentario','$idUser')";
$res = $mysqli->query($sql);
$lastID = mysqli_insert_id($mysqli);
if ($res){
     echo "Éxito"
} 
else{
    printf("Error message: %s\n", $mysqli->error);
}

And it shows "Error message" on the screen, but it does not say which one is the error. It seems that $mysqli->error doesn´t work. What i don´t understand why working in a local way it works and in a server it does't.

  • Don't mix functions from different libraries i.e. if you are using mysqli don't use mysql_real_escape_string. And there's a mix of object oriented and procedure oriented calls. That may work, but it looks really strange. With mysqli, you can use prepared statements with bind placeholders. – spencer7593 Apr 28 '16 at 23:36
  • You are completly right, I change mysql_real_escape_string to $mysqli->real_escape_string and it works. What do u mean with "mix of object oriented and procedure oriented calls." And yes i know. I should use bind placeholders but the project that my boss gave me is almost finish and it will take a lot of work to change that. – Isaac Hernández Apr 28 '16 at 23:48

1 Answers1

-1

first you have many syntax errors try this :

<?php 

header('Content-Type: text/html; charset=UTF-8');
include_once '../includes/db_connect.php';
include_once '../includes/psl-config.php';
$mysqli->query("SET NAMES 'utf8'");

$fechaRecibo = mysql_real_escape_string( $_POST["fechaRecibo"] );
$nombre = mysql_real_escape_string( $_POST["nombre"] );
$recibiDe = mysql_real_escape_string( $_POST["recibiDe"] );
$monto = mysql_real_escape_string( $_POST["monto"] );
$comentario = mysql_real_escape_string( $_POST["comentario"] );
$idUser = mysql_real_escape_string( $_POST['idUser'] );

$sql = "INSERT INTO vales (fecha, nombre, recibiDe, monto, comentario, created_by) values ('$fechaRecibo','$nombre','$recibiDe','$monto','$comentario','$idUser')";

$res = $mysqli->query($sql);
$lastID = mysqli_insert_id($mysqli);

if ($res){
    echo "Éxito";

} 

else {
    printf("Error message: %s\n", $mysqli->error);
}

?>
Yassine Qoraiche
  • 1,077
  • 14
  • 32