我有两页。第一页(admin_submit_job.php)有文本框并提取job_id:
<form name="form1" method="post" action="admin_send_job.php" >
<p>
<label for="textfield">شغل جدید</label>
<input type="text" name="textfield" id="textfield" />
<label for="Submit"></label>
<input type="submit" name="Submit" value="Submit" id="Submit" />
</p>
<?php
$db_host = 'localhost';
$db_name= 'site';
$db_table= 'job_list';
$db_user = 'root';
$db_pass = '';
$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
mysql_query("SET CHARACTER SET utf8");
$dbresult=mysql_query("SELECT job_id FROM $db_table
order by job_id desc
limit 1;",$con);
$id='job_id';
?>
</form>
并在第二页(admin_send_job.php)中我需要获取textbox和job_id的内容。
<?php
$db_host = 'localhost';
$db_name= 'site';
$db_table= 'job_list';
$db_user = 'root';
$db_pass = '';
$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
$ins = "INSERT INTO $db_table (job_id,job_name) VALUES ('" . mysql_escape_string($_POST['id']) . "','" . mysql_escape_string($_POST['textfield']) . "')";
$saved=mysql_query($ins );
mysql_close($con);
echo "('" . mysql_escape_string($_POST['id']) . "')";
?>
我不知道我应该写什么来获取和增加job_id。感谢...
答案 0 :(得分:2)
使用auto_increment
job_id
,您只需要执行此操作
$ins = "INSERT INTO $db_table (job_name) VALUES ('" . mysql_escape_string($_POST['textfield']) . "')";
如果最后一个是10
,它将插入job_id
11的新记录