terencevs Posted October 23, 2006 Share Posted October 23, 2006 I have a database named: mictsadb username: mictsa password: passwordOn this database I have a table named sms_whenupThe table has 3 fields:IDFullNameSMSNumberI 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! Quote Link to comment Share on other sites More sharing options...
dymon Posted October 23, 2006 Share Posted October 23, 2006 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 windowelse print "Your request was not successful.";?>[/code] Quote Link to comment Share on other sites More sharing options...
terencevs Posted October 23, 2006 Author Share Posted October 23, 2006 [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 windowelse 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! Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 23, 2006 Share Posted October 23, 2006 [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 Quote Link to comment Share on other sites More sharing options...
terencevs Posted October 23, 2006 Author Share Posted October 23, 2006 Thanks guys you have just made my day! Much appreciated! Quote Link to comment Share on other sites More sharing options...
terencevs Posted October 23, 2006 Author Share Posted October 23, 2006 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 windowelse 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] Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 25, 2006 Share Posted October 25, 2006 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 windowelse 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 <br> tag after your fullname input box, then after the smsnumber input box. :P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.