jokergonemad jokergonemad - 2 years ago 101
PHP Question

Importing to my sql

I am just learning php/mysql and can't add a new row to a database and i don't know why!

<?php

$Darrell= $_POST['Darrell'];
$Ashley = $_POST['Ashley'];



if ($_POST)

$sql = "INSERT INTO `updates`(`Darrell`, `Ashley`) VALUES ('$Darrel','$Ashley')";


if (mysqli_query($connection, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>


It just will not input to the fields. The database is connected and the column names are correct.

Answer Source

You have a simple spelling error. You set $Darrell(2 l) and then try and use $Darrel (1 l)

Also in your original question there was the missing quotes around the query parameters that @makmesh told you about! and then you chnaged your question.

$Darrell= $_POST['Darrell'];   // 2 L
$Ashley = $_POST['Ashley'];

if ($_POST) 

    // here $Darrel = 1 L
    $sql = "INSERT INTO `updates`(`Darrell`, `Ashley`) VALUES ('$Darrel','$Ashley')";  

    /*
     * Code you should write to check all queries worked
    */
    $res = mysqli_query($connection, $sql);
    if ($res === FALSE) {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
        exit;
    } else {
        echo "New record created successfully";
    }
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download