PHP变量插入数据库 [英] php variable insert into database

查看:63
本文介绍了PHP变量插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些php变量插入到Mysql数据库中而没有运气.连接没有问题,变量都具有值,所以我必须是我的插入语句.我一直在浏览网络,尝试了很多其他方法,但是都没有运气.这是代码:

I am attempting to insert some php variables into a Mysql database with no luck. The connection works no problem, the variables all have values, so I must be my insert statement. I have been browsing the web and tried a ton of alternative methods with no luck. Here is the code:

<?php

$connection = mysql_connect('localhost', 'username', 'password') or die (mysql_error());
mysql_select_db('table', $connection) or die (mysql_error());

$message = $_POST["Body"];

$data = explode("*", $message);

$id = '';
$phone = $_POST["From"];
$location = $data[0];
$speed = $data[1];
$direction = $data[2];
$comment = $data[3];


$query = mysql_query("INSERT INTO user_data (id, phone, location, speed, direction, comment) VALUES ('$id', '$phone', '$location', '$speed', '$direction', '$comment')");

我已经进行了测试,以确保变量包含数据,并且还测试了所有连接,除此之外一切正常!任何帮助将是巨大的!

I have tested to make sure the variables contain data, and I have also tested all connections, everything works perfect except for this! Any help would be great!

推荐答案

尝试将变量名包含在{}中,即

Try enclosing variable names in { }, i.e.

'{$speed}'

这篇关于PHP变量插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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