Home  >  Article  >  Backend Development  >  不能插入,但能更新数据

不能插入,但能更新数据

WBOY
WBOYOriginal
2016-06-23 13:22:2145721browse

我的页面,在本地时插入和更新数据都没有问题。上传服务器后,这个页面更新数据可以,但是不能插入数据。大侠们能给个解决思路么?谢谢。


回复讨论(解决方案)

先看一下有无插入权限

您是说是空间里数据库设置的问题么?我的EDIT页面上传空间后只能更新而不能插入,login页面上传空间后也可以插入。

我的edit页面代码为


 session_start () ;
include("IncDB.php"); 
//处理提交的修改 @allprojects @todo  multi-query
@$uid=$_SESSION['id'];
if(!empty($_POST['submit'])) {
$bid=$_POST['bid']; 
$bidt=addslashes($_POST['title']); 
$bidl=addslashes($_POST['links']); 

$result1=mysql_query("SELECT * FROM userlinks where id='$bid' and userid='".$_SESSION['id']."'",$link);
$row1=mysql_fetch_row($result1);
if($row1==null)
{
 $sql ="INSERT INTO `userlinks` (`id`,`title`, `links`,`userid`,`datetime`) VALUES ('$bid','$bidt','$bidl','".$_SESSION['id']."',now());";}
else{

$sql="update userlinks set title = '$bidt' ,links = '$bidl',userid='".$_SESSION['id']."',datetime=now() where id= '$bid';";
}



if(mysql_query($sql)){
echo "<script>parent.location.reload();</script>";
}else echo "<script>parent.location.reload();</script> ";


exit();


}





$bid=addslashes($_GET['id']); 


$result=mysql_query("SELECT * FROM userlinks where id ='".$bid."'and userid='$uid' order by datetime desc limit 1",$link);
@$row=mysql_fetch_row($result); 





?> 

 
" type="hidden" />
  
    
      
      
    




if($row==null) 
{$bid=addslashes($_GET['id']); 
$result1=mysql_query("SELECT * FROM links where id ='".$bid."'",$link); 
$row1=mysql_fetch_row($result1); 
while($row1) 
{ echo " "; 

$row1=mysql_fetch_row($result1); 
}

mysql_close($link); 
}
else
while($row) 

{

echo " "; 
}
$row=mysql_fetch_row($result); 

@mysql_close($link); 
?> 




标题 内容
";
echo "";
echo " 
";
echo "";
echo " 
";
echo "";
echo " 
";
echo "";
echo " 






   
 

红色的代码即是。我从后台添加数据后,再用update没有问题;但是不能插入。而上面这个代码在本地测试时插入和更新都没有问题。

把 
if(mysql_query($sql)){
echo "<script>parent.location.reload();</script>";
}else echo "<script>parent.location.reload();</script> ";

改成
if(mysql_query($sql)){
echo "<script>parent.location.reload();</script>";
}else  echo mysql_error(); //echo "<script>parent.location.reload();</script> ";
看看
因为你说本地可以,服务器不可以。所以应先检查权限
既然后台能插入,那么就应考虑是否是程序问题了

好的,我试试,谢谢!!

真牛X!又解决了。佩服佩服!

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