$ _SESSION에서 데이터베이스로 값을 입력하는 데 도움이 필요하지만 오류는 발생하지 않지만 데이터베이스 테이블에는 아무 것도 추가되지 않습니다. 제발 도와주세요
여기 내 코드입니다.
<?php
session_start();
$conn = @mysql_connect("localhost","root","12148qx3er");
$db = @mysql_select_db("buybranded");
include("includes/functions.php");
mysql_set_charset("UTF8");
if(isset($_REQUEST['command']) && $_REQUEST['command']=='update'){
$first_name=$_SESSION['first_name'];
$email=$_SESSION['email'];
$home_address=$_SESSION['home_address'];
$mobile_number=$_SESSION['mobile_number'];
$result=mysql_query("insert into customers(name,email,address,phone) values('','$first_name','$email','$home_address','$mobile_number')");
$customerid=mysql_insert_id();
$date=date('Y-m-d');
$result=mysql_query("insert into orders values('','$date','$customerid')");
$orderid=mysql_insert_id();
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
mysql_query("insert into order_detail values ($orderid,$pid,$q,$price)");
}
die('Thank You! your order has been placed!');
}
?>
여기에 checklogin.php가 있는데, 여기에 $ _SESSION 값이 있습니다. 라인 (14)의 모습에
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password="12148qx3er"; // Mysql password
$db_name="buybranded"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$email=$_POST['email'];
$password=$_POST['password'];
// To protect MySQL injection (more detail about MySQL injection)
$email = stripslashes($email);
$password = stripslashes($password);
$email = mysql_real_escape_string($email);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE email='$email' and password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_start();
$_SESSION["email"] = $email;
$_SESSION["password"] = $password;
$_SESSION["first_name"] = $first_name;
$_SESSION["middle_name"] = $middle_name;
$_SESSION["last_name"] = $last_name;
$_SESSION["gender"] = $gender;
$_SESSION["birth_date"] = $birth_date;
$_SESSION["home_address"] = $home_address;
$_SESSION["mobile_number"] = $mobile_number;
$_SESSION["home_phone"] = $home_phone;
$_SESSION["postal_code"] = $postal_code;
$_SESSION["city"] = $city;
$_SESSION["province"] = $province;
while($row = mysql_fetch_array($result)){
//remove this line ******header("location:customer_home.php");
if($row['type'] == 'admin'){
header("location: admin.php");
} else if($row['type'] == 'customer'){
header("location: customer_home.php");
}
}
}
else {
header('refresh: 0.1; url=sign-in.php');
$message = "Invalid Email or Password, Redirecting..";
die("<script type='text/javascript'>alert('$message');</script>"); // To prevent evil people manipulating the page, kill the script using die.
}
?>
여기서 세션 변수를 정의합니까? 왜냐하면 우리는 그들이 정의 된 곳을 알지 못하는 세션 밖의 항목을 게시하기 때문입니다. 그들을 에코 했나요? 당신은 당신의 질문을 반향 했습니까? – Dorvalla
SQL 인젝션에 대해 열려 있습니다. 또한 mysql 라이브러리는 더 이상 사용되지 않으며 제거 될 것이다. PDO 또는 MySQLi를 사용하고 준비된 문을 사용해야합니다. –
P. ... –