php+mysql建动态网站时,修改数据有问题。帮忙看看
<?phprequire_once('db_login.php');?><?php$conn=newmysqli($db_host,$db_username,$db_pa...
<?php require_once('db_login.php');?>
<?php
$conn=new mysqli($db_host,$db_username,$db_password,$db_database);
function GetSQLValueString($theValue,$theType,$theDefinedValue="",$theNotDefinedValue="")
{
$theValue=(!get_magic_quotes_gpc())? addslashes($theValue):$theValue;
switch($theType)
{
case "text":
$theValue=($theValue!="") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue=($theValue!="") ? intval($theValue) : "NULL";
break;
case "double":
$theValue=($theValue!="") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "data":
$theValue=($theValue!="") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue=($theValue!="") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction=$_SERVER['PHP_SELF'];
if(isset($_SERVER['QUERY_STRING']))
{
$editFormAction .="?" . htmlentities($_SERVER['QUERY_STRING']);
}
if((isset($_POST["MM_update"]))&&($_POST["MM_update"]=="form1"))
{
$updateSQL=sprintf("UPDATE book SET accounts=%s, password=%s WHERE strID=%s",
GetSQLValueString($_POST['accounts'],"text"),
GetSQLValueString($_POST['password'],"text"),
GetSQLValueString($_POST['strID'],"int"));
//mysql_select_db($db_database,$conn);
$Result1=mysqli_query($conn,$updateSQL) or die(mysql_error($conn));
$updateGoTo="comein.php";
if(isset($_SERVER['QUERY_STRING']))
{
$updateGoTo .=(strpos($updateGoTo,'?')) ? "&" : "?";
$updateGoTo .=$_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s",$updateGoTo));
}
$query= sprintf("SELECT * FROM book" );
$admin=mysqli_query($conn,$query) or die(mysqli_error($conn));
$row_admin=mysqli_fetch_assoc($admin);
$totalRows_admin=mysqli_num_rows($admin);
?>
<body>
<table width="100%" border="0" align="center">
<tr>
<td align="center" valign="middle"><font color="#cc6600" size="6">修改个人信息</font></td>
</tr>
<tr>
<td height="164"><form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST" >
<table width="100%" border="0">
<tr>
<td colspand="2" align="center" valign="middle" >账户名:<label>
<input name="accounts" type="text" id="accounts" value="<?php $row_admin['accounts']; ?>" size="20"/></label></td>
//
</tr>
<tr>
<td colspand="2" align="center" valign="middle">密码:<label>
<input name="password" type="password" id="password" value="<?php $row_admin['password']; ?>" size="20" /></label></td>
</tr >
<tr>
<td> </td>
<td align="center" valign="middle"><label>
<input name="strID" type="hidden" id="strID" value="<?php $row_admin['strID']; ?>" />
<input type="submit" name="Submit" value="修改个人信息"/>
</label></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
</form></td>
</tr>
</table>
</body> 展开
<?php
$conn=new mysqli($db_host,$db_username,$db_password,$db_database);
function GetSQLValueString($theValue,$theType,$theDefinedValue="",$theNotDefinedValue="")
{
$theValue=(!get_magic_quotes_gpc())? addslashes($theValue):$theValue;
switch($theType)
{
case "text":
$theValue=($theValue!="") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue=($theValue!="") ? intval($theValue) : "NULL";
break;
case "double":
$theValue=($theValue!="") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "data":
$theValue=($theValue!="") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue=($theValue!="") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction=$_SERVER['PHP_SELF'];
if(isset($_SERVER['QUERY_STRING']))
{
$editFormAction .="?" . htmlentities($_SERVER['QUERY_STRING']);
}
if((isset($_POST["MM_update"]))&&($_POST["MM_update"]=="form1"))
{
$updateSQL=sprintf("UPDATE book SET accounts=%s, password=%s WHERE strID=%s",
GetSQLValueString($_POST['accounts'],"text"),
GetSQLValueString($_POST['password'],"text"),
GetSQLValueString($_POST['strID'],"int"));
//mysql_select_db($db_database,$conn);
$Result1=mysqli_query($conn,$updateSQL) or die(mysql_error($conn));
$updateGoTo="comein.php";
if(isset($_SERVER['QUERY_STRING']))
{
$updateGoTo .=(strpos($updateGoTo,'?')) ? "&" : "?";
$updateGoTo .=$_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s",$updateGoTo));
}
$query= sprintf("SELECT * FROM book" );
$admin=mysqli_query($conn,$query) or die(mysqli_error($conn));
$row_admin=mysqli_fetch_assoc($admin);
$totalRows_admin=mysqli_num_rows($admin);
?>
<body>
<table width="100%" border="0" align="center">
<tr>
<td align="center" valign="middle"><font color="#cc6600" size="6">修改个人信息</font></td>
</tr>
<tr>
<td height="164"><form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST" >
<table width="100%" border="0">
<tr>
<td colspand="2" align="center" valign="middle" >账户名:<label>
<input name="accounts" type="text" id="accounts" value="<?php $row_admin['accounts']; ?>" size="20"/></label></td>
//
</tr>
<tr>
<td colspand="2" align="center" valign="middle">密码:<label>
<input name="password" type="password" id="password" value="<?php $row_admin['password']; ?>" size="20" /></label></td>
</tr >
<tr>
<td> </td>
<td align="center" valign="middle"><label>
<input name="strID" type="hidden" id="strID" value="<?php $row_admin['strID']; ?>" />
<input type="submit" name="Submit" value="修改个人信息"/>
</label></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
</form></td>
</tr>
</table>
</body> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询