PHP - You have an error in your SQL syntax;

Asked

Viewed 75 times

-4

Hello I have an error here! I have the same code as another page but on this page it works and this one does not...

error: You have an error in your SQL syntax; check the manual that Corresponds to your Mysql server version for the right syntax to use near '' at line 1

wrong code:

<?php
session_start();
if (empty($_SESSION['u_id'])){
    header("Location:../principal.php");
    exit(0);
}


require'dbh.inc.php';
$nome=$_POST['Nome'];
$calorias=$_POST['calorias'];


$query=mysqli_query($conn,"INSERT INTO ingredientes (Nome, calorias) VALUES ('$nome','$calorias'") or die(mysqli_error($conn));

mysqli_close($conn);
header("location:../calorias.php?note=success");

page that is linked to that code:

<?php
    include("includes/dbh.inc.php");
    $note="";
    if (!empty($_GET['note'])){
    $note=$_GET['note'];



}

?>

<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Calorias</title>
    <link href="../css/bootstrap.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="../css/estilox.css">
    <link rel="stylesheet" href="../css/menu.css">
    <link rel="stylesheet" href="../css/normalize.css">
    <link rel="stylesheet" href="../css/calorias.css">
    <link rel="stylesheet" type="text/css" href="../css/login.css">
</head>

<body>
    <div class="row">
        <?php
            include 'menu.php';
        ?>
    </div>
    <div id="page-wrap">
    <?PHP if($note=='success')
    {
    $msgconfirm='\nCalorias enviadas com Sucesso!';
    echo "<script>alert(\"$msgconfirm\")</script>";
    }
?>
    <div class="container">
        <div class="row" id="h-row">
            <div class="col-md-12 col-xs-12" id="">
                <form class="email-form" method="post" action="includes/sendcalorias.php">
                    <div class="espaco">
                        <label for="Nome" class="textoform">Titulo Receita:</label>
                        <input placeholder="Titulo Receita" class="form" id="titulo" type="text" name="Nome" required="required"/>
                    </div>
                    <div class="espaco">
                        <label for="calorias" class="textoform">Calorias Receita:</label>
                        <textarea name="calorias" id="message" class="form descricao"  placeholder="Calorias Receita" required="required"></textarea>
                    </div>
                    <div class="relative fullwidth">
                        <button type="submit" id="submit" name="submit" class="contact2 form-btn semibold">Enviar Receita</button> 
                    </div>
                </form>
            </div>
                    </div>
                </div>
            </div>


    <script src="../js/jquery-3.3.1.min.js"></script>
    <script src="../js/bootstrap.js"></script>
    <script src="../js/codigo.js" type="text/javascript"></script>
    <script src="../js/menu.js" type="text/javascript"></script>
<script type="text/javascript" src="../js/login.js" ></script>
</body>

</html>

only on these pages that goes wrong, on the other!

  • You forgot to close the parentheses of VALUES. VALUES ('$nome','$calorias')")

1 answer

0


You’re not closing the query correctly, a ")" is missing at the end of the Insert

$query=mysqli_query($conn,"INSERT INTO ingredientes (Nome, calorias) VALUES ('$nome','$calorias')") or die(mysqli_error($conn));
  • mt obg :D can’t believe it was this, we were 3 people back from the code trying to see where it was wrong ;D

  • Arrange ;) if you have decided do not forget to mark as accepted

  • of course! I just have to wait 4 minutes to do it :)

  • @Ivoamaro no problem, it’s standard comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.