Hi guys i have a from where user is going to select a course from drop down and second input user will select expired date that should be optional.so when user didn't give date it is showing error as Your Due date should be in future.
I don't know why it is showing like that if i didn't give any date in input field also.
here is my code:
if (isset($_POST['assigncourse'])) {
$courseid = $_POST['courseid'];
//$duedate = date('Y-m-d', strtotime($_POST['duedate']));
$duedate = strtotime($_POST['duedate']);
$now = strtotime(date('Y-m-d'));
if ($now < $duedate)
{
$courseid = required_param('courseid', PARAM_TEXT);
$groupid = required_param('groupid', PARAM_TEXT);
$insert_record = new stdClass();
$insert_record->courseid = $courseid;
$insert_record->groupid = $_SESSION['groupid'];
$insert_record->duedate = $duedate;
$insert_record->createdby= $id;
$insert_record->createdon = date('Y-m-d H:i:s');
$sql1 = "SELECT *
FROM mdl_ppc_assigncourses_group
WHERE groupid='".$_SESSION['groupid']."'
AND courseid='$courseid'";
$courses = $DB->get_records_sql($sql1);
if (count($courses) > 1) {
$errorMessage = "The course already taken!";
} else {
$DB->insert_record('ppc_assigncourses_group', $insert_record);
}
} else {
$errorMessage = "Your Due date should be in future.";
}
}
Here is my form:
<!-- /.card-header -->
<form class="form-horizontal" id="sign-in" style="margin-left: -2px; padding: 15px 15px 0px 15px" method="post" role="form" data-parsley-validate="" novalidate="">
<input type="hidden" name="groupid" class="col-md-12 form-control" id="inputEmail3" required="" value="<?php echo $_SESSION['groupid']; ?>" >
<!-- select -->
<input type="hidden" name="depid" class="col-md-12 form-control" id="inputEmail3" required="" value="<?php echo $_SESSION['depid']; ?>" >
<div class="form-group">
<label>Choose Course</label>
<select name="courseid" id="courseid" class="form-control" required>
<?php
$sql = "select id,fullname from {course} where id!='1' ";
$courses = $DB->get_records_sql($sql);
?>
<option value="">Choose Course</option>
<?php
if (sizeof($courses)): foreach ($courses as $row):
$coursename = $row->fullname;
?>
<option value="<?php echo $row->id; ?>"><?php echo $row->fullname; ?></option>
<?php
endforeach;
endif;
?>
</select>
</div>
<div class="form-group label-floating">
<label class="control-label">Due Date</label>
<input type="text" class="form-control" id="datepicker" name="duedate" >
</div>
<div class="form-group">
<button type="submit" name="assigncourse" id="submit" class="btn btn-info form-control">Assign</button>
</div>
</form>
Can anyone help me what mistake i have done.
Thanks in advance.
The problem is if duedate is not set. $now cannot be smaller than duedate.
This line:
if ($now < $duedate)
you will have to change. Make it so it looks if $duedate is set in first place.
if (isset($_POST['assigncourse'])) {
$courseid = $_POST['courseid'];
//$duedate = date('Y-m-d', strtotime($_POST['duedate']));
if(isset($_POST['duedate']) && ($_POST['duedate'] != "")) {
$duedate = strtotime($_POST['duedate']);
}
else {
$duedate = false;
}
$now = strtotime(date('Y-m-d'));
if ((!$duedate) || ($now < $duedate))
{
$courseid = required_param('courseid', PARAM_TEXT);
$groupid = required_param('groupid', PARAM_TEXT);
$insert_record = new stdClass();
$insert_record->courseid = $courseid;
$insert_record->groupid = $_SESSION['groupid'];
if(is_numeric($duedate)) {
$insert_record->duedate = $duedate;
}
else {
$insert_record->duedate = time();
}
$insert_record->createdby= $id;
$insert_record->createdon = date('Y-m-d H:i:s');
$sql1 = "SELECT *
FROM mdl_ppc_assigncourses_group
WHERE groupid='".$_SESSION['groupid']."'
AND courseid='$courseid'";
$courses = $DB->get_records_sql($sql1);
if (count($courses) > 1) {
$errorMessage = "The course already taken!";
} else {
$DB->insert_record('ppc_assigncourses_group', $insert_record);
}
} else {
$errorMessage = "Your Due date should be in future.";
}
}
ViewPage:
<td><?php if($duedate > 0) { echo date('Y-M-d',$duedate); } ?></td>
You need to check if the $duedate has a value. You would do that like this.
if(isset($duedate) && $duedate){
if(strtotime($now) < strtotime($duedate)){
echo 'Do something';
}else{
echo 'Do something else.';
}
}else{
echo 'You need to enter a due date.';
}
Your code would look like this:
if (isset($_POST['assigncourse'])) {
$courseid = $_POST['courseid'];
//$duedate = date('Y-m-d', strtotime($_POST['duedate']));
//$duedate = strtotime($_POST['duedate']);
$now = date('Y-m-d');
if(isset($_POST['duedate']) && $_POST['duedate']){
if(strtotime($now) < strtotime($_POST['duedate']))
{
$courseid = required_param('courseid', PARAM_TEXT);
$groupid = required_param('groupid', PARAM_TEXT);
$insert_record = new stdClass();
$insert_record->courseid = $courseid;
$insert_record->groupid = $_SESSION['groupid'];
$insert_record->duedate = $duedate;
$insert_record->createdby= $id;
$insert_record->createdon = date('Y-m-d H:i:s');
$sql1 = "SELECT *
FROM mdl_ppc_assigncourses_group
WHERE groupid='".$_SESSION['groupid']."'
AND courseid='$courseid'";
$courses = $DB->get_records_sql($sql1);
if (count($courses) > 1) {
$errorMessage = "The course already taken!";
}else{
$DB->insert_record('ppc_assigncourses_group', $insert_record);
}
}else{
$errorMessage = "Your Due date should be in future.";
}
}
}
Related
Help please, am trying to validate a form date input not empty and should not be greater that today's date. this is what I did so far. am getting 000-00-00 inserted in MySQL db. what am I doing wrong?
here is what in the form input
<div class="form-group">
<label>Join Date</label>
<input type="date" name="joindate" class="form-control <?php echo (!empty($joindate_err)) ? 'is-invalid' : ''; ?> " value="<?php echo $joindate ?>">
<span class="invalid-feedback"><?php echo $joindate_err; ?></span>
</div>
the php tag above has this validations
//date validation
$input_joindate = trim($_POST["joindate"]);
if (empty($input_joindate)) {
$joindate_err = "Select join date";
}
if (!empty($input_joindate)) {
$input_joindate = date('Y-m-d', strtotime($input_joindate));
$today = strtotime("now");
if (($input_joindate) > $today)
$joindate_err = "Date should not be in the future";
} else {
$joindate = $input_joindate;
}
<?php
$today = date("Y-m-d");
$joindate = $_POST["joindate"];
if (empty($joindate) || !isset($joindate)) {
$joindate_err = "Select join date";
} elseif (strtotime($today) < strtotime($joindate)) {
$joindate_err = "Date should not be in the future";
}
I don't really know how to explain my question, but I am in need. Of how to display warning before update into database.
example:
<?php
#Get id and yes before update waring code
if (isset($_GET["acept"])) {
$acept = $_GET["acept"];
} else {
$acept = " ";
}
if ($acept == "update") {
if (isset($_GET["yes"]) & $_GET["yes"] == true) {
$id = (int)$_GET["id"];
$query = mysqli_query($conn, "update users set balance='$redut' where id='$id'");
if ($query) {
echo " Successfull";
} else {
echo "retry";
}
exit();
}
$id = (int)$_GET["id"];
echo "<div class='topnav'>System Warning</div><div class='msg'>Are You Sure ?</div><div class='gap'></div><div class='button'><a href='?acept=update&yes=true&id=$idd'><font color='red'>Yes</font></a> | <a href='user.php'>No</a></div>";
}
here is my full code where I am trying to display the warning before updating into database
<?php
include_once 'init.php';
$error = false;
// check if form is submitted
if (isset($_POST['book'])) {
$book = mysqli_real_escape_string($conn, $_POST['book']);
$action = mysqli_real_escape_string($conn, $_POST['action']);
if (strlen($book) < 6) {
$error = true;
$book_error = "booking code must be alist 6 in digit";
}
if (!is_numeric($book)) {
$error = true;
$book_error = "Incorrect booking code";
}
if (empty($_POST["action"])) {
$error = true;
$action_error = "pick your action and try again";
}
if (!$error) {
if (preg_match('/(check)/i', $action)) {
echo "6mameja";
}
if (preg_match('/(comfirm)/i', $action)) {
if (isset($_SESSION["user_name"]) && (trim($_SESSION["user_name"]) != "")) {
$username = $_SESSION["user_name"];
$result = mysqli_query($conn, "select * from users where username='$username'");
}
if ($row = mysqli_fetch_array($result)) {
$idd = $row["id"];
$username = $row["username"];
$id = $row["id"];
$username = $row["username"];
$ip = $row["ip"];
$ban = $row["validated"];
$balance = $row["balance"];
$sql = "SELECT `item_name` , `quantity` FROM `books` WHERE `book`='$book'";
$query = mysqli_query($conn, $sql);
while ($rows = mysqli_fetch_assoc($query)) {
$da = $rows["item_name"];
$qty = $rows["quantity"];
$sqll = mysqli_query($conn, "SELECT * FROM promo WHERE code='$da' LIMIT 1");
while ($prow = mysqli_fetch_array($sqll)) {
$pid = $prow["id"];
$price = $prow["price"];
$count = 0;
$count = $qty * $price;
$show = $count + $show;
}
}
if ($show < $balance) {
echo "you cant buy here";
exit();
} elseif ($show > $balance) {
$redut = $balance - $show;
#display the warning before updating into daase if (isset($_GET["acept"])) {
$acept = $_GET["acept"];
} else {
$acept = " ";
}
if ($acept == "update") {
if (isset($_GET["yes"]) & $_GET["yes"] == true) {
$id = (int)$_GET["id"];
$query = mysqli_query($conn, "update users set balance='$redut' where id='$id'");
if ($query) {
echo " Successfull";
} else {
echo mysql_error();
}
exit();
}
$idd = (int)$_GET["id"];
echo "<div class='topnav'>System Warning</div><div class='msg'>Are You Sure ?</div><div class='gap'></div><div class='button'><a href='?acept=update&yes=true&id=$idd'><font color='red'>Yes</font></a> | <a href='user.php'>No</a></div>";
}
}
} else {
$errormsg = "Error in registering...Please try again later!";
}
}
}
}
?>
<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="booking">
<fieldset>
<legend>Check Booking</legend>
<div class="form-group">
<label for="name">Username</label>
<input type="text" name="book" placeholder="Enter Username" required value="<?php if($error) echo $book; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($book_error)) echo $book_error; ?></span>
</div>
<input type="submit" name="booking" value="Sign Up" class="btn btn-primary" />
<table><input type="radio" name="action" value="comfirm" <?php if(isset($_POST['action']) && $_POST['action']=="comfirm") { ?>checked<?php } ?>>
<input type="radio" name="action" value="check" <?php if(isset($_POST['action']) && $_POST['action']=="check") { ?>checked<?php } ?>> Check booking <span class="text-danger"><?php if (isset($action_error)) echo $action_error; ?></span>
</div></table>
I don't really know where am wrong with the code, but the expected warning before update do not display and the database is not updated. big thanks in advance.
if (isset($_GET["yes"]) & $_GET["yes"] == true) {
change this to
if (isset($_GET["yes"]) && $_GET["yes"] == 'true') {
servers take the GET method as a string. not boolean
I don't really get what kind of warning you are trying to display. If it is for a user you can use the print or echo function. It is possible to echo a block of html so:
echo '<div class=”warning-msg”><p>MY WARNING</p></div>'
will display the block. Only thing is the warning may not be in de correct place or time.
Or in js
echo ‘<script type="text/javascript">’
echo ‘alert(“message successfully sent”)’
echo ’</script>’
If the waring is for jou personal use the build in php error handeling handeling.
Here is a snippet for a query function using php.
Use:
$query = query("SELECT ... (SQL)", $variable);
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I keep getting a Parse error: syntax error, unexpected end of file error at line 167. I have gone through this code many times and can't seem to find what I'm missing. I've checked all of the brackets and statements and don't find anything off. Can the error possibly be from the
#!/usr/local/bin/php -d display_errors=STDOUT
<?php
date_default_timezone_set('America/Los_Angeles');
$time_stamp = time();
$disp = $_GET['time_stamp'];
if($disp == "previous")
$time_stamp -= 43200;
else if($disp == "next")
$time_stamp += 43200;
$today = date("D, F j, Y, g:i a",$time_stamp);
$start_hour_offset = -3;
$end_hour = 12;
$table = "event_table";
$field1 = "person";
$field2 = "time";
$field3 = "event_title";
$field4 = "event_message";
try
{
$db = new SQLite3('dbalexmf14.db');
}
catch (Exception $exception)
{
echo '<p>There was an error connecting to the
database!</p>';
if ($db)
{
echo $exception->getMessage();
}
}
/**function get_events($name, $ts){
$sql = "SELECT * FROM event_table WHERE person = $name, time = $ts || time <= $ts + 3600";
print "$sql";
$result = $db->query($sql);
while($record=$result->fetchArray())
{ $title = $record['event_title'];
$message = $record['event_message'];
$a_events= $title. " ". $message;
}**/
function get_hour_string($time_stamp){
$hour = date("g", $time_stamp);
$am_or_pm = date("a",$time_stamp);
return "$hour.00$am_or_pm";
}
print('<?xml version = "1.0" encoding="utf-8"?> ');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Calendar</title>
<link rel="stylesheet" type="text/css" href="calendar.css" />
</head>
<body>
<div class="container">
<h1>Bruin Family Schedule for <?php print"$today" ?> </h1>
<table id="event_table">
<?php
// print the header
print " <tr> \n";
print " <th class='hr_td_'> </th> <th class='table_header'>Alex</th><th class='table_header'>Ashton</th><th class='table_header'>Joshua</th> \n";
print " </tr> \n";
for ($i=0; $i<=$end_hour;++$i)
{
$hour_string = get_hour_string($time_stamp + $i*3600);
if ($i%2 == 0){
print "<tr class='even_row'>\n";
print "<td class='hr_td'>$hour_string</td> <td> </td> <td> </td> <td></td>\n";
}
if ($i%2 !=0){
print "<tr class='odd_row'>\n";
print "<td class='hr_td'>$hour_string</td> <td> </td> <td> </td> <td> </td>\n";
}
$sql = "SELECT * FROM event_table WHERE person = 'Alex', time = $ts || time <= $ts + 3600";
print "$sql";
$result = $db->query($sql);
$a_events="";
$j_events="";
$ah_events="";
while($record=$result->fetchArray())
{ $title = $record['event_title'];
$message = $record['event_message'];
$a_events= $title. " ". $message;
}
$sql = "SELECT * FROM event_table WHERE person = 'Ashton', time = $ts || time <= $ts + 3600";
print "$sql";
$result = $db->query($sql);
while($record=$result->fetchArray())
{ $title = $record['event_title'];
$message = $record['event_message'];
$ah_events= $title. " ". $message;
$sql = "SELECT * FROM event_table WHERE person = 'Joshua', time = $ts || time <= $ts + 3600";
print "$sql";
$result = $db->query($sql);
while($record=$result->fetchArray())
{ $title = $record['event_title'];
$message = $record['event_message'];
$j_events= $title. " ". $message;
//$a_events = get_events("Alex", $time_stamp);
//$ah_events = get-events("Ashton", $time_stamp);
//$j_events = get_events("Joshua", $time_stamp);
print "<td>$a_events</td><td>$j_events</td><td>$ah_events</td>";
print " </tr> \n";
?>
</table>
<div>
<form id="prev" method="get" action="calendar2.php">
<p>
<input type="hidden" name="time_stamp" value='previous' />
<input type="submit" value="Previous"/>
</p>
</form>
<form id="next" method="get" action="calendar2.php">
<p>
<input type="hidden" name="time_stamp" value='next' />
<input type="submit" value="Next"/>
</p>
</form>
<form id="today" method="get" action="calendar2.php">
<p>
<input type="submit" value="Today"/>
</p>
</form>
</div>
</div>
</body>
</html>
It seems that you are not properly closed the curly braces in your code.
Try Following
<?php
date_default_timezone_set('America/Los_Angeles');
$time_stamp = time();
$disp = $_GET['time_stamp'];
if($disp == "previous")
$time_stamp -= 43200;
else if($disp == "next")
$time_stamp += 43200;
$today = date("D, F j, Y, g:i a",$time_stamp);
$start_hour_offset = -3;
$end_hour = 12;
$table = "event_table";
$field1 = "person";
$field2 = "time";
$field3 = "event_title";
$field4 = "event_message";
try
{
$db = new SQLite3('dbalexmf14.db');
}
catch (Exception $exception)
{
echo '<p>There was an error connecting to the
database!</p>';
if ($db)
{
echo $exception->getMessage();
}
}
/**function get_events($name, $ts){
$sql = "SELECT * FROM event_table WHERE person = $name, time = $ts || time <= $ts + 3600";
print "$sql";
$result = $db->query($sql);
while($record=$result->fetchArray())
{ $title = $record['event_title'];
$message = $record['event_message'];
$a_events= $title. " ". $message;
}**/
function get_hour_string($time_stamp){
$hour = date("g", $time_stamp);
$am_or_pm = date("a",$time_stamp);
return "$hour.00$am_or_pm";
}
print('<?xml version = "1.0" encoding="utf-8"?> ');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>Calendar</title>
<link rel="stylesheet" type="text/css" href="calendar.css" />
</head>
<body>
<div class="container">
<h1>Bruin Family Schedule for <?php print"$today" ?> </h1>
<table id="event_table">
<?php
print " <tr> \n";
print " <th class='hr_td_'> </th> <th class='table_header'>Alex</th><th class='table_header'>Ashton</th><th class='table_header'>Joshua</th> \n";
print " </tr> \n";
for ($i=0; $i<=$end_hour;++$i)
{
$hour_string = get_hour_string($time_stamp + $i*3600);
if ($i%2 == 0){
print "<tr class='even_row'>\n";
print "<td class='hr_td'>$hour_string</td> <td> </td> <td> </td> <td></td>\n";
}
if ($i%2 !=0){
print "<tr class='odd_row'>\n";
print "<td class='hr_td'>$hour_string</td> <td> </td> <td> </td> <td> </td>\n";
}
$sql = "SELECT * FROM event_table WHERE person = 'Alex', time = $ts || time <= $ts + 3600";
print "$sql";
$result = $db->query($sql);
$a_events="";
$j_events="";
$ah_events="";
while($record=$result->fetchArray())
{ $title = $record['event_title'];
$message = $record['event_message'];
$a_events= $title. " ". $message;
}
$sql = "SELECT * FROM event_table WHERE person = 'Ashton', time = $ts || time <= $ts + 3600";
print "$sql";
$result = $db->query($sql);
while($record=$result->fetchArray())
{ $title = $record['event_title'];
$message = $record['event_message'];
$ah_events= $title. " ". $message;
$sql = "SELECT * FROM event_table WHERE person = 'Joshua', time = $ts || time <= $ts + 3600";
print "$sql";
$result = $db->query($sql);
while($record=$result->fetchArray())
{ $title = $record['event_title'];
$message = $record['event_message'];
$j_events= $title. " ". $message;
//$a_events = get_events("Alex", $time_stamp);
//$ah_events = get-events("Ashton", $time_stamp);
//$j_events = get_events("Joshua", $time_stamp);
print "<td>$a_events</td><td>$j_events</td><td>$ah_events</td>";
print " </tr> \n";
}
}
}
?>
</table>
<div>
<form id="prev" method="get" action="calendar2.php">
<p>
<input type="hidden" name="time_stamp" value='previous' />
<input type="submit" value="Previous"/>
</p>
</form>
<form id="next" method="get" action="calendar2.php">
<p>
<input type="hidden" name="time_stamp" value='next' />
<input type="submit" value="Next"/>
</p>
</form>
<form id="today" method="get" action="calendar2.php">
<p>
<input type="submit" value="Today"/>
</p>
</form>
</div>
</div>
</body>
</html>
<div class="control-group">
<label class="control-label" for="inputPassword">School Year:</label>
<div class="controls">
<select name="year" required>
<option></option>
<?php
$query = mysql_query("select * from school_year");
while($row = mysql_fetch_array($query)){
?>
<option><?php echo $row['school_year']; ?></option>
<?php } ?>
</select>
</div>
</div>
<?php
if (isset($_POST['save'])){
$day = $_POST['day'];
$time = $_POST['time'];
$room = $_POST['room'];
$subj = $_POST['subj'];
$sect = $_POST['sect'];
$inst = $_POST['inst'];
$sems = $_POST['sems'];
$year = $_POST['year'];
$notification = 'New Proctoring Schedule on '." ".'<b>'.$day.'</b>'." - ".'<b>'.$time.'</b>'.' at '.$room.'<br>'.$subj. ' - '.$sect.' - '.$sems.' Semester.';
$query = mysql_query("select * from schedule where day = '$day' and time = '$time' and room = '$room' ")or die(mysql_error());
$count = mysql_num_rows($query);
if ($count > 0){
echo "Hello world!";
?>
<?php
}else{
mysql_query("insert into schedule (day,time,room,subject,section,proctor,semester, schoolyear) values('$day','$time','$room','$subj','$sect','$inst','$sems','$year')");
mysql_query("insert into notification (teacher_class_id,notification,date_of_notification,link) value('$inst','$notification',NOW(),'dasboard_teacher.php')");
mysql_query("insert into activity_log (date,username,action) values(NOW(),'$user_username','Add Exam Schedule $subj - $sect')")or die(mysql_error());
?>
<script>
window.location = "exam.php";
</script>
<?php
}
}
?>
Try this
<?php
$flag=0;
if (isset($_POST['save'])){
$day = $_POST['day'];
$time = $_POST['time'];
$room = $_POST['room'];
$subj = $_POST['subj'];
$sect = $_POST['sect'];
$inst = $_POST['inst'];
$sems = $_POST['sems'];
$year = $_POST['year'];
$notification = 'New Proctoring Schedule on '." ".'<b>'.$day.'</b>'." - ".'<b>'.$time.'</b>'.' at '.$room.'<br>'.$subj. ' - '.$sect.' - '.$sems.' Semester.';
$query = mysql_query("select * from schedule where day = '$day' and time = '$time' and room = '$room' ")or die(mysql_error());
$count = mysql_num_rows($query);
if ($count > 0){
echo "Hello world!";
$flag=1;
}else{
mysql_query("insert into schedule (day,time,room,subject,section,proctor,semester, schoolyear) values('$day','$time','$room','$subj','$sect','$inst','$sems','$year')");
mysql_query("insert into notification (teacher_class_id,notification,date_of_notification,link) value('$inst','$notification',NOW(),'dasboard_teacher.php')");
mysql_query("insert into activity_log (date,username,action) values(NOW(),'$user_username','Add Exam Schedule $subj - $sect')")or die(mysql_error());
header("location:exam.php");
}
}
?>
<div class="control-group">
<label class="control-label" for="inputPassword">School Year:</label>
<div class="controls">
<select name="year" required>
<option></option>
<?php
$query = mysql_query("select * from school_year");
while($row = mysql_fetch_array($query)){
?>
<option <?php if(isset($_POST['year']) && $row['school_year'] == $_POST['year']) { echo "selected='selected' "; } ?> value="<?php echo $row['school_year'] ?>"> <?php echo $row['school_year']; ?></option>
<?php } ?>
</select>
</div>
<?php if($flag==1){ ?>
<div class="error">Data already present in database</div>
<?php } ?>
</div>
I'm working on news archive page for my website, search over archive is done with start date, end date and news category as search parameters. Form values are stored in $_SESSION var, and then they are passed around as an array for pagination and other purposes.
My question would be how to prevent displaying search results on main archive search page if user for some reason goes again to it to make a new search.
here's the code
<?php
session_start();
if (isset($_POST['submit'])) {
//get data from the form
$archFld_1 = $_POST['archiveFld1'];
$archFld_2 = $_POST['archiveFld2'];
$archFld_3 = $_POST['archiveFld3'];
//just some check on fields
if (strlen($archFld_1) > 10) { $archFld_1 = ""; }
if (strlen($archFld_2) > 10) { $archFld_2 = ""; }
//save them as a array and store to session var
$_archValues = array($archFld_3, $archFld_1, $archFld_2);
$_SESSION['storeValues'] = $_archValues;
}
if (isset($_SESSION['storeValues'])) {
//check params for search
//set cat for query
if ($_SESSION['storeValues'][0] > 0) { $valCat = "AND newsCat=". $_SESSION['storeValues'][0] ." "; } else { $valCat = ""; }
//set date for query
if(($_SESSION['storeValues'][1] != "" ) && ($_SESSION['storeValues'][2] == "")) {
$DateStart = $_SESSION['storeValues'][1];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') >= STR_TO_DATE('$DateStart', '%d-%m-%Y') ";
}
if(($_SESSION['storeValues'][2] != "") && ($_SESSION['storeValues'][1]=="")) {
$DateEnd = $_SESSION['storeValues'][2];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') <= STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
}
if(($_SESSION['storeValues'][1]!="") && ($_SESSION['storeValues'][2] != "")) {
$DateStart = $_SESSION['storeValues'][1];
$DateEnd = $_SESSION['storeValues'][2];
$valDate = " AND STR_TO_DATE(newsDate, '%d-%m-%Y') BETWEEN STR_TO_DATE('$DateStart', '%d-%m-%Y') AND STR_TO_DATE('$DateEnd', '%d-%m-%Y') ";
}
//query string and stire it to session
$archQuery_string = $valCat.$valDate;
$_SESSION['storeQuery'] = $archQuery_string;
}
//pagination start
$page = $_GET['id'];
$perPage = 10;
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION["storeQuery"] ."ORDER BY newsId DESC");
$totalPages = mysql_num_rows($result);
if(!$page)
$page = 1;
$start = ($page - 1)*$perPage;
?>
<div id="sps_middle">
<div class="sps_cnt">
<div id="sps_middle_ly1">
<div class="sps_cnt_small">
<div class="sps_page_title"><h3><?php echo $wb_lng['txtArchiveTitle']; ?></h3></div>
<div class="sps_pages_cnt" style="padding-top: 10px; float: left; margin-bottom: 15px;">
<div class="sps_middle_col01">
<div style="float: left;">
<p>
<?php echo $wb_lng['txtArchiveInfo']; ?>
</p>
<form action="<?php $PHP_SELF; ?>" method="post" name="archiveForm" class="archiveForm">
<ul>
<li>
<input name="archiveFld1" type="text" id="archiveFld1" value="<?php echo $wb_lng['txtArhivaFld_01']; ?>" />
<input name="archiveFld2" type="text" id="archiveFld2" value="<?php echo $wb_lng['txtArhivaFld_02']; ?>" />
<select name="archiveFld3">
<option value="0"><?php echo $wb_lng['txtArhivaFld_07']; ?></option>
<option value="0" ><?php echo $wb_lng['txtArhivaFld_06']; ?></option>
<option value="1"><?php echo $wb_lng['txtArhivaFld_03']; ?></option>
<option value="2"><?php echo $wb_lng['txtArhivaFld_04']; ?></option>
<option value="3"><?php echo $wb_lng['txtArhivaFld_05']; ?></option>
</select>
</li>
<li style="float: right;">
<input name="reset" type="reset" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormReset']; ?>"/>
<input name="submit" type="submit" class="sps_archiveform_btn" value="<?php echo $wb_lng['txtArchiveFormSend']; ?>"/>
</li>
</ul>
</form>
</div>
<hr />
<?php
if (#HERE GOES SOME CODE TO PERFORM THE CHECK!!!#) {
//perform db query
$result = wbQuery("SELECT * FROM wb_news WHERE newsLang=1 ". $_SESSION['storeQuery'] ."ORDER BY newsId DESC LIMIT $start, $perPage");
//count rows
$totalnews = mysql_num_rows($result);
$count = 1;
if($totalnews == 0) {
//no results, say to the user
echo "\t\t\t<div class=\"cil_news_text_big\">\n\t\t\t\t".$wb_lng['txtArchiveNoEntries']."\n\t\t\t</div>\n";
} else {
//we have results, yeeeeeeeeey
while($ROWnews = mysql_fetch_object($result)){
//set link extensions by the news cat
switch ($ROWnews->newsCat) {
case 1:
$newsCat_link = "news";
break;
case 2:
$newsCat_link = "statements";
break;
case 3:
$newsCat_link = "events";
break;
}
//text summary
if (strlen($ROWnews->newsShort) > 0 ) {$newsShortTxt = strip_tags($ROWnews->newsShort);
if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
} else {
$newsShortTxt = strip_tags($ROWnews->newsFull);
if ($lang_id==2) { $newsShortTxt = wbTranslit($newsShortTxt); }
}
$newsShortTxt = wbShorTxt($newsShortTxt, 210, "... <a title=\"".$wb_lng['txtShowMore']."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$wb_lng['txtShowMore']."...</a>");
//show news
echo "\t\t<div class=\"sps_news_list\">\n";
echo "\t\t<div class=\"sps_news_l\">\n";
echo "\t\t\t<img alt=\"\" src=\"http://".$_SERVER['HTTP_HOST']."/content/images/news/_thumb/".$ROWnews->newsImageThumb."\" />\n";
echo "\t\t</div>";
echo "\t\t<div class=\"sps_news_r\">\n";
//transliterate title
if ($lang_id==2) { $newsTitle = wbTranslit($ROWnews->newsTitle); } else { $newsTitle = $ROWnews->newsTitle; }
echo "\t\t\t<div class=\"sps_news_title\">\n\t\t\t\t<a title=\"".$newsTitle."\" href=\"http://".$_SERVER['HTTP_HOST']."/".$lang_link."/".$newsCat_link."/".$ROWnews->newsId."/full/\">".$newsTitle."</a>\n\t\t\t</div>\n";
echo "\t\t\t<div class=\"sps_news_date\">\n\t\t\t\t".$ROWnews->newsDate."\n\t\t\t</div>\n";
echo "\t\t\t<div class=\"sps_news_text_sh\">\n\t\t\t\t".$newsShortTxt."\n\t\t\t</div>\n";
echo "\t\t</div>";
echo "\t\t</div>";
//show <hr /> based on $count
if($totalnews != $count) { echo "\t\t\t<hr />\n"; }
$count++;
}
}
//pagination check
if($totalPages>$perPage) {
?>
<hr />
<div class="sps_pagginate">
<?PHP wbPageTurnFront($PHP_SELF."/".$lang_link."/archive/", $totalPages, $page, $perPage); ?>
</div>
<?php
}
}
?>
Any ideas?
Tnx :)
If user goes to make it a new search then you can clear the session at that time.
unset($_SESSION['storeValues']);