简体   繁体   中英

No infomation are inserted into my table in the database

A row are added into the selected table but no information are added, and i hope that someone that are better in coding can help me.

if (isset($_POST['submit'])) {

        mysqli_query($con, "INSERT INTO `ads` (`title`, `about`, `price`, `delivery`, `payment`, `picture1`, `picture2`, `picture3`, `picture4`)
        VALUES('$title', '$about' ,'$price', '$delivery', '$payment', '$picture1', '$picture2', '$picture3', '$picture4')") or die(mysqli_error());

    echo 'Your ad have now been created!';

    }

And here are the form:

echo '<form action="create.php" method="post">';

echo '<input class="input-field" name="title" type="text" placeholder="Title" />';

echo '<br><br>';

echo '<textarea name="about" style="width: 400px; height: 230px;" placeholder="Other infomation that can help us?"></textarea>';

echo '<br><br>';

echo '<input class="input-field" name="price" type="text" placeholder="Price" />';

echo '<br><br>';

echo '<input name="submit" type="submit" value="Make a request" />';

echo '</form>';

If you do not assign any value to the local variables, variables are considered to be empty in PHP. From the coding above, however, I would assume that you expect that the variables $title , $about and $price etc. are filled with the same values than in the HTML form (see also Get all variables sent with POST? ). Keep in mind that this behaviour (called register_globals has been deprectated since PHP 5.3.0 - background to this were severe security issues).

In short, an easy set of

$title = $_POST['title'];
$about = $_POST['about'];
$price = $_POST['price'];
// ...

might already be the solution to your problem.

Looks like you missed the $_POST

<?php
if (isset($_POST['submit'])) {

mysqli_query($con, "INSERT INTO `ads` (`title`, `about`, `price`, `delivery`, `payment`, `picture1`, `picture2`, `picture3`, `picture4`)
VALUES('".$_POST['title']."', '".$_POST['about']."' ,'".$_POST['price']."', '".$_POST['delivery']."', '".$_POST['payment']."', '".$_POST['picture1']."', '".$_POST['picture2']."', '".$_POST['picture3']."', '".$_POST['picture4']."')") or die(mysqli_error());

echo 'Your ad have now been created!';

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM