Jump to content


Photo

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


  • Please log in to reply
6 replies to this topic

#1 terencevs

terencevs
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 October 2006 - 08:00 AM

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!


#2 dymon

dymon
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 23 October 2006 - 08:30 AM

Hi,
<?
$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.";

?>

Web is the future ... desktop will die ...

#3 terencevs

terencevs
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 October 2006 - 09:10 AM

Hi,

<?
$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.";

?>



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!

#4 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 23 October 2006 - 09:25 AM

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']);
note the "04" followed by a dot. this just adds 04 to the start of the number.

hope this helps.
~jay
Good luck with your coding.
Jason / ProjectFear / Jaysonic

#5 terencevs

terencevs
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 October 2006 - 09:35 AM

Thanks guys you have just made my day! Much appreciated!

#6 terencevs

terencevs
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 23 October 2006 - 10:00 AM

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]

#7 JasonLewis

JasonLewis
  • Members
  • PipPipPip
  • Advanced Member
  • 3,351 posts
  • LocationVictoria, Australia

Posted 25 October 2006 - 10:24 AM

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:

$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.";

to this:

$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.";
}

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
Good luck with your coding.
Jason / ProjectFear / Jaysonic




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users