简体   繁体   中英

Simple INSERT doesnt work?

This simple code won't work and I really dont't know why

Any help will be appreciated

   <body>
    <?php
    if (isset($_POST["submit"])) {


        $sql = "INSERT INTO am (schulwoche,kalenderwoche,lehrstoff,anmerkungen,lehrer) VALUES ('".$_GET["sw"]."','".$_GET["kw"]."','".$_GET["ls"]."','".$_GET["an"]."','".$_GET["le"]."')";
        $conn->query($sql1);
    }
    ?>
    <div class="anzeige">
        <form action="insert.php" method="post">
            <b>Schulwoche: </b><input type="text" name="sw"><br>
            <b>Kalenderwoche: </b><input type="text" name="kw"><br>
            <b>Lehrstoff: </b><input type="text" name="ls"><br>
            <b>Anmkerkungen: </b><input type="text" name="an"><br>
            <b>Lehrer: </b><input type="text" name="le"><br>
            <input type="submit" value="Eintragen">
        </form>

What is the error you receive? My bet is that one of the get variables are missing at run time and you are trying to insert a null into a required field.

Its also possible that there are other fields in your am table that you are not populating using your php/sql insert syntax.

Try this

$sql = "INSERT INTO am (schulwoche,kalenderwoche,lehrstoff,anmerkungen,lehrer) VALUES ('".$_GET["sw"]."','".$_GET["kw"]."','".$_GET["ls"]."','".$_GET["an"]."','".$_GET["le"]."')";
echo $sql;

Then copy the SQL and try run it directly on your database via the terminal or something. You will quickly see what is wrong.

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