<?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而不是实际值。
答案 0 :(得分:0)
<input type="text" class="form-control" name="vis_id" value=" <?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT * FROM list1 ORDER BY card_no DESC LIMIT 1;';
mysql_select_db('visitor_list');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
/*echo "{$row['card_no']}";*/
$in= $row['card_no'];
$in+
$test = $in;
}
mysql_close($conn);
?>" disabled>
这是实际的代码 在此输入框中,值正在递增 帮我将这个输入框的值保存到另一个数据库文件中。