douzong6649 2012-01-30 06:34
浏览 41
已采纳

无法将UDID从iPhone发送到PHP到MySQL数据库

I am having difficulties sending the UDID from the iPhone to a PHP script to my MySQL database. I am not having a problem POSTing the data to the PHP script, but for some reason the PHP is not putting it into the database. I have tried entering "12343214312" as my example UDID and thats working, but the actual UDID is not for some reason. Is it some formatting mistake I am making?

Here is my code for the PHP:

<?php

    $udidfromiphone = $_POST['udidfromiphone'];
    //Connect To Database
    $hostname='HOSTNAME.db.7774297.hostedresource.com';
    $username='USERNAME';
    $password='PASSWORD';
    $dbname='DBNAME';

    mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
    mysql_select_db($dbname);

$query = "INSERT INTO mydatabase VALUES ($udidfromiphone,'7')";
    echo "Values added";
    mysql_query($query);


     mysql_close();   
?>

In my MySQL, I have two fields, one for UDID which is a varchar(60) and another field which is an integer.

Thanks!!

  • 写回答

1条回答 默认 最新

  • duanpai6581 2012-01-30 06:53
    关注
    INSERT INTO mydatabase VALUES ($udidfromiphone,'7')
    

    When trying this with a number, the query becomes like this:

    INSERT INTO mydatabase VALUES (12345678,'7')
    

    That's valid SQL. A UDID consists of letters and numbers though, so the query will be like this:

    INSERT INTO mydatabase VALUES (ABCDE12345FGHI,'7')
    

    That's not correct SQL. Quote your strings:

    INSERT INTO mydatabase VALUES ('$udidfromiphone','7')
    

    Furthermore, this is prone to SQL injection. Escape your values. Google for "SQL injection", there's a ton of material about it out there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里