- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有两张表,一张用于学生记录,一张用于学生的 sibling 。
当我想更新表格时,我将它们回显到文本区域。
我对学生表执行此操作没有任何问题,但对于 sibling 表,如果学生有两个或更多 sibling ,我的更新将失败,因为文本区域的名称成为最后一行(最后一个 sibling ) .
如何处理这种一对多关系?
这是我的代码:
<?php
$database="sy_database";
mysql_connect ("localhost", "root", "");
@mysql_select_db($database) or die( "Unable to select database");
$id=$_GET['up'];
$sno=$_GET['s_no'];
$order = "SELECT * FROM sy_form WHERE reg_no='$id'";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo "<form method=post action=ambot.php>";
mysql_select_db("sy_database", $con);
$result = mysql_query("SELECT * FROM sy_form where reg_no='$id'");
echo "<body align=center>";
echo"Student Record";
echo "<table border='1' width=1000px margin=0 padding=0 align=center>
<tr bgcolor=yellow>
<th>Reg No.</th>
<th>Name</th>
<th>Date of Birth</th>
<th>Age</th>
<th>Class</th>
<th>School</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr align=center>";
echo "<td><textarea readonly=readonly rows=1 cols=3 name=reg_no>". $row['reg_no'] ." </textarea></td>";
echo "<td><textarea rows=1 cols=20 name=name>" .$row['name']. "</textarea></td>";
echo "<td><textarea rows=1 cols=20 name=birth>" . $row['birth'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=3 name=age>" . $row['age'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=3 name=sclass>" . $row['sclass'] . "</textarea> </td>";
echo "<td><textarea rows=1 cols=20 name=school>" . $row['school'] . "</textarea></td>";
echo "</tr>";
}
echo "</table>";
$result = mysql_query("SELECT * FROM sy_form where reg_no='$id'");
echo "<br><table border='1' width=1250px margin=0 padding=0 align=center>
<tr bgcolor=yellow>
<th>Father's Name</th>
<th>Father's Occupation</th>
<th>Mother's Name</th>
<th>Mother's Occupation</th>
<th>Address</th>
<th>Phone No.</th>
<th>Cellphone No.</th>
<th>Email</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr align=center>";
echo "<td><textarea rows=1 cols=20 name=fname>" . $row['fname'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=10 name=focc>" . $row['focc'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=20 name=mname>" . $row['mname'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=10 name=mocc>" . $row['mocc'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=25 name=address>" . $row['address'] . "</textarea> </td>";
echo "<td><textarea rows=1 cols=8 name=phone>" . $row['phone'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=10 name=cp>" . $row['cp'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=20 name=email>" . $row['email'] . "</textarea></td>";
echo "</tr>";
}
echo "</table>";
echo"<br/>Student's Sibling(s)";
$result = mysql_query("SELECT * FROM siblings where reg_no='$id' AND s_no<min($sno)");
echo "<br/><table border='1' margin=0 padding=0 align=center>
<tr bgcolor=yellow>
<th>Reg No.</th>
<th>Sibling No.</th>
<th>Name</th>
<th>Age</th>
<th>School</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr align=center>";
echo "<td align=right><textarea readonly=readonly rows=1 cols=3 name=reg_no>". $row['reg_no'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=3>" . $row['s_no'] . "</textarea></td>";
echo "<td><textarea rows=1 name=sname>" . $row['sname'] . "</textarea></td>";
echo "<td><textarea rows=1 cols=3 name=sage>" . $row['sage'] . "</textarea></td>";
echo "<td><textarea rows=1 name=sschool>" . $row['sschool'] . "</textarea></td>";
echo "</tr>";
}
echo "</table>";
echo "<input type =submit value =update />";
echo "</form>";
mysql_close($con);
?>
<?php
$database="sy_database";
$id=$_POST['id'];
$ip=$_POST['ip'];
$mac=$_POST['mac'];
$location=$_POST['location'];
$use=$_POST['use'];
mysql_connect ("localhost", "root", "");
@mysql_select_db($database) or die( "Unable to select database");
$order = "UPDATE sy_form
SET name='$name' WHERE reg_no='$reg_no'";
$result=mysql_query($order);
if($result){
echo "<p style=margin-top:50px;><BR><BR><BR></p>";
echo "<a href='view.php'>Back to Records</a>";
}
else {
echo "ERROR";
echo $name;
}
?>
这是我的更新代码:
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sy_database", $con);
$result = mysql_query("UPDATE sy_form SET name='$name', birth='$birth', age='$age', sclass='$sclass', school='$school' , fname='$fname', focc='$focc', mname='$mname', mocc='$mocc', address='$address', phone='$phone', cp='$cp', email='$email' where reg_no='$reg'");
$result = mysql_query("UPDATE siblings SET sname='$sname',sage='$sage', sschool='$sschool' where reg_no='$reg'");
echo("record updated.");
mysql_close($con);
?>
这是我插入的 html 代码:
<html>
<head>
<style type = "text/css">
body {
font-family: Arial;
margin: 0 auto;
}
table{
margin: 0 auto;
}
#masterdiv {
width: 800px;
margin: 0 auto;
}
#header {
margin: 0 auto;
width: 796px;
height: 10;
background-image: url('header.jpg');
}
#fillForm {
margin: 0 auto;
width: 800px;
background-color: #FFFFFF;
}
#footer {
margin: 0 auto;
width: 798px;
height: 75px;
background-image: url('footer.jpg');
}
</style>
<title>Registration Form</title>
</head>
<body bgcolor="black">
<div id = "masterdiv">
<div id = "header"></div>
<div id = "fillForm">
<p align="right" style="color:red;font-size:60px;"/> Registration Form</p>
<table cellspacing="0" cellpadding="0" border="0">
<form action = "cc.php" method ="post">
<tr bgcolor="red">
<td colspan="3"> </td>
<td><b>Registration No:</b></td>
<td><input type = "text" name = "reg_no"></td>
</tr>
<tr><td> </td></tr>
<tr>
<td>Name: </td>
<td><input type = "text" size = "40" name = "name"></td>
<td> </td>
<td>Date of Birth: </td>
<td><input type = "text" name = "birth"></td>
</tr>
<tr>
<td>Age: </td>
<td><input type = "text" size = "20" name = "age"></td>
<td> </td>
<td>Class as at January: </td>
<td><input type = "text" name = "sclass"></td>
</tr>
<tr>
<td>School: </td>
<td colspan = "4"><input type = "text" size = "80" name = "school"></td>
</tr>
<tr>
<td>Father's Name: </td>
<td colspan = "4"><input type = "text" size = "80" name = "fname"></td>
</tr>
<tr>
<td>Father's Occupation: </td>
<td colspan = "4"><input type = "text" size = "80" name = "focc"></td>
</tr>
<tr>
<td>Mother's Name: </td>
<td colspan = "4"><input type = "text" size = "80" name = "mname"></td>
</tr>
<tr>
<td>Mother's Occupation: </td>
<td colspan = "4"><input type = "text" size = "80" name = "mocc"></td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td colspan = "5">Siblings (if any)</td>
</tr>
<tr>
<td> </td>
<td>Name</td>
<td>Age</td>
<td> </td>
<td>School</td>
</tr>
</table>
<table>
<tr>
<td>1. <input type = "text" size = "50" name = "sname"></td>
<td><input type = "text" size = "25" name = "sage"></td>
<td><input type = "text" size = "30" name = "sschool"></td>
</tr>
<tr>
<td>2. <input type = "text" size = "50" name = "sname2"></td>
<td><input type = "text" size = "25" name = "sage2"></td>
<td><input type = "text" size = "30" name = "sschool2"></td>
</tr>
<tr>
<td>3. <input type = "text" size = "50" name = "sname3"></td>
<td><input type = "text" size = "25" name = "sage3"></td>
<td><input type = "text" size = "30" name = "sschool3"></td>
</tr>
<tr align = "right">
<td colspan = "3">Address: <input type = "text" size = "80" name = "address"></td>
</tr>
<tr align = "right">
<td colspan = "3">Phone Number: <input type = "text" size = "80" name = "phone"></td>
</tr>
<tr align = "right">
<td colspan = "3">Cellphone Number (Mother/Father)<input type = "text" size = "80" name = "cp"></td>
</tr>
<tr align = "right">
<td colspan = "3">Email: <input type = "text" size = "80" name = "email"></td>
</tr>
<tr><td> </td></tr>
<tr align = "center">
<td colspan = "3">
<input type = "submit" value = "Submit" name = "Submit">
</form>
<form action="view.php" method="post" target="_blank">
<input type = "submit" value = "View/Update/Delete" name = "View" >
</form>
</td>
</tr>
<tr><td> </td></tr>
</table>
</div>
<div id = "footer"></div>
</div>
</body>
</html>
这是 INSERT 的 PHP 代码:
<?php
//student record details
$name = $_POST['name'];
$birth = $_POST['birth'];
$age = $_POST['age'];
$sclass = $_POST['sclass'];
$school = $_POST['school'];
$fname = $_POST['fname'];
$focc = $_POST['focc'];
$mname = $_POST['mname'];
$mocc = $_POST['mocc'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$cp = $_POST['cp'];
$email = $_POST['email'];
$reg = $_POST['reg_no'];
//siblings record
$sname = $_POST['sname'];
$sage = $_POST['sage'];
$sschool = $_POST['sschool'];
$sname2 = $_POST['sname2'];
$sage2 = $_POST['sage2'];
$sschool2 = $_POST['sschool2'];
$sname3 = $_POST['sname3'];
$sage3 = $_POST['sage3'];
$sschool3 = $_POST['sschool3'];
// connect to mysql
$conn = mysql_connect("localhost", "root", "")
or die("ERR: Connection");
// connect to database
$db = mysql_select_db("sy_database", $conn)
or die("ERR: Database");
// create mysql query
// Insert a row of information into the table "sy_form"
$sql = "INSERT INTO sy_form (reg_no, name, birth, age, sclass, school, fname, focc, mname, mocc, address, phone, cp, email)
VALUES('".$reg."', '".$name."', '".$birth."', '".$age."', '".$sclass."', '".$school."', '".$fname."', '".$focc."', '".$mname."', '".$mocc."','".$address."','".$phone."','".$cp."','".$email."')";
if (!mysql_query($sql,$conn))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
// execute query
$exec = mysql_query($sql, $conn);
// Insert a row of information into the table "sy_form" (1st sibling)
$sql_1 = "INSERT INTO siblings (reg_no,s_no, sname, sage, sschool)
VALUES('".$reg."','', '".$sname."', '".$sage."', '".$sschool."')";
if($sname==null)
return 0;
else
$exec = mysql_query($sql_1, $conn);
// Insert a row of information into the table "sy_form" (2nd sibling)
$sql_2 = "INSERT INTO siblings (reg_no,s_no, sname, sage, sschool)
VALUES('".$reg."','', '".$sname2."', '".$sage2."', '".$sschool2."')";
if($sname2==null)
return 0;
else
$exec = mysql_query($sql_2, $conn);
// Insert a row of information into the table "sy_form" (3rd sibling)
$sql_3 = "INSERT INTO siblings (reg_no,s_no, sname, sage, sschool)
VALUES('".$reg."','', '".$sname3."', '".$sage3."', '".$sschool3."')";
if($sname3==null)
return 0;
else
$exec = mysql_query($sql_3, $conn);
echo ("The following data has been added to sy_database");
?>
最佳答案
您可以将 [] 添加到字段名称的末尾,以将其作为数组发布。您没有发布任何更新代码,所以这里有一个简单的通用示例:
HTML:
<input type="text" name="sibling[unique_id][reg_no]" />
<input type="text" name="sibling[unique_id][name]" />
<input type="text" name="sibling[unique_id][birth]" />
... and so on
PHP:
// connect to your database as normal
// do your student update as normal
// now we're looping through siblings
foreach($_POST['sibling'] AS $sibling){
$reg_no = $sibling['reg_no'];
$name = $sibling['name'];
$birth = $sibling['birth'];
... and so on to set all your variables
// and now you can run your update query
}
如果 sibling 有自己的唯一 ID,您可以在括号中指定它,所以 name="sibling[unique_id]"
然后在 php 中您将有 $_POST['sibling ']['unique_id']
关于php帮助。与更新混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12540431/
我真的很困惑。我已经尝试使用带有 tomcat 的 Jax-rs 并使用所有注释,我能够使用 url 调用我的服务。因此,如果没有 Jax-rs,我可以简单地拥有一个 servlet 并调用我的服务。
是否有任何工具/商业混淆器可以混淆 WPF 控件中的 BAML 资源? 如果没有,就 IP 保护而言,这是一段艰难的时期,因为黑客可以通过使用 BAML 到 XAML 转换器轻松查看 BAML 资源。
嘿大家。我在尝试使用 COBOL 在 zOS 环境中解决的编码项目中遇到了一些麻烦。我需要读入一个文件并将它们放入索引表中(我知道将少于 90 条记录)。 让我感到困扰的是,我们受到项目参数的约束,以
我试图按照这个例子来理解 join() 方法: class PrintDemo { public void printCount() { try { for(int
当我编译我正在编写的代码,然后在 JD Gui 中查看时,方法显示带有如下标题: public void growSurface(Random paramRandom, int paramInt1,
我正在为重新分发准备 Android 库,它的代码必须进行混淆处理。我已经阅读了有关此主题的一些内容,并且决定使用 Android Library Project。它将作为 jar 分发(自动在/bi
两个混淆相关的问题: 1) 是否有任何工具可以将 F# 从 MSIL 目标形式反汇编回其源形式或接近它的形式?这不是通过默默无闻来实现安全性的尝试,但我想保护某些源代码免遭“盗窃”。 2) 我简要地查
谁能向我解释为什么 simulatedCase <- rbinom(100,1,0.5) simDf <- data.frame(CASE = simulatedCase) posterior_m0
我一直无法找到关于使用 AppDomains 时发生的事情的非常清楚的描述,所以希望有人能够启发我。我有一个简单的测试程序(基本上是扯掉了 MSDN example ): using System;
假设我有 2 个分支topic和 master如果我在 topic分支,然后运行 git rebase master它是 rebase master 还是 rebase 主题分支? 做 git r
我有一个类(class): public class LockTest { public void LockThis() { lock (this)
我正在尝试最小化/混淆我的 Angular 代码,但遇到了问题。我在这里阅读“缩小说明”http://docs.angularjs.org/tutorial/step_05但我定义我的 Control
我遇到了一些困惑的操作。 var a = 0.1; var b = 0.2; var c = 0.3; console.log(a); // 0.1 console.log(b); // 0.2 co
感谢您查看我的帖子 - 我正在尝试弄清楚如何在单击链接时关闭此下拉菜单,但我的 JavaScript 技能非常缺乏,而且代码似乎很困惑。这是 HTML:
混淆、哈希和加密之间有什么区别? 这是我的理解: 哈希是一种单向算法;无法逆转 混淆与加密类似,但不需要任何“ secret ”即可理解(ROT13 就是一个例子) 加密是可逆的,但需要“ secre
我有以下代码 my $content = $response->content; $content =~ /username=([\s\S]+?)&/; my $username = $1; prin
我在 .NET 中发现了一些与我预期的有点不同的东西。我粘贴的代码没有意义,但它是我拥有的一个复杂得多的函数的浓缩版。我实际上是在获取匿名类型信息作为参数(尚未创建匿名类型的实例),我需要创建该类型的
我正在努力解决 JavaFX 应用程序的混淆问题。使用此项目作为基础: https://github.com/openjfx/samples/tree/master/IDE/IntelliJ/Non-
是否可以制作一个与此类似的 CSV 阅读器 while((line = reader.readLine()) != null){ String[] values = line.
公共(public)类测试2 { 公共(public)静态无效主(字符串[]参数){ System.out.println("3 + 6"); System.out.println(3
我是一名优秀的程序员,十分优秀!