>  기사  >  백엔드 개발  >  做一个表单编辑界面 求指导

做一个表单编辑界面 求指导

WBOY
WBOY원래의
2016-06-20 12:51:51820검색

<?php	$myconn=mysql_connect("localhost","root","");	mysql_select_db("login_test",$myconn);?><html>	<head>		<title>Edit</title>		<link href="css.css" rel="stylesheet" type="text/css" />	</head>	<body>		<form method="POST">			<table>				<tr class="table_head">				<td>objname</td>				<td>objinfo</td>				</tr>				<?php					$strSql="select * from table_test";					$result=mysql_query($strSql,$myconn);					while($row=mysql_fetch_array($result))					{				?>				<tr>				<td><input type="text" name="objname" value="<?php echo $row['objname']?>" /></td>				<td><input type="text" name="objinfo" value="<?php echo $row['objinfo']?>" /></td>				</tr>				<?php					}				?>			</table>		</form>			<br>							<div style="display:inline;">				<input type="submit" class="button_black"/>				<input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/>				<?php					print_r($_POST);				if(!empty($_POST)){					$objname=$_POST["objname"];					$objinfo=$_POST["objinfo"];					$strSql="update table_test set objname='$objname',objinfo='$objinfo' where objname='$objname' or objinfo='$objinfo'";					$result=mysql_query($strSql,$myconn);					echo"修改成功!";				}				?>	</body><?php mysql_close($myconn); ?></html>

新人刚学php没多久
以上代码是我脑补的
结果是post没有传入值,点击提交后text里填写的值自动变回修改前的值
求指导!


回复讨论(解决方案)

if(!$myconn){
     echo "连接失败".mysql_error();


$result=mysql_query($sql,$myconn);
if(!$result){
     die(mysql_error());
}
加多些mysql错误判断,这样代码不清楚哪里错了。

if(!$myconn){
     echo "连接失败".mysql_error();


$result=mysql_query($sql,$myconn);
if(!$result){
     die(mysql_error());
}
加多些mysql错误判断,这样代码不清楚哪里错了。


多谢指导 但是问题还是没解决

你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_POST 是不可能得到任何数据的

你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_POST 是不可能得到任何数据的


提交按钮一定要写在form里才能获得post吗? 长姿势了

你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_POST 是不可能得到任何数据的


<?php	$myconn=mysql_connect("localhost","root","");	mysql_select_db("login_test",$myconn);	if(!$myconn){    	echo "连接失败".mysql_error();	}?><html>	<head>		<title>Edit</title>		<link href="css.css" rel="stylesheet" type="text/css" />	</head>	<body>		<form method="POST">			<table>				<tr class="table_head">				<td>objname</td>				<td>objinfo</td>				</tr>				<?php					$strSql="select * from table_test";					$result=mysql_query($strSql,$myconn);					while($row=mysql_fetch_array($result))					{					$objname1=$row['objname'];					$objinfo1=$row['objinfo'];				?>				<tr>				<td><input type="text" name="objname" value="<?php echo $objname1?>" /></td>				<td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td>				</tr>				<?php					}				print_r($_POST);				if(!empty($_POST)){					$objname=$_POST["objname"];					$objinfo=$_POST["objinfo"];					$strSql="update table_test set objname='$objname',objinfo='$objinfo' where objname='$objname1' or objinfo='$objinfo1'";					$result=mysql_query($strSql,$myconn);					if(!$result){    					die(mysql_error());					}					echo"修改成功!";										/*$strSql="select * from table_test";					$result=mysql_query($strSql,$myconn);					while($row=mysql_fetch_array($result))					{					$objname1=$row['objname'];					$objinfo1=$row['objinfo'];				?>				<tr>				<td><input type="text" name="objname" value="<?php echo $objname1?>" /></td>				<td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td>				</tr>				<?php					}*/				}				?>			</table>			<br>			<div style="display:inline;">				<input type="submit" class="button_black"/>				<input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/>		</form>	</body><?php mysql_close($myconn); ?></html>

修改之后发现编辑以后只修改了表单最后一行的数据
是因为提出数据进行修改时选择的是打印表单的最后一行数据吗?
难道要按照id提出数据进行修改吗?


你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_POST 是不可能得到任何数据的


<?php	$myconn=mysql_connect("localhost","root","");	mysql_select_db("login_test",$myconn);	if(!$myconn){    	echo "连接失败".mysql_error();	}?><html>	<head>		<title>Edit</title>		<link href="css.css" rel="stylesheet" type="text/css" />	</head>	<body>		<form method="POST">			<table>				<tr class="table_head">				<td>objname</td>				<td>objinfo</td>				</tr>				<?php					$strSql="select * from table_test";					$result=mysql_query($strSql,$myconn);					while($row=mysql_fetch_array($result))					{					$objname1=$row['objname'];					$objinfo1=$row['objinfo'];				?>				<tr>				<td><input type="text" name="objname" value="<?php echo $objname1?>" /></td>				<td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td>				</tr>				<?php					}				print_r($_POST);				if(!empty($_POST)){					$objname=$_POST["objname"];					$objinfo=$_POST["objinfo"];					$strSql="update table_test set objname='$objname',objinfo='$objinfo' where objname='$objname1' or objinfo='$objinfo1'";					$result=mysql_query($strSql,$myconn);					if(!$result){    					die(mysql_error());					}					echo"修改成功!";										/*$strSql="select * from table_test";					$result=mysql_query($strSql,$myconn);					while($row=mysql_fetch_array($result))					{					$objname1=$row['objname'];					$objinfo1=$row['objinfo'];				?>				<tr>				<td><input type="text" name="objname" value="<?php echo $objname1?>" /></td>				<td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td>				</tr>				<?php					}*/				}				?>			</table>			<br>			<div style="display:inline;">				<input type="submit" class="button_black"/>				<input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/>		</form>	</body><?php mysql_close($myconn); ?></html>

修改之后发现编辑以后只修改了表单最后一行的数据
是因为提出数据进行修改时选择的是打印表单的最后一行数据吗?
难道要按照id提出数据进行修改吗?
你那个表单
" />
                 " />
这里只显示最后一条数据啊,每次循环下一次就会把上一次的值给覆盖掉,所以只会修改掉最后一条数据



你的表单里并没有提交按钮,也没有看到用于提交的 js 代码
所以 $_POST 是不可能得到任何数据的


<?php	$myconn=mysql_connect("localhost","root","");	mysql_select_db("login_test",$myconn);	if(!$myconn){    	echo "连接失败".mysql_error();	}?><html>	<head>		<title>Edit</title>		<link href="css.css" rel="stylesheet" type="text/css" />	</head>	<body>		<form method="POST">			<table>				<tr class="table_head">				<td>objname</td>				<td>objinfo</td>				</tr>				<?php					$strSql="select * from table_test";					$result=mysql_query($strSql,$myconn);					while($row=mysql_fetch_array($result))					{					$objname1=$row['objname'];					$objinfo1=$row['objinfo'];				?>				<tr>				<td><input type="text" name="objname" value="<?php echo $objname1?>" /></td>				<td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td>				</tr>				<?php					}				print_r($_POST);				if(!empty($_POST)){					$objname=$_POST["objname"];					$objinfo=$_POST["objinfo"];					$strSql="update table_test set objname='$objname',objinfo='$objinfo' where objname='$objname1' or objinfo='$objinfo1'";					$result=mysql_query($strSql,$myconn);					if(!$result){    					die(mysql_error());					}					echo"修改成功!";										/*$strSql="select * from table_test";					$result=mysql_query($strSql,$myconn);					while($row=mysql_fetch_array($result))					{					$objname1=$row['objname'];					$objinfo1=$row['objinfo'];				?>				<tr>				<td><input type="text" name="objname" value="<?php echo $objname1?>" /></td>				<td><input type="text" name="objinfo" value="<?php echo $objinfo1?>" /></td>				</tr>				<?php					}*/				}				?>			</table>			<br>			<div style="display:inline;">				<input type="submit" class="button_black"/>				<input type="button" class="button_black" value="返回" onclick="javascript:document.location.href='test.php'"/>		</form>	</body><?php mysql_close($myconn); ?></html>

修改之后发现编辑以后只修改了表单最后一行的数据
是因为提出数据进行修改时选择的是打印表单的最后一行数据吗?
难道要按照id提出数据进行修改吗?
你那个表单
" />
                 " />
这里只显示最后一条数据啊,每次循环下一次就会把上一次的值给覆盖掉,所以只会修改掉最后一条数据
谢谢!
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.