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 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器