Hullo,
I am working on a php application that is meant to respond to user requests to create accounts. For instance; whoever wants to create an account has to send a text with "Login" as the message content.
Only problem is that the mysql queries are not being executed. Can anyone help?
Here is the code I am using;

<?php
# PHP Responder Script
$msg      = $_GET["msg"];
$sender   = $_GET["sender"];
$receiver = $_GET["receiver"];
$operator = $_GET["operator"];

#$command = trim(strtolower($msg));
#
# Create response SMS messages
#
if($msg == 'Login')
{
include('includes/connect.php');
$passw = "pass123";
$password2=md5($passw);

$create_user = "INSERT INTO authentication VALUES('','Farmer','','2','$sender','$password2','1')";
$result = mysql_query($create_user);

if($result)
{
$messages = "Dear User, Your username is: ".$sender." "."Password is: ".$passw.". Thank you for registering with us";
#
# Uncomment this line to send a response message
#
echo "{GSMSMS}{}{}{"."$sender"."}{".trim($messages)."}";
}
}
?>
Member Avatar for iamthwee

Well what's the error messages?
Turn php error reporting on if you haven't already. Is is getting through the if statements (do some echos)
are the correct number of fields being inserted into the db, are the fields in order, are they the same datatypes etc etc.

Also learn to format/indent your code properly.

It does not show any error. It just does not send the messages.
The fields are in order, and I just do not understand why it is not working.
Sorry about the code indenting thingi.

I have checked, and the errors are turned on ...

Member Avatar for iamthwee

does $msg equal 'Login', make sure all upper lower case match.

what's happening in connect.php, is it affecting it?

why is there an empty entry after Farmer?

Yes, the message content is 'Login'
Farmer, is the individual who sends the text message.
The 'connect.php' includes the connection string.

When I removed the select query from the code, the message was replied. However, I want the user's details to be inserted into the database, before it is sent to the user.

I have isolated the problem, and I just realised that the script is unable to connect to the database.

Any more ideas ...

Do you get an error when connecting (have you added error checking) ?

Yes, I added a checker that determines if there is a connection to the database, and I am receiving th error message. Implying that the connection to the database is not being made. Here is the code I am working with at the moment;

<?php
# PHP Responder Script
$msg = $_GET["msg"];
$sender = $_GET["sender"];
$receiver = $_GET["receiver"];
$operator = $_GET["operator"];

#$command = trim(strtolower($msg));
#
# Create response SMS messages
#
if($msg == 'Login')
{
    $link = mysql_connect('localhost','root','');
    mysql_select_db('agriculture_advisory',$link);

    if($link)
    {
        $selects = "SELECT firstName FROM authentication";
        mysql_query($selects);
        $results=mysql_query($selects);
        while($row=mysql_fetch_array($results))
        {
            $nut = $row['fistName'];
        }
        $messages = "Nutrition Tips:"."".$nut.""."THANK YOU FOR USING PATIENT MONITOR";
        #
        # Uncomment this line to send a response message
        #
        echo "{GSMSMS}{}{}{"."$sender"."}{".trim($messages)."}";
    }
    else
    {
        $message = "Unable to connect to database";
        #
        # Uncomment this line to send a response message
        #
        echo "{GSMSMS}{}{}{"."$sender"."}{".trim($message)."}";
    }
}
?>

At the moment, when I send a text message, I recieve the responce as "Unable to connect to database"
I dunno what to do ...

Change 14 and 15:

$link = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('agriculture_advisory', $link) or die(mysql_error());

Remove line 20.

Ok, lemme try that ...

Tried that out, but I still get the same error ....

That shouldn't be possible. I suggest you debug with an IDE, or use old-style echo's to trace the code.

I thought the same thing. However, when an SMS comes in, the message is logged into the database. I see that it is received; however, the script is just not sendiong out a responce ... I dunno why.

Is it something that I am missing out?? or is it my database connection?

I tried almost everything, but failed, so I used the crude way of inserting the message I want to send into the ozekimessage out and it seems to be responding now.

Thanx for all your comments.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.