1

i used this code and i didnt get any errors but when i check the phpadmin and my database its all empty no data added to the table what should i do ? where is the problem?

i checked also my database and table values and my html names

<?php
    if(isset( $_POST['submit'] ) )
    {                       
        $name = $_POST['p_name'];
        $price = $_POST['p_price'];
        $type = $_POST['p_type'];
        $des = $_POST['p_desc'];
        $img = 'images/is7.jpeg';
        //***********************
        require_once 'setting.php';
        $dbc = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
        mysqli_set_charset($dbc, 'utf8');
        $query = "INSERT INTO products(name, price, type, des, img)
                        VALUES('$name', '$price', '$type', $des, '$img')";
        mysqli_query($dbc, $query);
        mysqli_close($dbc);
        header('Location: success.php');
        exit;
    }
?>
2
  • Put echo mysqli_error($dbc); after mysqli_query($dbc, $query); Commented May 30, 2019 at 9:38
  • The right tool to solve such problems is your debugger. You should step through your code line-by-line before asking on Stack Overflow. For more help, please read How to debug small programs (by Eric Lippert). At a minimum, you should edit your question to include a Minimal, Complete, and Verifiable example that reproduces your problem, along with the observations you made in the debugger. Commented May 30, 2019 at 10:16

3 Answers 3

1

Did you try to put single quotes around description variable?

Change

VALUES('$name', '$price', '$type', $des, '$img')";

To

VALUES('$name', '$price', '$type', '$des', '$img')";

Cheers

Sign up to request clarification or add additional context in comments.

Comments

0
"INSERT INTO products(name, price, type, des, img) VALUES('$name', '$price', '$type', '$des', '$img')";

OR
"INSERT INTO products(name, price, type, des, img) VALUES(?, ?, ?, ?, ?)";

Comments

0

Replare this formate

<?php
$query = "INSERT INTO products(name, price, type, des, img)VALUES('$name', '$price', '$type', $des, '$img')";
?>

TO

<?php
$query = "INSERT INTO products(name, price, type, des, img)VALUES('".$name."', '".$price."', '".$type."', '".$des."', '".$img."')";
?>

In feature apply mySQL error check up to get mySQL error.

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.