Reputation:
Let me break down this page for you guys. Its called driver.php and the objective of this page is for a driver to pick up pending pick up requests from passengers (requests will show in options tags as their emails). THE ISSUE is that the DELETE QUERY is not working for some reason. I want to be able to delete the existing pickup request for table when a driver gets it. YES I've searched on this website for answers and google for help that is why I am posting here. Thank you all for your help.
<? session_start(); ?>
<?php
if(!isset($_SESSION['driver'])) {
header('Location: mobile.php');
exit;
}
?>
<!DOCTYPE html>
<html>
<head>
<script>
<!--This redirects the user to our mobile view-->
if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
} else {
window.location = "http://tripozipo.com/index.php";
}
</script>
<!--This is for mobile JQuery-->
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.timeentry.css">
<script type="text/javascript" src="js/jquery.plugin.js"></script>
<script type="text/javascript" src="js/jquery.timeentry.js"></script>
<?php
$host="localhost"; // Host name
$username="fakename"; // Mysql username
$password="fakepass"; // Mysql password
$db_name="fakedbname"; // Database name
$tbl_name="pickuprequests"; // Table name
// Connect to server and select database.
$link = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name", $link)or die("cannot select DB");
$email = $_POST['email'];
//this query gets all the records from pickuprequests so we can use mysql fetch array to ouput
//the emails (of ppl asking for rides) in the html option tags
$search_for_email="SELECT * FROM $tbl_name";
$result_for_email=mysql_query($search_for_locations, $link);
//get all the data in the table assoc with the email that the driver chooses
//this is so we can get the location assoc with the email for mailing purposes ect
$search_for_loc="SELECT * FROM $tbl_name WHERE email = '$email'";
$result_for_loc=mysql_query($search_for_loc, $link);
//get the loc assoc with the email and set it to loc variable for mailing purposes ect
$loc = mysql_fetch_array($result_for_loc);
$loc = $loc['location'];
//find how many rows are returned with that email assoc with that loc
//because if there is already a duplicate pickup request we want to delete it
$query="SELECT * FROM $tbl_name WHERE email = '$email' AND location = '$loc'";
$queryresult = mysql_query($query, $link);
$count=mysql_num_rows($queryresult);
//this query is so we can delete the records from pickup assoc with email (person that request ride)
$delete_query = "DELETE * FROM pickuprequests WHERE email = $email";
/* THIS IS CODE THAT HAS BEEN COMMENTED OUT
$altloc = $_POST['altloc'];
$time = $_POST['time'];
*/
$msg = "Your driver is on the way! You will receive one last email when the driver arrives.";
$subject = "Pickup Request";
$mailheaders = "From: TripoZipo <tripozipo.com> \r\n";
$driver = $_SESSION['driver'];
//When the driver chooses a pickup request and hits submit then delete the pick up request from the table
//'pickuprequests' so that another driver cant choose it, because its already been accepted
if(isset($_POST['submit']) && isset($_POST['email'])) {
//if we find data in row return then there must already be a pick request
//if there is then we want to delete that request but its not working
if($count) {
mysql_query($delete_query, $link);
/* THIS IS CODE THAT HAS BEEN COMMENTED OUT
mail($email, $subject, $msg, $mailheaders);
mail($driver, "Pickup Address", "Here is the location: ".$loc, $mailheaders);
echo "<script type='text/javascript'> document.location = 'http://mobile.tripozipo.com/confirmation.php'; </script>";
*/
}
else
/* THIS IS CODE THAT HAS BEEN COMMENTED OUT
mail($email, $subject, $msg, $mailheaders);
mail($driver, "Pickup Address", "Here is the location: ".$loc, $mailheaders);
echo "<script type='text/javascript'> document.location = 'http://mobile.tripozipo.com/confirmation.php'; </script>";
*/
}
?>
</head>
<body>
<div data-role="page">
<div class="ui-content" align="center">
<img src="images/logo.png" style="height:100px; width: 202px;">
<h2>Hello <?php echo("{$_SESSION['driver']}"); ?>, welcome to your dashboard</h2>
<form method="post" action="driver.php" data-ajax="false">
<label for="location">Here are some pending pickups</label>
<select name="email">
<?php while ($row1=mysql_fetch_array($result_for_email)) {
$title = $row1['email'];
echo "<option>$title</option>";
}
?>
</select>
<?php
if(isset($_POST['submit'])) {
if(!$count) {
echo "<b style='color: red;'>Oops! It looks like someone else took it</b>";
}}?>
<input type="submit" name="submit" value="Take">
<p align="center">Or</p>
<a href="logout.php"><input type="button" value="Log Out"></a>
<a href="mobile.php"><input type="button" value="Back"></a>
</form>
</div>
</div>
</body>
</html>
Upvotes: 0
Views: 1488
Reputation: 367
$delete_query = "DELETE * FROM pickuprequests WHERE email = $email";
It should be..
$delete_query = "DELETE FROM pickuprequests WHERE email = '{$email}'";
Note... You dont have to declare that you want to delete all from that row, if you find it with id, email or something (WHERE clausule) it will automaticly delete that row. So no need for * symbol.
Upvotes: 0
Reputation: 16963
There are small bugs in your code. Remove *
from the delete query and surround your strings inside quotes(' '
), like this:
$delete_query = "DELETE FROM pickuprequests WHERE email = '$email'";
Check for errors on your queries when testing:
Sidenote: Please don't use mysql_
database extensions, they were deprecated in PHP 5.5.0 and were removed in PHP 7.0.0. Use mysqli
or PDO
extensions instead. And this is why you shouldn't use mysql_
functions
Upvotes: 3
Reputation: 463
$delete_query = "DELETE * FROM pickuprequests WHERE email = $email";
should be?
$delete_query = "DELETE * FROM pickuprequests WHERE email = '$email'";
Single Quotes?
Upvotes: 0