I am stuck, I cannot fix this error that I am getting, and I think it may be that my database options are messed up
Here's where the data is put into a form
<form name = "quoted" method="post" onsubmit="get_action(this);">
<input id = "poster" type="text" name="poster" required="required" placeholder = "Credited Individual."> <br>
<textarea class = "actual_quote" name = "actual_quote" required="required" placeholder = "Write the question here!"></textarea><br><br><br>
<div class = "checkboxes" required="required">
<h3 style = "margin-top:-20px;">Please select one catagory that the quote falls into.</h3>
<label for="x"><input type="radio" name="x" value="Inspirational" id = "inspirational.php" checked="checked" /> <span>Inspirational</span></label><br>
<label for="x"><input type="radio" name="x" value="Funny" id = "funny.php" /> <span>Funny</span> </label><br>
<label for="x"><input type="radio" name="x" value="OutofContext" id = "outofcontext.php"/> <span>OutofContext</span></label>
</div>
<input id = "submit1" name="submit1"s type="submit"><br>
</form>
and here's the php to put that into the database
<?php
$db_name = 'submissions';
$db_user = 'root';
$db_pass = '';
$db_host = 'localhost';
try {
$db = new PDO('mysql:host = localhost;dbname=submissions', $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$actual_quote = (isset($_POST['actual_quote']) ? $_POST['actual_quote'] : null);
$poster = (isset($_POST['poster']) ? $_POST['poster'] : null);
$sql = "INSERT INTO data (actual_quote, poster) VALUES ( :actual_quote, :poster)";
$query = $db->prepare($sql);
$query->execute(array(':actual_quote'=>$actual_quote, ':poster'=>$poster));
?>
( ! ) Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'actual_quote' cannot be null' in C:\wamp\www\Quotr\webweb2.php on line 113 ( ! ) PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'actual_quote' cannot be null in C:\wamp\www\Quotr\webweb2.php on line 113 Call Stack Time Memory Function Location 1 0.0015 257160 {main}( ) ..\webweb2.php:0 2 0.0206 267672 execute ( ) ..\webweb2.php:113
When I do click null in the database, and I click the submit button on the form the error goes away and data shows up in the database, but there is no values, there's nothing there
can someone tell me whats wrong and how to fix this, if it's in the code, I personally think there's an issue with the database, here's some pictures of that.
http://i.imgur.com/0wrd7bT.png
http://i.imgur.com/OKEWCmf.png
(ignore the first 3 on the last picture, the last one is where I am at)
Nothing is wrong with the database. It is doing exactly what it is supposed to be doing.
When the database gives you those errors, it's telling you that you are trying to input "nothing" (null) into a column that doesn't allow it. You are sending nothing because if $_POST['actual_quote']
isn't set, it's null. Either get rid of that action if it isn't set or allow null in the database.
Also: get rid of the s
after the "
in name="submit1"s
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With