Avatar of sodapop7
sodapop7 asked on

How do I create a sample posting URL string to pass form data?

Hi,
I have created a form that posts data collected from a form into a MySQL database. It works fine, but the client said they need a sample posting url string, so they can use that to pass the form data directly. Can someone please help me.

Here is what I have so far below:
PHP CODE:
 
<?php
$con = mysql_connect("myserver.com","user","pass"); //Replace with your actual MySQL DB Username and Password
if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("eletha", $con); //Replace with your MySQL DB Name
$firstname=mysql_real_escape_string($_POST['firstname']); //This value has to be the same as in the HTML form file
$lastname=mysql_real_escape_string($_POST['lastname']); //This value has to be the same as in the HTML form file
$address=mysql_real_escape_string($_POST['address']); //This value has to be the same as in the HTML form file
$city=mysql_real_escape_string($_POST['city']); //This value has to be the same as in the HTML form file
$state=mysql_real_escape_string($_POST['state']); //This value has to be the same as in the HTML form file
$email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file
$phone=mysql_real_escape_string($_POST['phone']); //This value has to be the same as in the HTML form file
$phone2=mysql_real_escape_string($_POST['phone2']); //This value has to be the same as in the HTML form file
$contactime=mysql_real_escape_string($_POST['contactime']); //This value has to be the same as in the HTML form file
$mortgage_amount=mysql_real_escape_string($_POST['mortgage_amount']); //This value has to be the same as in the HTML form file
$months_behind=mysql_real_escape_string($_POST['months_behind']); //This value has to be the same as in the HTML form file
$zip=mysql_real_escape_string($_POST['zip']); //This value has to be the same as in the HTML form file
 
 
$sql="INSERT INTO LEADS (firstname,lastname,address,city,state,email,phone,phone2,contactime,mortgage_amount,months_behind,zip) VALUES ('$firstname','$lastname','$address','$city','$state','$email','$phone','$phone2','$contactime','$mortgage_amount','$months_behind','$zip')"; /*form_data is the name of the MySQL table where the form data will be saved.
 
name and email are the respective table fields*/
if (!mysql_query($sql,$con)) {
 die('Error: ' . mysql_error()); 
} 
echo "The form data was successfully added to your database.";
echo "<br />";
echo "<br />";
 
echo "firstname=";
echo $_POST['firstname'];
echo "<br />";
 
echo "lastname=";
echo $_POST['lastname'];
echo "<br />";
 
echo "address=";
echo $_POST['address'];
echo "<br />";
 
echo "city=";
echo $_POST['city'];
echo "<br />";
 
echo "state=";
echo $_POST['state'];
echo "<br />";
 
echo "zip=";
echo $_POST['zip'];
echo "<br />";
 
echo "email=";
echo $_POST['email'];
echo "<br />";
 
echo "phone=";
echo $_POST['phone'];
echo "<br />";
 
echo "phone2=";
echo $_POST['phone2'];
echo "<br />";
 
echo "contact time=";
echo $_POST['contactime'];
echo "<br />";
 
echo "mortgage amount=";
echo $_POST['mortgage_amount'];
echo "<br />";
 
echo "months behind=";
echo $_POST['months_behind'];
echo "<br />";
 
mysql_close($con);
?>
 
 
HTML CODE for FORM
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lead Form</title>
<link rel="stylesheet" href="main.css" type="text/css">
<style type="text/css">
<!--
.style1 {font-family: Verdana, Arial, Helvetica, sans-serif}
.style3 {font-size: 12px}
.style4 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000066; }
.style5 {color: #000066}
.style6 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; color: #000066; font-weight: bold; }
-->
</style>
</head>
 
<body>
<table width="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><FORM name='myform' action="leadForm.php" method="POST">
                    <table width="418" height="100%" border="0" align="center" cellpadding="2" cellspacing="2" bordercolor="#000000" class="style8">
                        <tr>
                          <td colspan="2"><div align="left" class="style6">LEAD FORM</div></td>
                        </tr>
                        <tr>
                          <td colspan="2"><div align="left" class="style4">* indicates required field</div></td>
                        </tr>
                        <tr>
                          <td width="157" valign="middle"><span class="style4">First Name:*</span></td>
                          <td width="247" class="question"><input maxlength=30 size=30 name="firstname" value="" id="firstname" /></td>
                        </tr>
                        <tr>
                          <td valign="middle"><span class="style4">Last Name:*</span> </td>
                          <td class="question"><input maxlength=30 size=30 name="lastname" id="lastname" /></td>
                      </tr>
                        
                        <tr>
                          <td valign="middle"><span class="style4">Street Address*</span></td>
                          <td class="question"><input maxlength="30" size="30" name="address" id="address" /></td>
                        </tr>
                        <tr>
                          <td valign="middle"><span class="style4">City:*</span></td>
                          <td class="question"><input name="city" id="city" size="20" maxlength=20 /></td>
                        </tr>
                        <tr>
                          <td valign="middle"><span class="style4">State:*</span></td>
                          <td class="question"><select name="state" id="state">
                            <option selected>-- select -- </option>
                            <option value="AL" > Alabama </option>
                            <option value="AK" > Alaska </option>
                            <option value="AZ" > Arizona </option>
                            <option value="AR" > Arkansas </option>
                            <option value="CA" > California </option>
                            <option value="CO" > Colorado </option>
                            <option value="CT" > Connecticut </option>
                            <option value="DE" > Delaware </option>
                            <option value="DC" > District of Columbia </option>
                            <option value="FL" > Florida </option>
                            <option value="GA" > Georgia </option>
                            <option value="HI" > Hawaii </option>
                            <option value="ID" > Idaho </option>
                            <option value="IL" > Illinois </option>
                            <option value="IN" > Indiana </option>
                            <option value="IA" > Iowa </option>
                            <option value="KS" > Kansas </option>
                            <option value="KY" > Kentucky </option>
                            <option value="LA" > Louisiana </option>
                            <option value="ME" > Maine </option>
                            <option value="MD" > Maryland </option>
                            <option value="MA" > Massachusetts </option>
                            <option value="MI" > Michigan </option>
                            <option value="MN" > Minnesota </option>
                            <option value="MS" > Mississippi </option>
                            <option value="MO" > Missouri </option>
                            <option value="MT" > Montana </option>
                            <option value="NE" > Nebraska </option>
                            <option value="NV" > Nevada </option>
                            <option value="NH" > New Hampshire </option>
                            <option value="NJ" > New Jersey </option>
                            <option value="NM" > New Mexico </option>
                            <option value="NY" > New York </option>
                            <option value="NC" > North Carolina </option>
                            <option value="ND" > North Dakota </option>
                            <option value="OH" > Ohio </option>
                            <option value="OK" > Oklahoma </option>
                            <option value="OR" > Oregon </option>
                            <option value="PA" > Pennsylvania </option>
                            <option value="RI" > Rhode Island </option>
                            <option value="SC" > South Carolina </option>
                            <option value="SD" > South Dakota </option>
                            <option value="TN" > Tennessee </option>
                            <option value="TX" > Texas </option>
                            <option value="UT" > Utah </option>
                            <option value="VT" > Vermont </option>
                            <option value="VA" > Virginia </option>
                            <option value="WA" > Washington </option>
                            <option value="WV" > West Virginia </option>
                            <option value="WI" > Wisconsin </option>
                            <option value="WY" > Wyoming </option>
                          </select></td>
                        </tr>
                        <tr>
                          <td valign="middle"><span class="style4">Zip:*</span></td>
                          <td class="question"><input maxlength=8 size=8 name="zip" id="zip" /></td>
                        </tr>
                        <tr>
                          <td valign="middle"><span class="style4">E-mail:*</span></td>
                          <td class="question"><input maxlength="30" size=30 name="email" id="email" /></td>
                        </tr>
                        <tr>
                          <td valign="middle"><span class="style4">Best Contact #:*</span></td>
                          <td class="question"><input type="text" name="phone" size="15" maxlength="10" id="phone" /></td>
                        </tr>
                        
                        <tr>
                          <td height="27" valign="middle"><span class="style4">Second Contact #:</span></td>
                          <td class="question"><input type="text" name="phone2" size="15" maxlength="10" id="phone2" /></td>
                        </tr>
                        
                        <tr>
                          <td valign="middle"><span class="style4">Best Time to Contact?*</span></td>
                          <td class="question"><select name="contactime" id="contactime">
                            <option value="morning" selected="selected">Morning</option>
                            <option value="afternoon">Afternoon</option>
                            <option value="evening">Evening</option>
                          </select>                          </td>
                        </tr>
                        
                        <tr>
                          <td valign="middle"><span class="style4">Mortgage Amount:*</span></td>
                          <td class="question"><select name="mortgage_amount" id="mortgage_amount">
                            <option value="" selected>Select Range</option>
									<option value="100000">100,001 - 105,000</option>
									<option value="107500">105,001 - 110,000</option>
									<option value="112500">110,001 - 115,000</option>
 
					
									<option value="117500">115,001 - 120,000</option>
									<option value="122500">120,001 - 125,000</option>
									<option value="127500">125,001 - 130,000</option>
									<option value="132500">130,001 - 135,000</option>
									<option value="137500">135,001 - 140,000</option>
									<option value="142500">140,001 - 145,000</option>
 
					
									<option value="147500">145,001 - 150,000</option>
									<option value="152500">150,001 - 155,000</option>
									<option value="157500">155,001 - 160,000</option>
									<option value="162500">160,001 - 165,000</option>
									<option value="167500">165,001 - 170,000</option>
									<option value="172500">170,001 - 175,000</option>
 
					
									<option value="177500">175,001 - 180,000</option>
									<option value="182500">180,001 - 185,000</option>
									<option value="187500">185,001 - 190,000</option>
									<option value="192500">190,001 - 195,000</option>
									<option value="197500">195,001 - 200,000</option>
									<option value="205000">200,001 - 210,000</option>
 
					
									<option value="215000">210,001 - 220,000</option>
									<option value="225000">220,001 - 230,000</option>
									<option value="235000">230,001 - 240,000</option>
									<option value="245000">240,001 - 250,000</option>
									<option value="255000">250,001 - 260,000</option>
									<option value="265000">260,001 - 270,000</option>
 
					
									<option value="275000">270,001 - 280,000</option>
									<option value="285000">280,001 - 290,000</option>
									<option value="295000">290,001 - 300,000</option>
									<option value="305000">300,001 - 310,000</option>
									<option value="315000">310,001 - 320,000</option>
									<option value="325000">320,001 - 330,000</option>
 
					
									<option value="335000">330,001 - 340,000</option>
									<option value="345000">340,001 - 350,000</option>
									<option value="355000">350,001 - 360,000</option>
									<option value="365000">360,001 - 370,000</option>
									<option value="375000">370,001 - 380,000</option>
									<option value="385000">380,001 - 390,000</option>
 
					
									<option value="395000">390,001 - 400,000</option>
									<option value="410000">400,001 - 420,000</option>
									<option value="430000">420,001 - 440,000</option>
									<option value="450000">440,001 - 460,000</option>
									<option value="470000">460,001 - 480,000</option>
									<option value="490000">480,001 - 500,000</option>
 
					
									<option value="510000">500,001 - 520,000</option>
									<option value="530000">520,001 - 540,000</option>
									<option value="550000">540,001 - 560,000</option>
									<option value="570000">560,001 - 580,000</option>
									<option value="590000">580,001 - 600,000</option>
									<option value="610000">600,001 - 620,000</option>
 
					
									<option value="630000">620,001 - 640,000</option>
									<option value="650000">640,001 - 660,000</option>
									<option value="670000">660,001 - 680,000</option>
									<option value="690000">680,001 - 700,000</option>
									<option value="710000">700,001 - 720,000</option>
									<option value="730000">720,001 - 740,000</option>
 
					
									<option value="750000">740,001 - 760,000</option>
									<option value="770000">760,001 - 780,000</option>
									<option value="790000">780,001 - 800,000</option>
									<option value="810000">800,001 - 820,000</option>
									<option value="830000">820,001 - 840,000</option>
									<option value="850000">840,001 - 860,000</option>
 
					
									<option value="870000">860,001 - 880,000</option>
									<option value="890000">880,001 - 900,000</option>
									<option value="910000">900,001 - 920,000</option>
									<option value="930000">920,001 - 940,000</option>
									<option value="950000">940,001 - 960,000</option>
									<option value="970000">960,001 - 980,000</option>
 
					
									<option value="990000">980,001 - 1,000,000</option>
									<option value="1250000">1,000,001 - 1,500,000</option>
									<option value="1750000">1,500,001 - 2,000,000</option>
									<option value="2250000">2,000,001 - 2,500,000</option>
									<option value="2750000">2,500,001 - 3,000,000</option>
									<option value="3250000">3,000,001 - 3,500,000</option>
									<option value="3750000">3,500,001 - 4,000,000</option>
									<option value="4250000">4,000,001 - 4,500,000</option>
									<option value="4750000">4,500,001 - 5,000,000</option>
									<option value="5250000">5,000,001 - 5,500,000</option>
									<option value="5750000">5,500,001 - 6,000,000</option>
									<option value="6250000">6,000,001 - 6,500,000</option>
									<option value="6750000">6,500,001 - 7,000,000</option>
									<option value="7000001">Over 7,000,001</option>
                          </select>                          </td>
                        </tr>
                        <tr>
                          <td valign="middle"><span class="style4">Months Behind:*</span></td>
                          <td class="question"><select name="months_behind" id="months_behind">
                            <option value="1" selected="selected">1</option>
                            <option value="2">2</option>
                            <option value="3">3</option>
                            <option value="4">4</option>
                            <option value="5">5</option>
                            <option value="6">6</option>
                            <option value="7">7</option>
                            <option value="8">8</option>
                            <option value="9">9</option>
                            <option value="10">10</option>
                            <option value="11">11</option>
                            <option value="12">12</option>
                          </select>                          </td>
                        </tr>
                          <tr>
                          <td colspan="2" valign="top">&nbsp;</td>
                          </tr>
                        <tr class="question">
                          <td height="44" colspan="2" rowspan="2"><div align="center" class="style19 style1 style3 style5">
                            <input value="submit" type="submit" name="submit" />
                          </div></td>
                        </tr>
                    </table>
                 </form>
                 </td>
  </tr>
</table>
</body>
</html>

Open in new window

PHPWeb Languages and Standards

Avatar of undefined
Last Comment
patrad

8/22/2022 - Mon
ludofulop

i'm not sure if i understand, but...

do they want to send data using POST or GET method ?
in both cases you will probably need to send them list of your variable (input element names) and the URL of your script.

in case of sending data GET, you will have to modify your script to get data from $_GET instead of $_POST.
or (best solution) you can accept both GET and POST variables
ASKER
sodapop7

The example they sent uses "POST" ...
 
I need a sample string to send back to them....
 
their instructions also say:

All url variables must be url-encoded. :   Encoding for [space] = +
    Encoding for & = %26
    Encoding for / = %2f
    Encoding for : = %3a    
    Ex: 1 A B = A+B     where space is +
    Ex: 2 A & B = A+%26+B where space is + and & is %26
    Ex: 3 8:12:30 = 8%3a12%3a30     where : is %3a
    Ex: 4 01/10/2008 = 01%2f10%2f2008
        where / is %2f
Date must be formatted as follows 01/01/0001 00:00:00 mm/dd/yyyy hh:mm:ss
    Encoded as previously stated = 01%2f01%2f2008+00%3a00%3a00  
Response Header Result The response header contains a variable with and id of Action Headers["Action"]
If response action is "success" there were no problems.  
ludofulop

i'm sorry, but now i'm totally confused, i think i don't understand what's the reason for this... do they want to submit data from their form to your script?
maybe giving them GET style params url will be enough.. this means
firstname=test&lastname=test&......
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER
sodapop7

They want to send us leads/data using a url string.
Can you help me set the string up with our variables? They only need 1 sample, because they will take that sample and put it in their code (which is a code that collects leads), they'll then pass those leads to us, which should write to our MySQL database.
I think that the params will work...what would the entire url be?
ASKER
sodapop7

Here is what i developed:
 
http://www.elethal.com/elethalLeads/leadForm.php?firstname=Kamia&lastname=Kindle&address=123&city=greenwood&state=missouri&email=kamia2000@aol.com&phone=8167656262&phone2=8167652222&contactime=mor&mortgage_amount=107500+months_behind=4&zip=64137
 
But it gives me this:
(see code snippet)
 
And nothing writes to the DB

The form data was successfully added to your database.
 
firstname=
lastname=
address=
city=
state=
zip=
email=
phone=
phone2=
contact time=
mortgage amount=
months behind=
PHP Notice: Undefined index: firstname in D:\webs\eletha\elethalLeads\leadForm.php on line 8 PHP Notice: Undefined index: lastname in D:\webs\eletha\elethalLeads\leadForm.php on line 9 PHP Notice: Undefined index: address in D:\webs\eletha\elethalLeads\leadForm.php on line 10 PHP Notice: Undefined index: city in D:\webs\eletha\elethalLeads\leadForm.php on line 11 PHP Notice: Undefined index: state in D:\webs\eletha\elethalLeads\leadForm.php on line 12 PHP Notice: Undefined index: email in D:\webs\eletha\elethalLeads\leadForm.php on line 13 PHP Notice: Undefined index: phone in D:\webs\eletha\elethalLeads\leadForm.php on line 14 PHP Notice: Undefined index: phone2 in D:\webs\eletha\elethalLeads\leadForm.php on line 15 PHP Notice: Undefined index: contactime in D:\webs\eletha\elethalLeads\leadForm.php on line 16 PHP Notice: Undefined index: mortgage_amount in D:\webs\eletha\elethalLeads\leadForm.php on line 17 PHP Notice: Undefined index: months_behind in D:\webs\eletha\elethalLeads\leadForm.php on line 18 PHP Notice: Undefined index: zip in D:\webs\eletha\elethalLeads\leadForm.php on line 19 PHP Notice: Undefined index: firstname in D:\webs\eletha\elethalLeads\leadForm.php on line 33 PHP Notice: Undefined index: lastname in D:\webs\eletha\elethalLeads\leadForm.php on line 37 PHP Notice: Undefined index: address in D:\webs\eletha\elethalLeads\leadForm.php on line 41 PHP Notice: Undefined index: city in D:\webs\eletha\elethalLeads\leadForm.php on line 45 PHP Notice: Undefined index: state in D:\webs\eletha\elethalLeads\leadForm.php on line 49 PHP Notice: Undefined index: zip in D:\webs\eletha\elethalLeads\leadForm.php on line 53 PHP Notice: Undefined index: email in D:\webs\eletha\elethalLeads\leadForm.php on line 57 PHP Notice: Undefined index: phone in D:\webs\eletha\elethalLeads\leadForm.php on line 61 PHP Notice: Undefined index: phone2 in D:\webs\eletha\elethalLeads\leadForm.php on line 65 PHP Notice: Undefined index: contactime in D:\webs\eletha\elethalLeads\leadForm.php on line 69 PHP Notice: Undefined index: mortgage_amount in D:\webs\eletha\elethalLeads\leadForm.php on line 73 PHP Notice: Undefined index: months_behind in D:\webs\eletha\elethalLeads\leadForm.php on line 77  

Open in new window

ludofulop

the url will be http://yourserver/yourscript.php?firstname=test&lastname=test&....
but this is GET method to send parameters to your script...

if they are sending it using POST (using sockets, or other way), then they need 2 informations:
your script url: http://yourserver/yourscript.php
submited data format: firstname=test&lastname=test&....

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
ludofulop

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
sodapop7

OK - in response for your CASE ID: 23469514
I am finding out right now if it matters POST vs GET. If GET is ok, i got it to work fine, and it writes to the database (yay!).
If POST is required, I will follow up and find out, because I think that I am getting some errors: about Undefined index
 
Thanks
patrad

You could send them a "print_r" page of the POST variables so they could see your variable names as well.  That would help them be able to post data to the form themselves.