Windows time in MySQL - php

I have a datetime variable in MySQL. Now it's 15:36 14-09-2021 on my computer, but when I store it to MySQL there is 09:36 2021-09-14. What can I do to display it in a way which takes into account Windows time? Do you know how to do that? Do you have any ideas?
This is my current code:
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Question</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<a href="index.php">
<img id="logo" src="logo.png" width="100px" height="100px" style="margin-left: 400px;">
</a>
</div>
<?php
$connection = mysqli_connect("XXX", "XXX", "XXX", "XXX");
if (isset($_POST['answer'])) {
$stmt = mysqli_prepare($connection, "INSERT INTO answers(questionId, dateAndTime, answer) VALUES (?,(SELECT now()),?)");
$stmt->bind_param("ss", $a, $b);
$a = $_SESSION['id'];
$b = $_POST['answer'];
$stmt->execute();
}
if (isset($_GET['id'])) {
$stmt = mysqli_prepare($connection, "SELECT posts.title,posts.body,posts.dateAndTime FROM posts WHERE posts.id=?");
$stmt->bind_param("s", $id);
$id = $_GET['id'];
$_SESSION['id'] = $id;
$stmt->execute();
$result = $stmt->get_result();
while ($row = mysqli_fetch_assoc($result)) {
echo '<div style="display: flex;"><div>', $row['dateAndTime'], '</div><div style="font-size: 42px;">', $row['title'], "</div></div><div>", $row['body'], "</div>";
}
} else {
$stmt = mysqli_prepare($connection, "SELECT posts.title,posts.body,posts.dateAndTime FROM posts WHERE posts.id=?");
$stmt->bind_param("s", $id);
$id = $_SESSION['id'];
$stmt->execute();
$result = $stmt->get_result();
while ($row = mysqli_fetch_assoc($result)) {
echo '<div style="display: flex;"><div>', $row['dateAndTime'], '</div><div style="font-size: 42px;">', $row['title'], "</div></div><div>", $row['body'], "</div>";
}
} {
$stmt = mysqli_prepare($connection, "SELECT answers.answer, answers.dateAndTime FROM answers WHERE answers.questionId=?");
$stmt->bind_param("s", $id);
$stmt->execute();
$result = $stmt->get_result();
while ($row = mysqli_fetch_assoc($result)) {
echo '<div style="border-style: solid; margin: 5px; display: inline-block;"><div style="display:flex;"><div>', $row['dateAndTime'], '</div><div style="margin: 5px;">', $row['answer'], "</div></div></div><br>";
}
}
?>
<form action="question.php" method="POST" style="display: flex; flex-direction: column;">
<textarea name="answer" style="margin-top: 100px; width: 25%; height: 200px;"></textarea>
<button type="submit" class="btn" style=" width: 5%; text-align: center;">Answer</button>
<input type='hidden' value='send' name='first'>
</form>
</body>
</html>

First use the following javascript code:
<script>
function createCookie(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
} else {
expires = "";
}
document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
}
createCookie("timeZone", Intl.DateTimeFormat().resolvedOptions().timeZone, "10");
</script>
And than just use the following code in PHP:
$date = new DateTime($row['dateAndTime'], new DateTimeZone(date_default_timezone_get()));
$date->setTimezone(new DateTimeZone($_COOKIE["timeZone"]));
$date->format('Y-m-d H:i:s')

Related

how can i limit the number of results fetched and then filter them?

I recently started learning ajax in order to use the live filter by checkbox. This worked out well until i decided to limit the results fetched from the database using order by id asc limit 0,$rowperpage where rowperpage = 3. Adding this to my code disabled the checkbox filter completely. What could i be doing wrong?
The following is my code.
index.php
<?php
//index.php
include('database_connection.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Product filter in php</title>
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-ui.js"></script>
<script src="js/bootstrap.min.js"></script>
</head>
<body>
<!-- Page Content -->
<div class="">
<h3>Duration</h3>
<?php
$query = "
SELECT DISTINCT(duration) FROM career
";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<div class="checkbox">
<label><input type="checkbox" class="common_selector duration" value="<?php echo $row['duration']; ?>" > <?php echo $row['duration']; ?></label>
</div>
<?php
}
?>
</div>
<br />
<div class="filter_data">
</div>
<style>
#loading
{
text-align:center;
background: url('loader.gif') no-repeat center;
height: 150px;
}
.jobs{
background: gray;
margin: 10px;
padding: 10px;
width: 200px;
}
</style>
<script>
$(document).ready(function(){
filter_data();
function filter_data()
//this deals with filter checkboxes
{
$('.filter_data').html('<div id="loading" style="" ></div>');
var action = 'fetch_data';
var duration = get_filter('duration');
$.ajax({
url:"fetch_data.php",
method:"POST",
data:{action:action, duration:duration},
success:function(data){
$('.filter_data').html(data);
}
});
}
function get_filter(class_name)
{
var filter = [];
$('.'+class_name+':checked').each(function(){
filter.push($(this).val());
});
return filter;
}
$('.common_selector').click(function(){
filter_data();
});
});
</script>
</body>
</html>
fetch_data.php
<?php
//fetch_data.php
include('database_connection.php');
$rowperpage = 3;
if(isset($_POST["action"]))
{
//statement limits but disables check box filter
$query = "
SELECT * FROM career order by id asc limit 0,$rowperpage
";
if(isset($_POST["duration"]))
{
$duration_filter = implode("','", $_POST["duration"]);
$query .= "
WHERE duration IN('".$duration_filter."')
";
}
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
$output = '';
if($total_row > 0)
{
foreach($result as $row)
{
$output .= '
<div class="jobs">
Title : '. $row['title'] .' <br />
duration : '. $row['duration'] .'
</div>
';
}
}
else
{
$output = '<h3>No Data Found</h3>';
}
echo $output;
}
?>
database_connection.php
<?php
//database_connection.php
$connect = new PDO("mysql:host=localhost;dbname=biit", "root", "");
?>
The database table 'career'
Any help will be much appreciated :)

Can someone explain why my MySQL table data is not being displayed?

I'm new to PHP and MySQL. I have an HTML table and form that submits the entered data to MySQL, but doesn't display the MySQL data in my HTML table. Here is an image for reference: https://i.imgur.com/OEDd6Px.png. I want the submitted data to display upon submission if possible but am unable to find a solution. Thanks in advance.
<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "test";
$conn = mysqli_connect($host, $user, $pass, $db);
if (!$conn) {
die ('Failed to connect to MySQL: ' . mysqli_connect_error());
}
if(isset($_POST["asin"]))
{
$asin = $_POST["asin"];
$category = $_POST["category"];
$submit = "INSERT INTO `user_input`(`id`, `asin`, `category`, `date`) VALUES (NULL, '$asin', '$category', CURRENT_DATE())";
$sql = mysqli_query($conn, $submit);
if (!$sql) {
die ('SQL Error: ' . mysqli_error($conn));
}
$display = "SELECT * FROM user_input";
$result = mysqli_query($conn, $display);
if (!$result) {
die ('SQL Error: ' . mysqli_error($conn));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>testEnv</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<style>
form {
padding-bottom: 10px;
padding-top: 10px;
}
table, thead, tbody, th, td {
padding: 4px;
border-collapse: collapse;
border: 1px solid black;
}
form {
font-size: 13px;
}
th, td {
width: auto;
text-align: center;
font-size: 13px;
}
</style>
</head>
<body>
<div class="container-fluid">
<form id="form" method="post">
<div>
<label id="asinLabel" for="asin">ASIN:</label>
<input id="asinInput" type="text" name="asin"></input>
<label id="categoryLabel" for="category">Category:</label>
<input id="categoryInput" type="text" name="category"></input>
<input id="submit" type="submit" value="Submit"></input>
</div>
</form>
</div>
<div class="container-fluid">
<table class="container-fluid">
<thead>
<tr>
<th>ID</th>
<th>ASIN</th>
<th>Category</th>
<th>Date</th>
<th>6:00 AM</th>
<th>8:00 AM</th>
<th>10:00 AM</th>
<th>12:00 PM</th>
</tr>
</thead>
<tbody id="tableBody">
<?php
while($row = mysqli_fetch_array($result));
{
echo '<tr>
<td>'.$row['id'].'</td>
<td>'.$row['asin'].'</td>
<td>'.$row['category'].'</td>
<td>'. date('m d, Y', strtotime($row['date'])) .'</td>
<td>'.$row['6am'].'</td>
<td>'.$row['8am'].'</td>
<td>'.$row['10am'].'</td>
<td>'.$row['12pm'].'</td>
</tr>';
}
mysqli_close($conn);
?>
</tbody>
</table>
</div>
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script rel="script" type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script rel="script" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.js"></script>
<script rel="script" type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.js"></script>
</body>
</html>
Try to write
$display = "SELECT * FROM user_input";
$result = mysqli_query($conn, $display);
if (!$result) {
die ('SQL Error: ' . mysqli_error($conn));
}
block out side of the condition.

Fullcalendar not showing up events - PHP mysql

I am using the Full calendar in my PHP application. But the issue is that events don't show up in the calendar.
Calendar.php -
<?php
$host = "localhost";
$user = "myusername";
$pw = "mypass";
$database = "mydb";
$db = mysql_connect($host,$user,$pw)
or die("Cannot connect to mySQL.");
mysql_select_db($database,$db)
or die("Cannot connect to database.");
$year = date('Y');
$month = date('m');
$command = "SELECT * FROM `calendar_urls` ";
$result = mysql_query($command, $db);
while ($row = mysql_fetch_assoc($result)) {
$url = $row['calendar_array'];
$urls[] = $url;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel='stylesheet' type='text/css' href='fullcalendar/fullcalendar.css' />
<link rel='stylesheet' type='text/css' href='fullcalendar/fullcalendar.print.css' media='print' />
<script type='text/javascript' src='jquery/jquery-1.7.1.min.js'></script>
<script type='text/javascript' src='jquery/jquery-ui-1.8.17.custom.min.js'></script>
<script type='text/javascript' src='fullcalendar/fullcalendar.min.js'></script>
<script type='text/javascript' src='fullcalendar/gcal.js'></script>
<script>
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'prev,next',
center: 'title',
right: 'month,basicWeek,basicDay'
},
editable: true,
//events: 'https://www.google.com/calendar/feeds/kelchuk68%40gmail.com/public/basic/',
eventSources: [
//get_string(),
/*'https://www.google.com/calendar/feeds/kelchuk68%40gmail.com/public/basic',
'events.php',*/
<?php echo implode(",", $urls); ?>
]
});
});
</script>
<style type='text/css'>
body {
margin-top: 40px;
text-align: center;
font-size: 14px;
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
}
#calendar {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div style="display:block; width:900px; margin: 0 auto; ">
<div style="float:right; margin-bottom:10px;">
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post">
<input type="submit" name="add_event" value="Add Event"/>
</form>
<p style="display:none">Add Event | Edit Event | Delete Event</p></div>
</div>
<div style="clear:both;"></div>
<?php if($_POST['add_event']){
$year = date("Y");
$year2= $year + 1;
$mymonth = date("m");
$day = date("d");?>
<div style="background-color:grey; width:900px; margin:0 auto;padding-top:20px;padding-bottom:10px; border-radius:15px;">
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post">
<div style="float:left;margin-left:10px;">Title: <input style="margin:0 auto; text-align:left;" type="text" name="event_title" value=""/>
<select name ="year">
<?php echo '<option selected="selected">'.$year.'</option>';
echo '<option>'.$year2.'</option>';
echo '</select>';
?>
<select name ="month">
<?php
$month = array($month);
echo '<option selected="selected">'.$mymonth.'</option>';
$months = array('01','02','03','04','05','06','07','08','09','10','11','12');
$months = array_diff($months,$month);
foreach($months as $month_opt){
echo '<option>'.$month_opt.'</option>';
}
echo '</select>';
?>
<select name="day">
<?php echo '<option selected="selected">'.$day.'</option>';
for($i=1; $i<32; $i++) {
echo '<option>'.$i.'</option>';
}
echo '</select>';
?>
&nbsp Hour: <select name="hour">
<?php
$hours = array('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23');
foreach($hours as $hour){
echo '<option>'.$hour.'</option>';
}
echo '</select>';
?>
&nbsp Minutes: <select name="minutes">
<?php
$minutes = array('00','15','30','45');
foreach($minutes as $minute){
echo '<option>'.$minute.'</option>';
}
echo '</select>';
echo'</div>';
?><br/><br/>
<div style="float:left;margin-left:10px;margin-bottom:5px;">Notes:</div>
<textarea name="notes" style="width:880px; margin:0 auto;"></textarea><br/>
<?php
echo '<input style="margin-top:10px;" type="submit" name="adding" value="Add the Event"/></form></div><br/><br/>';
}
if($_POST['adding']) {
$year = $_POST['year'];
$month = $_POST['month'];
$day= $_POST['day'];
$hour= $_POST['hour'];
$minutes= $_POST['minutes'];
$fulldate = $year."-".$month."-".$day." ".$hour.":".$minutes;
$command = "INSERT INTO calendar VALUES('','0', '{$_POST['event_title']}', '{$_POST['notes']}', '$fulldate','') ";
$result = mysql_query($command, $db);
if($result) {
echo "Successful Insert!";
}
}
?>
<div style="clear:both;"></div>
<div id='calendar'></div>
</body>
</html>
The calendar shows up properly. Also it lets user add events but those events are not displayed.
The 2 tables which are used by the calendar contain the following -
This is my events.php-
<?php
session_start();
date_default_timezone_set('Asia/Calcutta');
include ("connect.inc");
$db = public_db_connect();
$year = date('Y');
$month = date('m');
$command = "SELECT * FROM `calendar`";
$result = mysql_query($command, $db);
while ($row = mysql_fetch_assoc($result)) {
//echo "hi";
//$start = date("D, j M Y G:i:s T", strtotime($row['start']));
//$end = date("D, j M Y G:i:s T", strtotime($row['end_time']));
$start = date("Y-m-d", strtotime($row['start']));
//$start = "$year-$month-20";
$myid = $row['id'];
$eventsArray['id'] = (int)trim($myid);
$eventsArray['title'] = $row['title'];
$title = date("g:ia", strtotime($row['start']))." ".$row['title'];
//$title = $row['title'];
//echo $title;
$eventsArray['title'] = $title;
$eventsArray['start'] = $start;
/*$eventsArray['end'] = $start;*/
$eventsArray['url'] = "edit_calendar.php?calendarid=".$row['id'];
// $eventsArray['end'] = $end;
// $eventsArray['allDay'] = false;
$events[] = $eventsArray;
}
echo json_encode($events);
Connect.inc -
<?php
function public_db_connect() {
$host = "localhost";
$user = "myuser";
$pw = "mypass";
$database = "mydb";
$db = mysql_connect($host,$user,$pw)
or die("Cannot connect to mySQL.");
mysql_select_db($database,$db)
or die("Cannot connect to database.");
return $db;
}
?>
I don't know what that calendar URL is for and why it has some google link as it came from the site I downloaded this calendar.
Thanks.

Foreach loop from a Query using PHP

I have a query on my php which prints out a result of one row only, I need to print out all the rows for each and every user.
Here is the php:
<?php
// see if the form has been completed
include_once("php_includes/check_login_status.php");
//include_once("php_includes/db_conx.php");
// Initialize any variables that the page might echo
$username = "";
$weight = "";
$weighthist = "";
$id = "";
if(isset($_GET["u"])){
$username = preg_replace('#[^a-z0-9]#i', '', $_GET['u']);
}
$sql = "SELECT users.*, weighthistory.* FROM users JOIN weighthistory USING(id)";
$user_query = mysqli_query($db_conx, $sql);
// check if the user exists in the database
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$id = $row ["id"];
$username = $row ["username"];
$weight = $row["weight"];
$weighthist = $row["weighthist"];
$point_hist = $row["point_hist"];
}
// this is to calculate points score
$calweight = $weight - $weighthist;
$points = $calweight * 10;
$res = mysqli_query($db_conx,'SELECT sum(point_hist) FROM points_history');
if (FALSE === $res) die("Select sum failed: ".mysqli_error);
$row = mysqli_fetch_row($res);
$sum = $row[0];
?>
Here is the HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Profile Update: <?php echo $u; ?></title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="js/main.js"></script>
<script src="js/javascript.js"></script>
<script src="js/ajax.js"></script>
<style type="text/css">
#updateform{
margin-top:24px;
}
#updateform > div {
margin-top: 12px;
}
#updateform > input {
width: 200px;
padding: 3px;
background: #F3F9DD;
}
</style>
</head>
<body>
<p> </p>
<?php include_once("template_pageTop.php"); ?>
<div id="pageMiddle">
<div id="usernamecss"> Username: <?php echo $username; ?></div>
<table width="100%" border="0">
<tr>
<td>Name</td>
<td>Weight</td>
<td>Rank</td>
<td>Points</td>
</tr>
<tr>
<td><?php echo $username ?></td>
<td><?php echo $weight?></td>
<td><?php echo $rank?></td>
<td><?php echo $sum?></td>
</tr>
</table>
<p> </p>
<strong></strong>
Go to Profile
</form>
</div>
<?php include_once("template_pageBottom.php"); ?>
</body>
</html>
I am new to this so how can I print all rows for all user ID, I get the idea I have to use a foreach loop.
This is how you could do it...
PHP file
<?php
// see if the form has been completed
include_once("php_includes/check_login_status.php");
//include_once("php_includes/db_conx.php");
// Initialize any variables that the page might echo
$username = "";
$weight = "";
$weighthist = "";
$id = "";
if(isset($_GET["u"])){
$username = preg_replace('#[^a-z0-9]#i', '', $_GET['u']);
}
$sql = "SELECT users.*, weighthistory.* FROM users JOIN weighthistory USING(id)";
$user_query = mysqli_query($db_conx, $sql);
// check if the user exists in the database
while ($row = mysqli_fetch_assoc($user_query)) {
$id = $row ["id"];
$username = $row ["username"];
$weight = $row["weight"];
$weighthist = $row["weighthist"];
$point_hist = $row["point_hist"];
// this is to calculate points score
$calweight = $weight - $weighthist;
$points = $calweight * 10;
$res = mysqli_query($db_conx,'SELECT sum(point_hist) FROM points_history');
if (FALSE === $res) die("Select sum failed: ".mysqli_error);
$row = mysqli_fetch_row($res);
$sum = $row[0];
?>
<div id="pageMiddle">
<div id="usernamecss"> Username: <?php echo $username; ?></div>
<table width="100%" border="0">
<tr>
<td>Name</td>
<td>Weight</td>
<td>Rank</td>
<td>Points</td>
</tr>
<tr>
<td><?php echo $username ?></td>
<td><?php echo $weight?></td>
<td><?php echo $rank?></td>
<td><?php echo $sum?></td>
</tr>
</table>
<p> </p>
<strong></strong>
Go to Profile
</form>
</div>
<?php
}
?>
HTML file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Profile Update: <?php echo $u; ?></title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="js/main.js"></script>
<script src="js/javascript.js"></script>
<script src="js/ajax.js"></script>
<style type="text/css">
#updateform{
margin-top:24px;
}
#updateform > div {
margin-top: 12px;
}
#updateform > input {
width: 200px;
padding: 3px;
background: #F3F9DD;
}
</style>
</head>
<body>
<p> </p>
<?php include_once("template_pageTop.php"); ?>
<?php include_once("template_pageBottom.php"); ?>
</body>
</html>
Edit:
If username is a column in your points_history table... then you can change this
$res = mysqli_query($db_conx,'SELECT sum(point_hist) FROM points_history');
if (FALSE === $res) die("Select sum failed: ".mysqli_error);
$row = mysqli_fetch_row($res);
$sum = $row[0];
to this
$query = "SELECT sum(point_hist) FROM points_history WHERE username = $username";
$res = mysqli_query($db_conx, $query);
$row = mysqli_fetch_row($res);
$sum = $row[0];

SQLSTATE[42000]: Syntax error or access violation: 1064, can't find source

I'm being thrown an error:
"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an
error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '* FROM auction
WHERE etime < ?' at line 1 "
My understanding of this is usually I have spelt something wrong where it says the error is occurring.
However, in the following script, there is no "* FROM auction WHERE etime < ?" on line 1 of my page.
Further it occurs only 3 times in the page - at line 19, 26 and 288.
I've checked all these locations for a syntax blunder around it and it looks proper. So I have no idea why this is being thrown, I want it to go away.
The page is rather large, bear with me:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
session_start();
$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$_SESSION['lasturl'] = $url;
include("connect.php");
$pdo = connect();
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try{
$old = time() - (60*24*60*60);
$stmt15 = $pdo->prepare("DELETE * FROM auction WHERE etime < :time");
$stmt15->bindParam(":time", $old, PDO::PARAM_INT);
$stmt15->execute();
$time = time();
$stmt8 = $pdo->prepare("SELECT * FROM auction WHERE etime < :time AND closed < 1");
$stmt8->bindParam(":time", $time, PDO::PARAM_INT);
$stmt8->execute();
while($row = $stmt8->fetch(PDO::FETCH_ASSOC)){
$id = $row['ID'];
$holder = $row['holder'];
$owner = $row['owner'];
$stmt5 = $pdo->prepare("UPDATE auction SET closed = 50 WHERE ID = :id");
$stmt5->bindParam(":id", $id, PDO::PARAM_INT);
$stmt5->execute();
$stmt3 = $pdo->prepare("SELECT * FROM user WHERE username = :holder");
$stmt3->bindParam(":holder", $holder, PDO::PARAM_STR);
$stmt3->execute();
$row2 = $stmt3->fetch(PDO::FETCH_ASSOC);
$fbtokenh = $row2['fbtoken'];
$fbtokenh++;
$stmt4 = $pdo->prepare("UPDATE user WHERE username = :holder SET fbtoken = :fbtoken");
$stmt4->bindParam(":holder", $holder, PDO::PARMA_STR);
$stmt4->bindParam(":fbtoken", $fbtokenh, PDO::PARAM_INT);
$stmt4->execute();
$stmt6 = $pdo->prepare("SELECT * FROM user WHERE username = :owner");
$stmt6->bindParam(":owner", $owner, PDO::PARAM_STR);
$stmt6->execute();
$row3 = $stmt6->fetch(PDO::FETCH_ASSOC);
$fbtokeno = $row2['fbtoken'];
$fbtokeno++;
$stmt7 = $pdo->prepare("UPDATE user WHERE username = :owner SET fbtoken = :fbtoken");
$stmt7->bindParam(":owner", $owner, PDO::PARAM_STR);
$stmt7->bindParam(":fbtoken", $fbtokeno, PDO::PARAM_INT);
$stmt7->execute();
}
}catch(PDOException $e){
echo $e->getMessage();
}
if(isset($_GET['searchbox'])){
$search = $_GET['searchbox'];
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Trade diving equipment online at DiveBay</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.countdown.css" />
<script type="text/javascript" src="js/jquery.countdown.js"></script>
<script src="js/menuscript.js" language="javascript" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="css/menustyle.css" media="screen, print" />
<link rel="stylesheet" type="text/css" href="css/searching.css" />
</head>
<body>
<center>
<div id="wrapper">
<div id="header">
<div id="hbackground">
<img src="db3.jpg" alt="hbackground" width="100%" height="100%" style="z-index:1;" />
<div id="htitle">
<span id="banner">DIVEBAY.COM</span>
<span id="byline">SEARCHING FOR STUFF ONLINE</span>
<table border="0" cellpadding="0" cellspacing="0" style="float:right; background-color:transparent;">
<tr>
<td>
<img src="buttons/button1up.png" border="0" id="button1" vspace="1" hspace="1"><br>
<img src="buttons/button2up.png" border="0" id="button2" vspace="1" hspace="1"><br>
<img src="buttons/button3up.png" border="0" id="button3" vspace="1" hspace="1"><br>
<img src="buttons/button4up.png" border="0" id="button4" vspace="1" hspace="1"><br>
<img src="buttons/button5up.png" border="0" id="button5" vspace="1" hspace="1"><br>
<?php
if(isset($_SESSION['loggedin'])){
?>
<img src="buttons/button7up.png" border="0" id="button7" vspace="1" hspace="1"><br>
<?php
}else{
?>
<img src="buttons/button6up.png" border="0" id="button6" vspace="1" hspace="1"><br>
<?php
}
?>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="searchandlog">
<div id="search">
<form id="searchdivebay" action="search.php" method="get">
<div id="searchboxholder"><input type="text" name="searchbox" id="searchbox" /></div>
<div id="searchbuttonholder"><input type="submit" name="searchbutton" id="searchbutton" value="Search DiveBay"/></div>
<input type="hidden" id="submit" name="submit" value="1"/>
</form>
</div>
<div id="login">
<?php
if(isset($_SESSION['loggedin'])){
echo '<span class="price1">Logged in as:</span> <span class="sessionset">'.$_SESSION['username'].'</span>';
}
else{
echo '<ul class="signreg">
<li><i>Existing user?</i>SIGN IN</li>
<li><i>or, new?</i>REGISTER</li>
</ul>';
}
?>
</div>
</div>
<?php
if(isset($_POST['searchbox'])){
if($search == ""){
?>
<p style="color:black; font-size:18pt; font-family: Impact; "> You didn"t search for anything!</p>
<?php
}else{
try{
$time = time();
$stmt12 = $pdo->prepare('SELECT * FROM auction WHERE name LIKE :name');
$stmt12->bindParam(':name', '%'. trim($search) .'%',PDO::PARAM_STR);
$stmt12->execute();
$numrows = 0;
?>
<div id="searchresults"><span style="font-style:italic; font-size: 14pt; font-family:Impact;">Search results for: </span>&nbsp<span id="searchword"><?php echo $search; ?></span></div>
<div id="content">
<table id="displaying" class="displayer">
<?php
while($row = $stmt12->fetch(PDO::FETCH_ASSOC)){
$numrows++;
$ID = $row['ID'];
$img = $row['img'];
$desc = $row['description'];
$name = $row['name'];
$owner = $row['owner'];
$cprice = $row['sprice'];
$iprice = $row['iprice'];
$incprice = $row['incprice'];
$etime = $row['etime'];
$nextBid = $cprice + $incprice;
$stmt21 = $pdo->prepare("SELECT * FROM user WHERE username = :username");
$stmt21->bindParam(":username", $owner,PDO::PARAM_STR);
$stmt21->execute();
$thisuser = $stmt21->fetch(PDO::FETCH_ASSOC);
$location = $thisuser['location'];
echo'
<tr class="resultindex">
<td class="imgCol"><img src="'.$img.'" alt="'.$name.'" /></td>
<td class="infoCol">
<div class="nameDiv">
<a class="nameLink" href="displayAuct.php?id='.$ID.'">'.$name.'</a><br/>
</div>
<div class="descDiv">
<span class="priceLabel2">'.$desc.'</span>
</div>
<div class="userdiv">
<span class="fromuser">Location: </span><br/>
<span class="location">'.$location.'</span>
</div>
</td>
<td style="width:1px; background-color:#330066;" ></td>
<td class="priceCol">
<div class="currentp"><span class="priceLabel">Current Bid: </span><br/><span class="price1">$'.$cprice.'</span></div>
<div class="instantp"><span class="priceLabel2">Instant Sale: </span><br/><span class="price2">$'.$iprice.'</span></div>
<div style="height:5px;"></div>
<div class="incp"><span class="priceLabel2">Next Bid:</span><br/><span class="price2">$'.$nextBid.'</span></div>
</td>
<td style="width:1px; background-color:#330066;"></td>
<td class="timerCol">
<div id="timeRow">
<span class="timeleft">Time Left: </span>
</div>
<div id="countdownRow"></div>
<script type=text/javascript>
var timestamp = '. $etime * 1000 .';
var endTime = new Date();
endTime.setTime(timestamp);
$("#countdownRow").countdown({until: endTime});
</script>
</td>
</tr>
';
}
if($numrows == 0){
?>
<tr>
<td colspan="6"><span class="price1">Sorry your search returned no results</span></td>
</tr>
<?php
}
else{
?>
<tr>
<td colspan="6"><span class="price1">Displaying <?php echo $numrows; ?> results</span></td>
</tr>
<?php
$pdo = null;
}
}catch(PDOException $e){
echo $e->getMessage();
}
}
?>
</table>
</div>
<?php
}else{
?>
<div id="searchresults"><span style="font-style:italic; font-size: 14pt; font-family:Impact;">Hurry, these auctions dont have long left!:</span></div>
<div id="content">
<table id="displaying" class="displayer">
<?php
try{
$time = time();
$in15 = time() + 900;
$stmt55 = $pdo->prepare('SELECT * FROM auction WHERE etime < :etime AND etime > :time ORDER BY etime');
$stmt55->bindParam(':etime', $in15, PDO::PARAM_INT);
$stmt55->bindParam(':time', $time, PDO::PARAM_INT);
$stmt55->execute();
while($row = $stmt55->fetch(PDO::FETCH_ASSOC)){
$ID = $row['ID'];
$img = $row['img'];
$desc = $row['description'];
$name = $row['name'];
$owner = $row['owner'];
$cprice = $row['sprice'];
$iprice = $row['iprice'];
$incprice = $row['incprice'];
$etime = $row['etime'];
$nextBid = $cprice + $incprice;
$stmt23 = $pdo->prepare("SELECT * FROM user WHERE username = :username");
$stmt23->bindParam(":username", $owner,PDO::PARAM_STR);
$stmt23->execute();
$thisuser = $stmt23->fetch(PDO::FETCH_ASSOC);
$location = $thisuser['location'];
echo'
<tr class="resultindex">
<td class="imgCol"><img src="'.$img.'" alt="'.$name.'" /></td>
<td class="infoCol">
<div class="nameDiv">
<a class="nameLink" href="displayAuct.php?id='.$ID.'">'.$name.'</a><br/>
</div>
<div class="descDiv">
<span class="priceLabel2">'.$desc.'</span>
</div>
<div class="userdiv">
<span class="fromuser">Location: </span><br/>
<span class="location">'.$location.'</span>
</div>
</td>
<td style="width:1px; background-color:#330066;" ></td>
<td class="priceCol">
<div class="currentp"><span class="priceLabel">Current Bid: </span><br/><span class="price1">$'.$cprice.'</span></div>
<div class="instantp"><span class="priceLabel2">Instant Sale: </span><br/><span class="price2">$'.$iprice.'</span></div>
<div style="height:5px;"></div>
<div class="incp"><span class="priceLabel2">Next Bid:</span><br/><span class="price2">$'.$nextBid.'</span></div>
</td>
<td style="width:1px; background-color:#330066;"></td>
<td class="timerCol">
<div id="timeRow">
<span class="timeleft">Time Left: </span>
</div>
<div id="countdownRow"></div>
<script type=text/javascript>
var timestamp = '. $etime * 1000 .';
var endTime = new Date();
endTime.setTime(timestamp);
$("#countdownRow").countdown({until: endTime});
</script>
</td>
</tr>
';
}
$pdo = null;
}catch(PDOException $e){
echo $e->getMessage();
}
}
?>
</table>
</div>
<div id="sitemap">
</div>
</div>
</center>
</body>
</html>
Your SQL is slightly off, you have an extra * in your DELETE. It would make no sense to give a column list, since DELETE always deletes a whole row;
DELETE * FROM auction WHERE etime < :time
should be
DELETE FROM auction WHERE etime < :time
I'm being thrown an error
You are not.
In fact, you are being thrown a way more informative error message, including the exact spot where the error occurred. But for some reason you are using the code that strips all the useful info down, throwing naked error message at you.
can't find source
If you get rid of these try and catch operators, you will make yourself quite informed of the exact query where error occurred.

Categories