Reputation: 199
the page does not seem to be writing to the database. I have a feeling this may be a database error rather than the form submission itself. There are no errors that I have found and I can't seem to figure out why the database isn't accepting my parameters. Please see the code and the database structure below. Please let me know if you need more information.
<?php
session_name('shipshapeLogin');
session_set_cookie_params(2*7*24*60*60);
session_start();
define('INCLUDE_CHECK',true);
require('connect.php');
//require_once('business.php');
if(empty($_SESSION['id']))
{
header("Location: index.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Ad Posting</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-1.9.1.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="advertise.css" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script>
$(function() {
$( "#from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#to" ).datepicker( "option", "minDate", selectedDate );
}
});
$( "#to" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 3,
onClose: function( selectedDate ) {
$( "#from" ).datepicker( "option", "maxDate", selectedDate );
}
});
});
</script>
</head>
<body>
<div class="container">
<form action="" method="post" class="advertiseform">
<div>
<input class="field" type="text" name="business" id="business" disabled="disabled" placeholder="Business Name" value="<?php echo $_SESSION['username']?>" required="true" />
</div>
<div>
<input class="field" type="text" name="title" id="title" placeholder="Title" value="" size="23" required="true" />
</div>
<div>
<textarea input class="field" type="textarea" name="ad" id="ad" placeholder="Body" required="true">
</textarea>
</div>
<div>
<input type="text" id="from" name="from" placeholder="Valid from:" required="true">
</div>
<div>
<input type="text" id="to" name="to" placeholder="To:" required="true">
</div>
<div>
<button type="button" id="clearbtn">Clear Advertisement</button>
<input type="submit" name="submit" value="Post Advertisement" class="submit" />
</div>
</form>
</div>
<?php
$business_name = $_POST['business'];
$title = $_POST['title'];
$body = $_POST['ad'];
//$valid_date= $_POST['from']." to ". $_POST['to'];
$fromDate = $_POST['from'];
$toDate = $_POST['to'];
$query = "INSERT INTO Businesses_ads ( business_name, title, from, to, body, posted) VALUES ( :business_name, :title, :from, :to, :body, NOW())";
$query_params = array(
':business_name' => $business_name,
':title' => $title,
':from' => $fromDate,
':to' => $toDate,
':body' => $body,
);
try{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
echo $ex;
}
?>
</body>
</html>
Upvotes: 0
Views: 94
Reputation: 74216
to
and from
are reserved words which must be wrapped in backticks
Change:
( business_name, title, from, to, body, posted)
to:
( business_name, title, `from`, `to`, body, posted)
Upvotes: 5