<?php
//connecting to the database
define('DB_HOST', 'localhost');
define('DB_NAME', 'visitor_list');
define('DB_USER','root');
define('DB_PASSWORD','');
$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error()); $db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " .
mysql_error()); //inserting Record to the database
$dat1 = date("d");
$moth1 = date("m");
$year1 = date("Y");
$sql2 = 'SELECT * FROM list1 ORDER BY card_no DESC LIMIT 1;';
$retval = mysql_query($con,$sql2);
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
/*echo "{$row['card_no']}";*/
$in= $row['card_no'];
$in++;
}
$ap_ty = $_POST['ap_ty'];
$per = $_POST['per'];
$no_vis = $_POST['no_vis'];
$nm_vis = $_POST['nm_vis'];
$co_nm = $_POST['co_nm'];
$ad = $_POST['ad'];
$po = $_POST['po'];
$ty_vis = $_POST['ty_vis'];
$met_nm = $_POST['met_nm'];
$dep = $_POST['dep'];
$des = $_POST['des'];
$por_met = $_POST['por_met'];
$vad = $_POST['vad'];
if(!isset($_POST['submit'])){
$query = "INSERT INTO list1 (card_no,d1,m1,y1,app_ty,no_per,area_vis,nm,com_nm,add1,pho,ty1_vis,met_with,depart,desi,pur_meet,vad_up) VALUES ('$in','$dat1','$moth1','$year1','$ap_ty','$per','$no_vis','$nm_vis','$co_nm','$ad','$po','$ty_vis','$met_nm','$dep','$des','$por_met','$vad')";}
$result = mysql_query($query);
if($result)
{
echo '<script type="text/javascript">
alert("Your Deatils has been Submitted");
</script> ';
header('location:index.php');
}
else
{ die('Error: '.mysql_error($con)); }
mysql_close($con);
?>
我想將$in
變量值保存在查詢中但無法保存。在插入時它保存值0而不是實際值。如何將變量值保存在PHP中的循環之外?
你想保存你從第一個查詢中獲得的所有卡號嗎? – Poria
while循環之外嘗試通過$ in = 0啓動$ in變量,在$ in ++之後回顯$ in的值,看看它是否實際上正在增加。@ gundeep –
刪除$ in ++;在while循環內 –