I am currently learning web development and trying to put together a simple application in PHP that stores SMS messages from phones of all mobile types, both smart and the non, into a MySQL database hosted on a webserver. I will do some other things later with these strings once stored, but struggling right now to get this whole thing working.
I have been trying to use this here platform: http://www.txtweb.com/
which allows delivery to web apps of a message, a "location key" in the form of an @ keyword, and the number of the texter. It then returns information to user with an html request, where all thats in the body tags gets returned. They don't have any direct examples of MySQL interfacing, nor any discussion in the forums. Here I have followed one of their code samples, can get the return text to work, but fail to get any action in the database. Does anyone out there perchance have advice of either a better method for gathering SMS messages into a MySQL database or perhaps some obvious flaws in my code? I will put what I am trying below, and much appreciate the help.
<?php
define("DB_SERVER", "...");
define("DB_USER", "...");
define("DB_PASS", "...");
define("DB_NAME", "...");
=$connection = mysql_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
die("Database connection failed: " . mysql_error()); }
$db_select = mysql_select_db(DB_NAME,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
} ?>
<html>
<head>
<meta name=\"txtweb-appkey\" content=\"VALUE ASSIGNED BY PLATFORM\">
</head>
<?php if(isset($_GET['txtweb-message'])) $message = $_GET['txtweb-message'];
if(isset($_GET['txtweb-mobile'])) $number = mysql_prep($_GET['txtweb-mobile'开发者_如何学Python]);
if(isset($_GET['txtweb-location'])) $location = mysql_prep($_GET['txtweb- location']);
$query = "INSERT INTO ... (
`Number`, 'Message', 'Location' )
VALUES (
'{$message}', '{$number}', '{$location}' )";
mysql_query($query, $connection); ?>
<body>
"message to user, yet to be determined"
</body>
</html>
<?php mysql_close($connection); ?>
You are using single quotes ('
) to encase your column names. MySQL won't like that. You should be using backticks (`) to encase column names.
Notice that Number uses backticks and Message and Location use single quotes.
`Number`, 'Message', 'Location'
try:
`Number`, `Message`, `Location`
Might be worth making a call to mysql_error ?
print mysql_error();
Call that after
mysql_query($query, $connection);
When you do this, any errors from the query are shown on the page.
精彩评论