Home  >  Article  >  Backend Development  >  做一个表单编辑界面 求指导

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

WBOY
WBOYOriginal
2016-06-20 12:51:51820browse

<?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提出数据进行修改吗?
你那个表单
" />
                 " />
这里只显示最后一条数据啊,每次循环下一次就会把上一次的值给覆盖掉,所以只会修改掉最后一条数据
谢谢!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn