The code below allows my users to add an item ($site) to a table ($find). It works well. But every once in a while, it adds a blank value to the table in addition to the one the value the user adds.

下面的代码允许我的用户将一个项目($ site)添加到表($ find)。它运作良好。但是每隔一段时间,除了用户添加的值之外,它还会向表中添加一个空白值。

Any ideas why?

有什么想法吗?

Thanks in advance,

提前致谢,

John

<?

$find1 = urlencode($find); 

print   "<div class=\"siteadd\">
        <form action='bookprocess.php?find=$find1' method='post'>
        Add an item: <input name='site' type='text' size='50'>
        <input type='submit' value='Submit'>
        </form> 
        </div>";
?>

Then, on bookprocess.php:

然后,在bookprocess.php上:

<?
$remove_array = array('http://www.', 'http://', 'https://', 'https://www.', 'www.');
$site = str_replace($remove_array, "", $_POST['site']);
$site = strtolower($site);

function check_porn_terms($input){
     $porn_terms = array(here are a lot of swear words and porn terms); //add terms here
     foreach($porn_terms as $term){
          if(substr_count($input, $term) > 0) return false;
     }

     return true;
}


if(!check_porn_terms($_POST['site']))
{

   session_write_close();
   header("Location:http://www.site.com/index.php");
   exit;

}


mysql_connect("mysqlv10", "username", "password") or die(mysql_error());
mysql_select_db("bookfeather") or die(mysql_error());

$_GET['find'] = $find;
$find = urldecode($find);
$find = mysql_real_escape_string($find);

$site = mysql_real_escape_string($site);
$illegal = array("/", "\"");
$site = str_replace($illegal, '', $site);

mysql_query("INSERT INTO `$find` VALUES (NULL, '$site',1,0)");
?>

1 个解决方案

#1


You should check to be sure the user actually entered something.

您应该检查以确保用户确实输入了某些内容。

Something along the lines of:

有点像:

if(trim($find) && trim($site)) {
  mysql_query("INSERT INTO `$find` VALUES (NULL, '$site',1,0)");
} else {
  print "You must enter values!";
}

更多相关文章

  1. 根据网址上的国家/地区将用户重定向到正确的数据库,我使用i18n fo
  2. PHP结合Redis来限制用户或者IP某个时间段内访问的次数
  3. 使用JOIN获取有关两个用户的信息
  4. PHP:如果用户没有按下提交按钮,则Mysql回滚多个查询(通过ajax完成)
  5. Zend数据库适配器-未捕获异常-堆栈跟踪显示用户名和密码
  6. 在MySQL数据库中存储无法访问的用户
  7. init-connectMysql对用户操作加审计功能
  8. mysql user表root 用户修改权限后出现无法访问数据库的解决方法
  9. Linux下修改MySQL初始密码、开启远程登录、授权远程登录用户

随机推荐

  1. Android构建时报错: java.io.IOException:
  2. Android开发者的Ane简单入门
  3. android底层开发-android基础架构
  4. android开发中常用的五大布局
  5. Android的UI组件之TextView、EditText
  6. Android_传感器综述
  7. Android(安卓)ListView圆角实现
  8. Android使用FFmpeg(二)--Android Studio
  9. Android五个布局
  10. Android SVG动画PathView源码解析与使用