I have designed a survey with PHP that submits the responses into a MySQL database. The people that will be taking the survey are existing clients which have user IDs and information stored in a database that I do not have direct access to.

What I would like to do is send each client an email with a link that sends their id number with their survey responses.

I have two variables that I need to pass with the link: center and custID - I was planning on doing it like so...
.../pre_venture.php?center=10&custID=1...

When they click the link, I need the values passed with the survey responses. I have two files pre_venture.php and presurvey.php... pre_venture is the actual survey and presurvey is what sends the information into the database.

In the presurvey.php file, I use post to send the information to the database like so...

$sql="INSERT INTO pre_vent (center, custID, yStart, yAcquired, yOther, comments)
VALUES
('$_POST','$_POST[custID]','$_...

When I test the survey, the values for center and custID are not sent. Please help!

Recommended Answers

All 5 Replies

Try $_GET instead of $_POST to get parameters every time you use URL method.

Also, try to remove the single quotes on the SQL query. Use it on the array index.

$sql= sprintf("INSERT INTO pre_vent (center, custID, yStart, yAcquired, yOther, comments)
VALUES
('%s','%s', ... )", 
   mysql_real_escape_string($_GET['center']),
   mysql_real_escape_string($_GET['custID']),
... );

Thanks but I still am not having any luck... here's the code in its entirety for both files... also here's a link to the survey page...
http://www.melissajeandesign.com/pre_venture.php

Here is the code for the actual survey....

<!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>Oklahoma SBDC Pre-Venture Survey</title>
<link href="survey_styles.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<img src="images/OSBDC_logo2sm.jpg" alt="Oklahoma SBDC" style="width: 300px; height: 116px" />
<h2 style="font-family: arial, veranda, tahoma; font-size: 14pt;">Pre-Venture Survey</h2>


<form method="post" action="presurvey.php">

<!--<p>
Please enter your Survey Code: <input type="text" maxlength="2" size="3" name="center" />-<input type="text" name="custID" maxlength="5" size="10" />
</p>-->
<ol>
<li>
<p>Please indicate the year your business was either started or acquired (if never, please indicate by selecting "Not Applicable").<br /><br />
Year Started: <select name="yStart">
<option value="default"> </option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="Other">Other</option>
<option value="N/A">Not Applicable</option>
</select>
or Year Acquired: <select name="yAcquired">
<option value="default"> </option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="Other">Other</option>
<option value="N/A">Not Applicable</option>
</select><br />
If other, please specify:
<input type="text" name="yOther" size="8" maxlength="4" />
</p></li>

<li><p>What was the major activity of your business or proposed business in 2007?<br />
<table><tr><td><select name="majAct">
<option value="default"> </option>
<option value="Retail">Retailing</option>
<option value="Services">Services (personal OR professional)</option>
<option value="Wholesale">Wholesale (distribution, etc.)</option>
<option value="Manufacturing">Manufacturing</option>
<option value="Construction">Construction (all general, and other contractors)</option>
<option value="Other">Other</option>
</select></td></tr>
<tr><td>If other, please specify: 
<input type="text" name="majActOther" /></td></tr></table>
</p></li>

<li><p>Counting yourself, how many full-time (35 hours or more per week) and part-time (less than 35 hours per week) employees did you have at the end of each of the following years that you were in business.<br /><i>If you were not in business, leave blank or type N/A in the appropriate blank(s).</i><br />
<table><tr><td>2007 <input type="text" name="ft2007" size="10" /> full-time employees, <input type="text" name="pt2007" size="10" /> part-time employees</td></tr>
<tr><td>2008 <input type="text" name="ft2008" size="10" /> full-time employees, <input type="text" name="pt2008" size="10" /> part-time employees</td></tr></table></p></li>

<li><p>Please estimate the number of jobs saved as a result of the assistance received from the SBDC.<br />
<table><tr><td>Existing full-time jobs saved:</td><td><input type="text" name="ftSaved" size="10" /></td></tr>
<tr><td>Existing part-time jobs saved:</td><td><input type="text" name="ptSaved" size="10" /></td></tr></table></p></li>

<li><p>What were your gross sales revenue (before expenses) for the following calendar years?<br /><i>If you were not in business, leave blank or type N/A in the appropriate blank(s).</i><br />
<table><tr><td>2007 $<input type="text" name="gross2007" size="10" /></td></tr>
<tr><td>2008 $<input type="text" name="gross2008" size="10" /></td></tr></table></p></li>

<li><p>Please estimate the amount of gross sales revenues maintained as a result of the SBDC's assistance.<br /><br />
Existing revenues maintained $<input type="text" name="grossMain" size="10" /></p></li>

<li><p>Did the SBDC assist you in obtaining financing? 
<select name="assistFin">
<option value="default"> </option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select></p></li>

<li><p>Please estimate the total amount of debt and equity financing your business raised in 2007 and 2008. <br />
<table>
<tr><td>SBA Loans </td><td>$<input type="text" name="sbaLoans" /></td></tr>
<tr><td>Other Loans/Debt Financing </td><td>$<input type="text" name="otherLoans" /></td></tr>
<tr><td>Equity Raised from Investors </td><td>$<input type="text" name="equityRaised" /></td></tr>
</table></p></li>
</ol>
<h2>How Are We Doing?</h2>
<ol start="9">
<li><p>Was the overall service you received from the Small Business Development Center beneficial?
<select name="servBene">
<option value="default"> </option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select></p></li></ol>

<table cellpadding="10" border="0" cellspacing="0" style="text-align: center; vertical-align: middle; margin-left: -10px">
<tr><td style="text-align: left"><span style=" margin-left: 13px; font-weight: bold">Please rate your experience with the OSBDC.</span></td><td style="background-color: #BBF4DC">Excellent</td><td style="background-color: #BBF4DC">Above Average</td>
<td style="background-color: #BBF4DC">Average</td><td style="background-color: #BBF4DC">Below Average</td><td style="background-color: #BBF4DC">Poor</td></tr>
<tr><td style="text-align: left"><ol start="10"><li>Knowledge and Expertise of Counselor:</li></ol></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Excellent" /></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Above Average" /></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Average" /></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Below Average" /></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Poor" /></td></tr>
<tr><td style="text-align: left"><ol start="11"><li>Overall Working Relationship with the SBDC counselor:</li></ol></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Excellent" /></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Above Average" /></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Average" /></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Below Average" /></td>
<td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Poor" /></td>
</tr>
</table>

<ol start="12">
<li><p>Woud you recommend that other business persons contact the Small Business Development Center? 
<select name="recommend">
<option value="default"> </option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select></p></li>

<li><p>Was comparable assistance available from a private consultant at a price you could afford? 
<select name="compServ">
<option value="default"> </option>
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="DontKnow">Don't Know</option>
</select></p></li>

<p>Additional Comments or Suggestions:<br />
<textarea name="comments" rows="5" cols="65"></textarea></p>

<p style="text-align: center">
Thank you for taking our survey!<br />
<input type="submit" value="Submit" /> <input type="reset" value="Reset" />
</form>
</body>
</html>

And here's the code that sends it into my database and displays a thank you message...

<!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>Oklahoma SBDC - Survey Submitted</title>
<link href="survey_styles.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<?php

$dbhost = 'localhost';
$dbuser = 'melissa1_osbdc';
$dbpass = 'prevent';

$con = mysql_connect($dbhost, $dbuser, $dbpass);

if (!$con)
{
	die(mysql_error());
}

mysql_select_db("melissa1_osbdcPre", $con);

$sql="INSERT INTO pre_vent (center, custID, yStart, yAcquired, yOther, majAct, majActOther, ft2007, pt2007, ft2008, pt2008, ftSaved, ptSaved, gross2007, gross2008, grossMain, assistFin, sbaLoans, otherLoans, equityRaised, servBene, counRating, counRating2, recommend, compServ, comments)
VALUES
('$_POST','$_POST[custID]','$_POST[yStart]','$_POST[yAcquired]',
'$_POST[yOther]','$_POST[majAct]','$_POST[majActOther]',
'$_POST[ft2007]','$_POST[pt2007]','$_POST[ft2008]',
'$_POST[pt2008]','$_POST[ftSaved]','$_POST[ptSaved]',
'$_POST[gross2007]','$_POST[gross2008]','$_POST[grossMain]',
'$_POST[assistFin]','$_POST[sbaLoans]','$_POST[otherLoans]',
'$_POST[equityRaised]','$_POST[servBene]','$_POST[counRating]',
'$_POST[counRating2]','$_POST[recommend]','$_POST[compServ]',
'$_POST[comments]')";

if (!mysql_query($sql,$con))
{
	die('Error: ' . mysql_error());
}

print("<h2>Thank you, your information has been submitted.</h2>");

mysql_close($con);
?>

</body>
</html>

I'm new to PHP and have been trying to learn it from the w3schools website.. obviously I have a lot to learn..

anyway, thank you for your help

I'm looking at your code, the method used in your form and mysql variables is ok, but into the form code, the survey code is commented into <!-- ... --> tags, remove it.

Add value="<?php echo $_GET['center']?>" into the input tags, should be something like:

<input type="text" maxlength="2" size="3" name="center" value="<?php echo $_GET['center']?>" />-<input type="text" name="custID" maxlength="5" size="10" value="<?php echo $_GET['custID']?>" />

Now, you can use /pre_venture.php?center=10&custID=1 in your link

If you want to hide that input elements, use this instead of above code:

<input type="hidden" name="center" value="<?php echo $_GET['center']?>" />
<input type="hidden" name="custID" value="<?php echo $_GET['custID']?>" />

On the PHP submission code, you use only $_POST instead of $_POST['center'] on the first value. Is that ok?

commented: Good post. You could have also mentioned the use of the $_REQUEST since she is mixing both $_POST and $_GET usage in her page. +2

Thank you!! It works perfectly! You are awesome!

hi guys,
i have one question... two php file is there... i get another file using links.. i want that data also in the corresponing fields... wat i want 2 do???? pls reply any of them........

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.