Jump to content

Please help... Quick code needed I am a total NEWB :)


terencevs

Recommended Posts

I have a database named: mictsadb username: mictsa password: password

On this database I have a table named sms_whenup

The table has 3 fields:

ID
FullName
SMSNumber

I want someone to be able to fill in their full name and mobile number in a form and when they click in submit it adds it to the database.

Once successfully added I would like a popup that’s says "Your request was successful."

I will pickup the data from my SMS software.

Any help will be gladly appreciated!

Thanks!
Link to comment
Share on other sites

Hi,
[code]
<?
$FullName = mysql_escape_string($_POST['FullName']);
$SMSNumber = mysql_escape_string($_POST['SMSNumber']);

$conn = mysql_connect ($host, $user, $pass);
mysql_select_db ($dbName);
$query = "INSERT INTO sms_whenup ('FullName', 'SMSNumber') VALUES ('$FullName', '$SMSNumber')";
$rs = mysql_query ($query);

if ($rs)
    print "Your request was successful."; //or the popup window
else
    print "Your request was not successful.";

?>
[/code]
Link to comment
Share on other sites

[quote author=dymon link=topic=112406.msg456168#msg456168 date=1161592228]
Hi,
[code]
<?
$FullName = mysql_escape_string($_POST['FullName']);
$SMSNumber = mysql_escape_string($_POST['SMSNumber']);

$conn = mysql_connect ($host, $user, $pass);
mysql_select_db ($dbName);
$query = "INSERT INTO sms_whenup ('FullName', 'SMSNumber') VALUES ('$FullName', '$SMSNumber')";
$rs = mysql_query ($query);

if ($rs)
    print "Your request was successful."; //or the popup window
else
    print "Your request was not successful.";

?>
[/code]
[/quote]


THANKS SO MUCH!

One last question.

Do I create a form now and name the two text fields $FullName and $SMSNumber.

How do I setup the form?

Thanks!
Link to comment
Share on other sites

[code]your form would look something like this:

[code]
<form action="linktophpfile.php" method="POST">
Full Name: <input type="text" name="FullName"><br>
Mobile Number: <input type="text" name="SMSNumber" value="04"><br>
<input type="submit" value="Add to Database">
</form>
[/code]
the value in SMSNumber field just adds the 04 at the start, because mobile numbers must begin with 04.

you could even have the 04 outside the box, like this:
[code]Mobile Number: 04<input type="text" name="SMSNumber">[/code]

then in your php file have this:
[code=php:0]$SMSNumber = mysql_escape_string("04".$_POST['SMSNumber']);[/code]
note the "04" followed by a dot. this just adds 04 to the start of the number.

hope this helps.
~jay
Link to comment
Share on other sites

This is my current setup. I am still getting the "Your request was not successful." and nothing goes to the database.

What must I still do to get this working?

Attached please find screenshot of my table setup. (Screenshot from PHPMyAdmin)

THANKS!

<?

$host = "myserver";
$user = "myuser";
$pass = "mypassword";
$dbName = "mydatabase";

$FullName = mysql_escape_string($_POST['FullName']);
$SMSNumber = mysql_escape_string($_POST['SMSNumber']);

$conn = mysql_connect ($host, $user, $pass);
mysql_select_db ($dbName);
$query = "INSERT INTO sms_whenup ('FullName', 'SMSNumber') VALUES ('$FullName', '$SMSNumber')";
$rs = mysql_query ($query);

if ($rs)
    print "Your request was successful."; //or the popup window
else
    print "Your request was not successful.";

?>

UPDATE:

This is the content of my smscontact.php

<form action="smscontactp.php" method="POST">
Full Name: <input type="text" name="FullName"><br>
Mobile Number: <input type="text" name="SMSNumber" value="04"><br>
<input type="submit" value="Add to Database">
</form>

[attachment deleted by admin]
Link to comment
Share on other sites

i am asuming that smscontactp.php is the php code above and the smscontact.php contains the form etc.
also. is you ID field an auto_increment field. i dont think it is. try changing that to an auto_increment field by adding it in the EXTRA box. just click the edit and you should be able to see what i mean.

one more thing. try combining all of your query into the one string and add the curly brackets. change this:

[code=php:0]
$query = "INSERT INTO sms_whenup ('FullName', 'SMSNumber') VALUES ('$FullName', '$SMSNumber')";
$rs = mysql_query ($query);

if ($rs)
    print "Your request was successful."; //or the popup window
else
    print "Your request was not successful.";
[/code]

to this:

[code=php:0]
$query = mysql_query("INSERT INTO `sms_whenup` ('FullName','SMSNumber') VALUES ('".$FullName."', '".$SMSNumber."')") or die("Error: ".mysql_error()); //note the ".$variable.". this i think, is a good habit to get into. also try combining your query code into one variable.

if($query){
    print "Your request was successful."; //or the popup window
}else{
    print "Your request was not successful.";
}
[/code]

if you keep getting the request was not successfull try printing out your fullname and smsnumber variables then exit() the script just to see if it is receiving the variables.

Oh! one more thing. add the &lt;br&gt; tag after your fullname input box, then after the smsnumber input box. :P
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.