php表单提交 - Q2 [英] php form submit - Q2
本文介绍了php表单提交 - Q2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
修正:现在提交效果很好
Q2 - 仍然无法使用复选框:( - 请
)有人可以告诉我如何追踪这样的错误吗?
< php include(db_connect.php);?>
< html>
< head>< / head>
< body>
< form method =postaction =moving.php>
< table border =1>
< tr>
< td>
< php
$ left ='SELECT * FROM test1 ORDER BY name ASC';
$ result1 = mysql_query($ left);
$ count = mysql_num_rows($ result1);
while ($ resulta = mysql_fetch_array($ result1)){
?>
< input name =checkbox []type =checkboxid = 复选框[]value =<? echo $ resulta ['id']; >>< ;? echo $ resulta ['name'];?>
<>
<?php}>
< / td>
< td>< input type =submitid =addname =addvalue =Add/>< / td>
< td>
<?php
$ rigth ='SELECT * FROM test2,test1 WHERE test2.collect = test1.id ORDER BY test1.name ASC';
$ result2 = mysql_query($ right) ;
while($ resultb = mysql_fetch_array($ result2)){
echo $ resultb ['id'];
echo< br />;
}
?>
< / td>
< / tr>
< / table>
<?php
//检查add ($ i = 0; $ i <$ count; $ i ++){
$ add_id){is $($ _ POST ['add'])){
启动此
= $ checkbox [$ i];
if($ add_id =='1'){
$ sql =INSERT INTO test2(status,collect)VALUES(1,1);
$ result = mysql_query($ sql);
//如果成功重定向到delete_multiple.php
if($ result){
echo< meta http-equiv = \refresh \content = \0; URL = moving.php\>;
}
}
mysql_close();
?>
< / form>
< / body>
< / html>
感谢:)初学者
解决方案
解决方案 - 不是很好,但它的工作原理 - 感谢所有的意见和帮助!!!
<?php include(db_connect.php);?>
< html>
< head>
< / head>
< body>
< form method =postaction =test.php>
新:
<?php
$ left ='SELECT * FROM test1 ORDER BY name ASC';
$ result1 = mysql_query($ left);
$ count = mysql_num_rows($ result1);
while($ resulta = mysql_fetch_array($ result1))
{
?>
< input name =checkbox_add []type =checkboxid =checkbox_add []value =< ;? echo $ resulta ['id'];?>/ > < ;? echo $ resulta ['name']; ?>
< br />
<?php
}
?>
< / td> < td>< input type =submitid =addname =addvalue =Add/>< br />< input type =submitid =deletename =删除值=Del/>< / td>< td>
<?php
$ right ='SELECT test2.id,test1.name FROM test2,test1 WHERE test1.id = test2.collect AND test2.status = 1';
$ result2 = mysql_query($ right);
while($ resultb = mysql_fetch_array($ result2))
{
?>
< input name =checkbox_del []type =checkboxid =checkbox_del []value =<?php echo $ resultb ['id'];?>/>, <?php echo $ resultb ['id']; ?>,< ;? echo $ resultb ['name']; ?>
< br />
<?php
}
?>
< / td>< / tr>< / table>
<?php
//检查添加按钮是否有效,启动
if(isset($ _ POST ['add'])){
for($ c = 0; $ c< count($ _ POST ['checkbox_add']); $ c ++){
$ checkbox_add = $ _POST ['checkbox_add'] [$ c];
$ sql =INSERT INTO test2(status,collect)VALUES(1,。$ checkbox_add。);
echo $ sql;
$ result = mysql_query($ sql);
if($ result){
echo< meta http-equiv = \refresh'\\content = \0; URL = test.php\>;
$ b elseif(isset($ _ POST ['delete'])){
for($ c = 0; $ c $ checkbox_del = $ _POST ['checkbox_del'] [$ c];
回声日期(Y-m-d);
$ sql =UPDATE test2 SET status ='2',log ='。date('Y-m-d')。'其中id =。$ checkbox_del;
echo $ sql;
$ result = mysql_query($ sql);
if($ result){
echo< meta http-equiv = \refresh'\\content = \0; URL = test.php\>;
$ b elseif isset($ _ POST ['new'])){
$ sql =INSERT INTO test1(status,name)VALUES (1,'。$ _ POST ['newitem']。');
echo $ sql;
$ result = mysql_query($ sql);
if($ result){
echo< meta http-equiv = \refresh'\\content = \0; URL = test.php\>;
}
}
mysql_close();
?>
< / form>
< / body>
< / html>
i am sorry for the dummy question. Here is my simple PHP form with two SQL tables and with the ADD submit button I would like to move people from Test1 to Test2. Many thing are fine:( only the submit button does't work therefore no feedback from Test2 table.
Revised: Submit now works great
Q2 - still don't get the checkboxs to work:( - please
Could somebody show me how to track back such an error like this please?
<?php include("db_connect.php");?>
<html>
<head></head>
<body>
<form method="post" action="moving.php">
<table border="1">
<tr>
<td>
<?php
$left='SELECT * FROM test1 ORDER BY name ASC';
$result1=mysql_query($left);
$count=mysql_num_rows($result1);
while($resulta = mysql_fetch_array($result1)) {
?>
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $resulta['id']; ?>"/> <? echo $resulta['name']; ?>
<br />
<?php } ?>
</td>
<td><input type="submit" id="add" name="add" value="Add" /></td>
<td>
<?php
$rigth='SELECT * FROM test2,test1 WHERE test2.collect=test1.id ORDER BY test1.name ASC';
$result2=mysql_query($right);
while($resultb = mysql_fetch_array($result2)) {
echo $resultb['id'] ;
echo "<br />";
}
?>
</td>
</tr>
</table>
<?php
// Check if add button active, start this
if (isset($_POST['add'])) {
for ($i=0;$i<$count;$i++) {
$add_id = $checkbox[$i];
if ($add_id=='1') {
$sql = "INSERT INTO test2 (status, collect) VALUES(1, 1)";
$result = mysql_query($sql);
}
}
// if successful redirect to delete_multiple.php
if ($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=moving.php\">";
}
}
mysql_close();
?>
</form>
</body>
</html>
thanks:) from a beginner
解决方案
the solution - not nice but it works - thanks for all the comments and help!!!
<?php include("db_connect.php");?>
<html>
<head>
</head>
<body>
<form method="post" action="test.php">
New:
<?php
$left='SELECT * FROM test1 ORDER BY name ASC';
$result1=mysql_query($left);
$count=mysql_num_rows($result1);
while($resulta = mysql_fetch_array($result1))
{
?>
<input name="checkbox_add[]" type="checkbox" id="checkbox_add[]" value="<? echo $resulta['id']; ?>"/> <? echo $resulta['name']; ?>
<br />
<?php
}
?>
</td> <td><input type="submit" id="add" name="add" value="Add" /><br /><input type="submit" id="delete" name="delete" value="Del" /></td><td>
<?php
$right='SELECT test2.id, test1.name FROM test2, test1 WHERE test1.id=test2.collect AND test2.status=1';
$result2=mysql_query($right);
while($resultb = mysql_fetch_array($result2))
{
?>
<input name="checkbox_del[]" type="checkbox" id="checkbox_del[]" value="<?php echo $resultb['id']; ?>"/>, <?php echo $resultb['id']; ?>, <? echo $resultb['name']; ?>
<br />
<?php
}
?>
</td></tr></table>
<?php
// Check if add button active, start this
if (isset($_POST['add'])) {
for ($c = 0; $c < count($_POST['checkbox_add']); $c++){
$checkbox_add = $_POST['checkbox_add'][$c];
$sql = "INSERT INTO test2 (status, collect) VALUES(1, ".$checkbox_add.")";
echo $sql;
$result = mysql_query($sql);
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=test.php\">";
}
}
}
elseif (isset($_POST['delete'])) {
for ($c = 0; $c < count($_POST['checkbox_del']); $c++){
$checkbox_del = $_POST['checkbox_del'][$c];
echo date("Y-m-d");
$sql = "UPDATE test2 SET status='2', log='".date('Y-m-d')."' Where id=".$checkbox_del;
echo $sql;
$result = mysql_query($sql);
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=test.php\">";
}
}
}
elseif (isset($_POST['new'])) {
$sql = "INSERT INTO test1 (status, name) VALUES(1, '".$_POST['newitem']."')";
echo $sql;
$result = mysql_query($sql);
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=test.php\">";
}
}
mysql_close();
?>
</form>
</body>
</html>
这篇关于php表单提交 - Q2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文