简体   繁体   中英

Error or not and insert to database mysql

Why wont this work?

<?php include "top.php"; 
include "connect.php";
if(isset($_POST["submit"])) {
$error = "";
    if(empty($_POST["name"])) {
        $error .= "Du glömde märket!<br>";
        if(empty($_POST["rating"])){
        $error .= "Du glömde att bedömma märket!<br>";
                if(empty($_POST["worth"])){
        $error .= "Du glömde att välja vilken klass den hör till!<br>";
                if(empty($_POST["username"])){
        $error .= "Du glömde att skriva ditt namn!<br>";
                if(empty($_POST["rating"])){
        $error .= "Du glömde att skriva någonting?!!<br>";
        }}}}}
    if(!empty($error)){
    echo $error;
    }else{
$name = $_POST["name"];
$rating = $_POST["rating"];
$worth = $_POST["worth"];
$favorite = $_POST["favorite"];
$username = $_POST["username"];
$description = $_POST["description"];
mysql_query("INSERT INTO brands (name, rating, worth, favorite, username, description) VALUES ('$name', '$rating', '$worth', '$favorite', '$username', '$description')");
echo "<span style='color: green'>Yir yir, <a href='brand.php'>klicka här för att gå till Märken.</a></span>";
    }
    }

It doesnt come with errors it just say the succeed message like it has inserted to database

.We can't help you unless you at least try to get some debug information.

For instance, replace

mysql_query("INSERT INTO brands (name, rating, worth, favorite, username, description) VALUES ('$name', '$rating', '$worth', '$favorite', '$username', '$description')");

With

$query = "INSERT INTO brands (name, rating, worth, favorite, username, description) VALUES ('$name', '$rating', '$worth', '$favorite', '$username', '$description')";

echo "Query: " . $query;

mysql_query($query);

It echoes the query to the screen before executing it, perhaps it provides some more information.

回显您创建的查询,并查看显示的内容并执行该查询以在phpmyadmin中进行测试

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