我有 4 张桌子:
Departments:
dept_id dept_name
1 dept 1
2 dept 2
3 dept 3
4 dept 4
-------------
Hours:
hours_id proj_hours
1 18
2 36
-------------
Project:
proj_id proj_name
1 project1
2 project2
-------------
Summary:
Summary_id proj_id hours_id dept_id
1 1 1 1
2 2 1 2
3 1 2 3
4 1 1 4
-----------------------------------------------------
SELECT *
FROM summary S
JOIN projects P ON S.proj_id = P.proj_id
JOIN departments D ON D.dept_id = S.dept_id
JOIN hours H ON H.hours_id = S.hours_id
我有一个 index.php 表,它整齐地显示上面的连接数据,但编辑功能损坏.....我不知道如何通过手动编辑功能从查找表中更新实际值。
<td align="center"><a href="edit2.php?id=<?php echo $rows['summary_id']; ?>">Edit</a></td>
用于将 summary_id 发送到编辑页面,它肯定会发送,但不是值。我有空白字段。从那里,我想让我的字段准备好编辑,但同样,空白字段......我遇到了“id”而不是“值”的问题,并且格式化正确。
建议?
编辑.php代码:
<?php
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if(isset($_GET['summary_id']))
{
$id = $_GET['summary_id'];
$res = mysql_query("SELECT * FROM summary WHERE proj_id='$proj_id'");
$rows = mysql_fetch_array($res);
}
if (isset($_POST['nproj_id']))
{
$summary_id = $_POST['summary_id'];
$nproj_id = $_POST['nproj_id'];
$nclarity_id = $_POST['clarity_id'];
$nhours_id = $_POST['nhours_id'];
$ndept_id = $_POST['ndept_id'];
$sql = "UPDATE summary SET clarity_id='$nclarity_id' WHERE proj_id='$proj_id'"
or die ("couldn't update".mysql_error());
$res = mysql_query($sql) or die ("couldn't update".mysql_error());
echo "<meta http-equiv='refresh' content='0;url=index2.php'>";
}
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="edit2.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td> </td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
</tr>
<tr>
<td align="center"> </td>
<td align="center"><strong>Clarity ID</strong></td>
<td align="center"><strong>Hours</strong></td>
<td align="center"><strong>Department</strong></td>
</tr>
<tr>
<td> </td>
<td align="center">
<input name="nclarity_id" type="text" id="nclarity_id" value="<?php echo $rows['clarity_id']; ?>">
</td>
<td align="center">
<input name="nproj_hours" type="text" id="nproj_hours" value="<?php echo $rows['proj_hours']; ?>" size="15">
</td>
<td>
<input name="ndept_name" type="text" id="ndept_name" value="<?php echo $rows['dept_name']; ?>" size="15">
</td>
</tr>
<tr>
<td> </td>
<td>
<input name="summary_id" type="hidden" id="summary_id" value="<?php echo $rows['summary_id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Update">
</td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<?php
// close connection
mysql_close();
?>
这是我的 index.php .... 您所做的更正仍然无效。:(
<?php
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if($_POST['submitted'])
{
$proj_id = $_POST['proj_id'];
$summary_id = $_POST['summary_id'];
$clarity_id = $_POST['clarity_id'];
$hours_id = $_POST['hours_id'];
$proj_hours = $_POST['proj_hours'];
$dept_name = $_POST['dept_name'];
$dept_id = $_POST['dept_id'];
$sqlinsert = "INSERT INTO summary (summary_id,proj_id,hours_id,dept_id) VALUES (NULL,
'$proj_id','$hours_id','$dept_id'";
if (!mysql_query($sqlinsert)) {
die('error inserting new record'.mysql_error());
} // end of the nested if statement
}
$result = mysql_query("SELECT *
FROM summary S
JOIN projects P ON S.proj_id = P.proj_id
JOIN departments D ON D.dept_id = S.dept_id
JOIN hours H ON H.hours_id = S.hours_id
LIMIT 0 , 30");
?>
<form action="index.php" method="post">
Clarity #: <input type="text" name="clarity_id"><br />
Estimated Hours: <input type="text" name="proj_hours"><br />
Department: <input type="text" name="dept_name"><br />
<input type="hidden" name="submitted" value="true"/>
<input type="submit" value="enter">
</form>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from mysql </strong> </td>
</tr>
<tr>
<td align="center"><strong>Clarity#</strong></td>
<td align="center"><strong>Estimated Hours</strong></td>
<td align="center"><strong>Department</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rows['clarity_id']; ?></td>
<td><?php echo $rows['proj_hours']; ?></td>
<td><?php echo $rows['dept_name']; ?></td>
<td align="center"><a href="edit2.php?id=<?php echo $rows['summary_id']; ?>">Edit</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>