gpt4 book ai didi

php - 我无法使用 php 中的 session 将值从一个页面传递到另一个页面

转载 作者:行者123 更新时间:2023-11-29 21:59:56 26 4
gpt4 key购买 nike

我是编程新手。我想从数据库中获取记录的用户 ID 并存储在 SESSION 中,然后将该 session ID 插入到另一个表中。我想我很开心,但不幸的是,有一个错误让我发疯。任何帮助将不胜感激!

数据库btrs有表booking,其中有可能名称

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 文件中启动 session 。

profile.phpbooking.php 中添加 session_start(); 在行顶部,包含 dbconfig 文件之前。

关于php - 我无法使用 php 中的 session 将值从一个页面传递到另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32753185/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com