mysql_fetch_array没有检索php邮件的结果

时间:2015-12-29 21:23:06

标签: php html mysql

我正在尝试将乘客位置发送给司机电子邮件。由于某种原因,$loc变量未获取该位置。当用户提交表单时,它会获取乘客姓名,然后$search_loc['location']应该从选项标签中选择的该名称的db获取位置。谢谢你的帮助。

<?php
$host="localhost"; // Host name 
$username="hidden"; // Mysql username 
$password="hidden"; // Mysql password 
$db_name="hidden"; // 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");

//names of the passengers in option tags
$name = $_POST['name'];

//this query gets all the records from pickuprequests of the passenger selected
$query="SELECT * FROM $tbl_name WHERE name = '$name'";
$result=mysql_query($result, $link);

// get the location of the passenger from $result
$search_loc = mysql_fetch_array($query, $link);
$loc = $search_loc['location'];


//find how many rows are returned with the passenger name
$search_row = mysql_query($query, $link);
$count = mysql_num_rows($search_row, $link);

//deletes a record assoc with passenger name
$delete_query = "DELETE FROM pickuprequests WHERE name = '$name'";

/* THIS IS CODE THAT HAS BEEN COMMENTED OUT
$altloc = $_POST['altloc'];
$time = $_POST['time'];
*/

//message for the passenger
$msg_passenger = "Your driver is on the way! You will receive one last email when the driver arrives.";
$subject_passenger = "Driver on the way";
$mailheaders = "From: TripoZipo <tripozipo.com> \r\n";

//passengers email
$search_email = mysql_fetch_array($result, $link);
$email = $search_email['email']; // this wont get the passengers email as well

//message for the driver
$msg_driver = "".$name." is located at".$loc.""; // the problem is that this wont display loc in email
$subject_driver = "Passenger Location";

//drivers email is the session name for driver.php
$driver = $_SESSION['driver'];

//on submit and if a passenger is selected run code
if(isset($_POST['submit']) && isset($_POST['name'])) {

    //$count returns all the rows assoc with passenger name
    if($count) {
    mail($email, $subject_passenger, $msg_passenger, $mailheaders); // email passenger your ride is on the way
    mail($driver, $subject_driver, $msg_driver, $mailheaders); // email driver the location
    //mysql_query($delete_query, $link); // finally delete the request as its not pending anymore
    echo "<script type='text/javascript'> document.location = 'http://mobile.tripozipo.com/confirmation2.php'; </script>";
    }
    else {  //else if no rows are returned
    mail($email, $subject_passenger, $msg_passenger, $mailheaders); // email passenger your ride is on the way
    mail($driver, $subject_driver, $msg_driver, $mailheaders); // email driver the location
    //mysql_query($delete_query, $link); // delete pickup request so its no longer available
    echo "<script type='text/javascript'> document.location = 'http://mobile.tripozipo.com/confirmation2.php'; </script>";

    }
}
?>

0 个答案:

没有答案