<?php
session_start();
session_register("s_orderid");
include ("connect.php");
$product_id = $_POST ['product_id'];
$amount = $_POST['amount'];
// checknull
function checknull($var,$value)
{
if (empty($var)){
echo"<script>
alert('Pleae Input ".$value."');
history.back();
</script>";
exit();
}
}
checknull ($product_id,"product_id");
checknull ($amount,"amount");
// SAVE
$sql="insert into order
values (' ','$product_id','$amount')";
mysql_query($sql) or die ("SAVE Error!!!");
include ("connect.php");
$order_id = $_SESSION['s_orderid'];
$sql="select * from order where order_id = '$order_id'";
$result = mysql_query($sql) or die ('SQL error');
$row_user = mysql_fetch_array($result);
echo"<script>
alert('Number Order : $row[0]');
alert('Save Data OK');
window.location='memberhomepage.php';
</script>";
exit();
?>
นี้UPDATE Code (PHP)
<?php
session_start();
include ("connect.php");
$username = trim($_POST['username']);
$password = trim($_POST['password']);
$repassword = trim($_POST['repassword']);
$name = $_POST ['name'];
$sname = $_POST['sname'];
$address = $_POST['address'];
$tel = $_POST['tel'];
$email = $_POST['email'];
// checknull
function checknull($var,$value)
{
if (empty($var)){
echo"<script>
alert('Please Input ".$value."');
history.back();
</script>";
exit();
}
}
checknull ($email,"email");
checknull ($username,"username");
// update
$sql="update profile set password ='$password',name ='$name', sname = '$sname', address = '$address', tel = '$tel', email = '$email' ";
if (!empty($password))
{
$sql.="password='$password'";
}
$sql.="where username ='$username'";
mysql_query($sql) or die ("Update Error!!!");
echo"<script>
alert('Save Data OK');
</script>";
echo"<center> <a href = 'editprofile.php'>
FORM EDIT </a></center>" ;
?>
<?php
$sql="insert into order
values (' ','$product_id','$amount')";
mysql_query($sql) or die ("SAVE Error!!!");
include ("connect.php");
$order_id = $_SESSION['s_orderid'];
$sql="select * from order where order_id = '$order_id'";
$result = mysql_query($sql) or die ('SQL error'); // ตรงนี้ไม่ทำงานอ่ะคับ เพราะผมต้องการให้มันแสดง
$row_user = mysql_fetch_array($result);
echo"<script>
alert('Number Order : $row[0]'); // ตรวนี้คับ
alert('Save Data OK');
window.location='memberhomepage.php';
</script>";
exit();
?>