>  기사  >  백엔드 개발  >  这段代码一直有异常,麻烦大神看下

这段代码一直有异常,麻烦大神看下

PHP中文网
PHP中文网원래의
2017-03-21 14:29:28960검색

<a href =&#39;index.php&#39; >返回留言板</a><hr><hr>
<?php
/*

 * To change the template for this generated file go to

 * Window - Preferences - PHPeclipse - PHP - Code Templates

 */
require("conn.php");
 $user=$_POST[&#39;user&#39;];
 $title=$_POST[&#39;title&#39;];
$content=$_POST[&#39;content&#39;];
$sql_luck="insert into sny (id,user,title,content,lastDate)value(&#39;&#39;,&#39;$user&#39;,&#39;$title&#39;,&#39;$content&#39;,now())"	
 $sql="SELECT user FROM sny WHERE user=&#39;$user&#39;";
 $query =mysql_query($sql);
 $rows=mysql_fetch_array($query);
if((!empty($_POST[&#39;sub&#39;]))and($rows[&#39;user&#39;]==$user)){
//echo $content;
 	echo "<script>alert(&#39;用户已存在,请重新输入&#39;);location.href=&#39;add2.php&#39;</script>" ;exit;  
  mysql_free_result($query);exit;
 }
 else{
  mysql_query($sql_luck);
  echo"<script>alert(&#39;哟!成功!&#39;);location.href=&#39;index.php&#39;</script>";
  echo "插入成功";
 }
?>
<form action="add.php" method="post">
用户:<input type="text" name="user" value="请输入用户名" size="20" maxlength="10"/><br/>
标题:<input type="text" name="title" value="请输入内容" size="40" maxlength="40"/><br/>
内容:<textarea name="content" rows="10" cols="50" wrap="off">
text</textarea>
 <br/>
  <input type="submit" name="sub" value="Release"/><br/>
  <form/>

解决方案

你if判断仔细看看里边缕缕。好么?

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.