我是编程的新手。我想从数据库中获取记录的用户ID并存储在SESSION中,然后将该会话ID插入另一个表中。我想我过得很愉快,但不幸的是,有一个错误使我发疯。任何帮助,将不胜感激!
数据库btrs
具有表booking
,表的名称为coulmn
booking_id,customer_id,route_id
dbConfig.php
<?php
$dbhost = "localhost";
$dbname = "btrs";
$dbuser = "root";
$dbpass = "";
$conn =mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
?>
Logincheck.php
<?php
session_start();
include('dbConfig.php');
$error = ''; // Variable To Store Error Message
if (isset($_POST['submit'])) {
if (empty($_POST['email']) || empty($_POST['password'])) {
$error = "email or Password is invalid";
}
else {
$email = $_POST['email'];
$password = $_POST['password'];
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysql_real_escape_string($email);
$password = mysql_real_escape_string($password);
$query = mysql_query("select * from member where password='$password' AND email='$email'");
$count = mysql_num_rows($query);
if ($count > 0 ) {
$row = mysql_fetch_array(mysql_query("select * from member where password='$password' AND email='$email'"));
$id = $row['id'];
// echo $id;
$_SESSION['id']=$id;
header("location: profile.php");
} else {
$error = "Username or Password is invalid";
}
}
}
?>
booking.php
<?php
include"dbConfig.php";
include "logincheck.php";
if (isset($_POST['submit'])) {
$from1 = $_POST['from'];
$destination1 = $_POST['destination'];
$query = mysql_query("SELECT route_id FROM route WHERE pick_from='$from1' AND destination='$destination1'");
$row = mysql_fetch_array($query);
$route_id = $row['route_id'];
// echo $route_id;
if ($row!=NULL) {
$query1 = "INSERT INTO booking(customer_id,route_id) VALUES ('".$_SESSION['id']."','$route_id')";
if ($query1==1) {
echo"very goodddd";
}
}
else {
echo "good";
}
}
?>
最佳答案
您需要在profile.php
文件中启动会话。
在包括dbconfig文件之前,在session_start();
或profile.php
的行顶部添加booking.php
。