在数据库$ _GET零星不必要的空条目 [英] sporadic unwanted null entries in database $_GET

查看:118
本文介绍了在数据库$ _GET零星不必要的空条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点点温度protocoling Web应用程序,在那里度得到调整页面上,并保存在数据库中。

I have a little temperature protocoling web app, where degrees get adjusted on a page and saved in a database.

它的工作原理,但是从用户,我不能重现时有发生偶发性错误!

It works, but sometimes sporadic errors occur from users which I can't reproduce!

有时在数据库空项,我不知道如何和为什么。这空的孔排(每天几个温度可选)。

如果如没有温度得到了在一个div字符串NA应交给分贝选择。此错误是如此有弹性,我不知道还有什么地方转向。

If e.g. no temp got selected in a div string "NA" should be handed to the db. This bug is so resilient, I don't know where else to turn to.

阿贾克斯点击箭头增加值

$(".arrow_up").die('click');        
$(".arrow_up").live('click',function() {
    var value = $("#temp_"+this.id).html();
    if (value=="NA") {value=$("#istemp_"+this.id).html()}
            var newValue = parseInt(value)+ 1;

手价值转移到服务器

$(document).ready(function() {
$('#save').die('click');                       
$("#save").live('click',function() {
    var tempA=$("#temp_itemA").html();
    var tempB=$("#temp_itemB").html();          

PHP有存储它

我看,如果它不是空的,也不该字符串空被移交。最后一个动作错误。

I look if it isn't empty nor that the string null gets handed over. Last one throws Error.

<?php
    if((!isset($_GET['tempA'])) || (!isset($_GET['tempB'])) || ($_GET['tempA']!='null')
      {
        echo "values are missing";
      }
    else 
    {
    error_reporting(E_ALL);
    try {
        $dbh = new PDO('sqlite:/var/www/xxx.sqlite');
        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  

    $date=date("Y-m-d",time());
    $sql = "SELECT * FROM tableTemp WHERE date='".$date."'";    
    $result = $dbh->query($sql);
    foreach($result as $row) {
        $id = $row['id'];
    }

    if (!empty($id)) {
        $sql = "UPDATE tableTemp SET tempA='".$_GET['tempA']."',tempB='".$_GET['tempB']"'";
        $result = $dbh->query($sql);
    }

    else {
        $sql = "INSERT INTO tableTemp ('tempA','tempB')";
        $result = $dbh->query($sql)
?>

我的意思是,这是因为它得到一样简单。我只能想象trasmitting错误可能是与WIFI和数据包丢失。

I mean, this is as simple as it gets. I can only imagine the trasmitting errors might have something to do with WIFI and packet loss.

我如何能停止插入(丢弃)这些讨厌的空串入数据库,并抛出一个错误,让用户再次尝试吗?我的!使用isset不起作用,因为它不是空

推荐答案

请注意这大概说明明显

但你能不能规定在DB列要求值不为空,然后赶上在插入错误

But can you not stipulate that the column in the DB requires a value that is not null then catch the error on the insert

你见过这个答案?

http://stackoverflow.com/a/2103256/1479565

这篇关于在数据库$ _GET零星不必要的空条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆