我有一个包含字段的表(id,status,reason,sid) 字段为链接表注册
请参阅此代码:
<?php
include "config.php";
/*
CREATE TABLE `reg` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 255 ) NOT NULL ,
`id_number` VARCHAR( 255 ) NOT NULL ,
`birthdate` VARCHAR( 255 ) NOT NULL ,
`mobile` VARCHAR( 255 ) NOT NULL ,
`qualification` VARCHAR( 255 ) NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`project` VARCHAR( 255 ) NOT NULL ,
`project_type` VARCHAR( 255 ) NOT NULL ,
`experience` VARCHAR( 255 ) NOT NULL ,
`notes` VARCHAR( 255 ) NOT NULL ,
`date` DATETIME NOT NULL
) ENGINE = MYISAM ;
*/
/// STATUS
/*
CREATE TABLE `status` (
`sid` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`status` VARCHAR( 60 ) NOT NULL ,
`reason` TEXT NOT NULL ,
`id` INT NOT NULL
) ENGINE = MYISAM ;
*/
$gid = intval($_GET['id']);
$id = $_POST['id'];
$n = $_POST['name'];
$i = $_POST['id_number'];
$b = $_POST['birthdate'];
$m = $_POST['mobile'];
$q = $_POST['qualification'];
$e = $_POST['email'];
$p = $_POST['project'];
$pt = $_POST['project_type'];
$ex = $_POST['experience'];
$no = $_POST['notes'];
// STATUS
$sid = $_POST['id'];
$status = strip_tags($_POST['status']);
$reason = strip_tags($_POST['reason']);
if (isset($_POST['nstatus']) and $_POST['nstatus'] == 'stat'){
$insertstatus = mysql_query ("INSERT INTO status (id,status,reason) VALUES ('$sid','$status','$reason')") or die ("mysql error");
if (isset ($insertstatus)){
die ("Update Is Done
<meta http-equiv='Refresh' content='2; url=show_reg.php' />");
}
}
// STATUS END
if (isset($_POST['edit']) and $_POST['edit'] == 'reg'){
$update = mysql_query ("UPDATE reg SET name='$n',id_number='$i',birthdate='$b',mobile='$m',qualification='$q',email='$e',project='$p', project_type='$pt',experience='$ex',notes='$no' WHERE id='$id'") or die ("mysql error");
if (isset($update)){
echo "<h2>Update is done</h2>";
}
}
if ($_REQUEST['del'] == 'reg'){
$del = mysql_query ("DELETE FROM reg WHERE id='".$gid."'");
if (isset ($del)){
echo "<h2>Delete is done</h2>";
}
}
$q = mysql_query("SELECT * FROM reg WHERE id='".$gid."'") or die ("mysql error");
$rowedit = mysql_fetch_assoc($q);
if ($_REQUEST['do'] == 'edit'){
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>
<table border='1' width='750' cellspacing='1'>
<tr>
<td colspan='4'><input type='text' name='name' value='".$rowedit['name']."' /></td>
<td>name</td>
</tr>
<tr>
<td colspan='4'><input type='text' name='id_number' value='".$rowedit['id_number']."' /></td>
<td>Id Number</td>
</tr>
<tr>
<td colspan='4'><input type='date' name='birthdate' value='".$rowedit['birthdate']."' /></td>
<td>Birthdate</td>
</tr>
<tr>
<td colspan='4'><input type='number' name='mobile' value='".$rowedit['mobile']."' /></td>
<td>Mobile No.</td>
</tr>
<tr>
<td colspan='4'><input type='text' name='qualification' value='".$rowedit['qualification']."' /></td>
<td>Qualification</td>
</tr>
<tr>
<td colspan='4'><input type='email' name='email' value='".$rowedit['email']."' /></td>
<td>Email</td>
</tr>
<tr>
<td colspan='4'><input type='text' name='project' value='".$rowedit['project']."' /></td>
<td>Project Name</td>
</tr>
<tr>
<td>Busines</td>
<td><input type='radio' name='project_type' value='Busines' /></td>
<td>Home</td>
<td><input type='radio' name='project_type' value='Home' /></td>
<td>Project Type</td>
</tr>
<tr>
<td colspan='4'><input type='text' name='experience' value='".$rowedit['experience']."' /></td>
<td>Experience</td>
</tr>
<tr>
<td colspan='4'><textarea style='width:300px; height:50px;' name='notes'>".$rowedit['notes']."</textarea></td>
<td>Notes</td>
</tr>
</table>
<input type='submit' value='Save' />
<input type='hidden' name='id' value='".$gid."' />
<input type='hidden' name='edit' value='reg' />
</form>";}
$data = mysql_query("SELECT * FROM reg ORDER BY id DESC");
$gid = intval($_GET['id']);
$query = mysql_query("SELECT * FROM reg WHERE id='".$gid."'") or die ("mysql error");
$row = mysql_fetch_assoc($query);
if (!isset ($gid)){
die ("<h2>Input is incorrect</h2>");
}
else if (mysql_num_rows($query) < 1){
die ("<h2>No data in the database</h2>");
}else if (isset($gid) and is_numeric($gid)) {
echo "<table width='80%' cellpadding='5' border='1'>
<tr>
<td>#</td>
<td>Name</td>
<td>Id Number</td>
<td>Birthdate</td>
<td>Mobile No.</td>
<td>Qualification </td>
<td>Email</td>
<td>Project</td>
<td>Project Type</td>
<td>Experience</td>
<td>Notes</td>
<td>Date</td>
<td>Options</td>
</tr>
<tr>
<td>".$row['id']."</td>
<td>".$row['name']."</td>
<td>".$row['id_number']."</td>
<td>".$row['birthdate']."</td>
<td>".$row['mobile']."</td>
<td>".$row['qualification']."</td>
<td>".$row['email']."</td>
<td>".$row['project']."</td>
<td>".$row['project_type']."</td>
<td>".$row['experience']."</td>
<td>".$row['notes']."</td>
<td>".$row['date']."</td>
<td>
<a href='show_reg_more.php?do=edit&id=".$row['id']."'>Edit</a>-
<a href='show_reg_more.php?del=reg&id=".$row['id']."'>Delete</a>
</td>
</tr>
</table>";
// START STATUS
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>
<table width='80%' border='1' cellpadding='5'>
<tr>
<td align='center' colspan='2'>Add Status</td>
</tr>
<tr>
<td>Status</td>
<td>Yes<input type='radio' name='status' value='Yes' /></br>
No<input type='radio' name='status' value='No' /></td>
</tr>
<tr>
<td>Reason Rejection</td>
<td><textarea name='reason'></textarea></td>
</tr>
<tr>
<td align='center' colspan='2'><input type='submit' value='Add Status' /></td>
</tr>
</table>
<input type='hidden' name='nstatus' value='stat' />
<input type='hidden' name='id' value='".$gid."' />
</form>";
// END STATUS
}else {
echo "<h2>No Results</h2>";
}
mysql_close($con);
?>
如果字段(状态)为空,那么我想允许更新,如果该字段不为空,则不允许更新。
如何在PHP中编写IF代码
答案 0 :(得分:0)
如果(状态)为空,则允许添加数据输入 我使用此代码但不起作用
$status = strip_tags($_POST['status']);
if (isset($_POST['nstatus']) and $_POST['nstatus'] == 'stat'){
$insertstatus = mysql_query ("INSERT INTO status (id,status,reason) VALUES ('$sid','$status','$reason')") or die ("mysql error");
if (!empty($status)){
die ("Has recently added");
}else
if (isset ($insertstatus)){
die ("Update us done
<meta http-equiv='Refresh' content='2; url=show_reg.php' />");
}
}
答案 1 :(得分:0)
你的意思是什么?
$status = strip_tags($_POST['status']);
if (isset($_POST['nstatus']) && $_POST['nstatus'] == 'stat') {
if (empty($status)) {
$insertstatus = mysql_query ("INSERT INTO status (id,status,reason) VALUES ('$sid','$status','$reason')") or die ("mysql error");
if($insertstatus) {
die ("Update us done <meta http-equiv='Refresh' content='2; url=show_reg.php' />");
} else {
die("An Error occured.");
}
} else {
die ("Has recently added");
}
}
答案 2 :(得分:0)
不起作用 需要: 添加(status)时要确保该字段不包含任何有价值的输入。 如果没有输入值数据