I am facing this error and can't get rid of it at all. Can someone please help?
Attached:
1: Code snippet of my form (HTML) 2: Code snippet of my PHP page where data is meant to be inserted into DB. 3: Output (the error) 4: My DB Screen Shot.
1 FORM CODE
<form class="uk-grid-small uk-margin-medium-top" data-uk-grid action="insertContact.php" method="post">
<div class="uk-width-1-1">
<label>
<input class="uk-input uk-form-large" type="text" name="name" placeholder="Full Name">
</label>
</div>
<div class="uk-width-1-1">
<label>
<input class="uk-input uk-form-large" type="email" name="mail" placeholder="Email Address">
</label>
</div>
<div class="uk-width-1-1">
<label for="reason"></label>
<select name="reason" class="uk-select uk-form-large" >
<option value="">Reason for contacting us</option>
<option value="quote">Quote request</option>
<option value="meet">Arrange a meeting</option>
<option value="work">Work for us</option>
<option value="legal">Legal</option>
<option value="other">Other</option>
</select>
</div>
<div class="uk-width-1-1">
<label for="message"></label>
<textarea class="uk-textarea" rows="5" placeholder="Message" name="txtMessage" id="txtMessage"></textarea>
</div>
<div class="uk-width-1-1">
<button class="uk-button uk-button-large uk-button-primary">Send Message</button>
</div>
</form>
2 PHP CODE
<?php
$server_name= "localhost";
$db_user="root";
$db_password="";
$db_name="digitalmarketing";
$connection=mysqli_connect($server_name,$db_user,$db_password,$db_name);
$dbconfig=mysqli_select_db($connection,$db_name);
if($connection==false)
{
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$name=$_POST['name'];
$mail=$_POST['mail'];
$reason=$_POST['reason'];
$message=$_POST['txtMessage'];
echo $name;
echo "<br>";
echo $mail;
echo "<br>";
echo $reason;
echo "<br>";
echo $message;
echo "<br>";
$sql='INSERT INTO `contacts` VALUES (NULL, $mail, $reason, $message)';
if(mysqli_query($connection, $sql)){
echo "Records inserted successfully.";
} else{
?>
<div class="uk-alert-danger uk-alert uk-alert-danger uk-alert-large" uk-alert>
<a class="uk-alert-close" uk-close></a>
<p> <?php echo "ERROR: Could not able to execute $sql. " . mysqli_error($connection); ?> </p>
</div>
<?php
}
3 ERROR SCREENSHOT
Error :
Anshul Paliwal abc@gmail.com meet Hello Please help me lol ERROR: Could not able to execute INSERT INTO
contacts
VALUES (NULL, $mail, $reason, $message). Unknown column '$mail' in 'field list'
DB
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
CREATE TABLE `contacts` (
`contact_id` int(11) NOT NULL,
`contact_mail` varchar(200) NOT NULL,
`contact_reason` varchar(1000) NOT NULL,
`contact_message` varchar(2000) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Aucun commentaire:
Enregistrer un commentaire