| | |
How do I pass values with a link into mySQL database using PHP?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 3
Reputation:
Solved Threads: 0
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...
When I test the survey, the values for center and custID are not sent. Please help!
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...
PHP Syntax (Toggle Plain Text)
$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!
Last edited by mmitchell73; Apr 14th, 2009 at 12:18 pm.
•
•
Join Date: Aug 2007
Posts: 189
Reputation:
Solved Threads: 14
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.
Also, try to remove the single quotes on the SQL query. Use it on the array index.
php Syntax (Toggle Plain Text)
$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']), ... );
Last edited by martin5211; Apr 14th, 2009 at 1:18 pm.
•
•
Join Date: Apr 2009
Posts: 3
Reputation:
Solved Threads: 0
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....
And here's the code that sends it into my database and displays a thank you message...
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
http://www.melissajeandesign.com/pre_venture.php
Here is the code for the actual survey....
PHP Syntax (Toggle Plain Text)
<!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...
PHP Syntax (Toggle Plain Text)
<!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
Last edited by mmitchell73; Apr 14th, 2009 at 1:37 pm.
•
•
Join Date: Aug 2007
Posts: 189
Reputation:
Solved Threads: 14
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
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:
On the PHP submission code, you use only $_POST instead of
Add
value="<?php echo $_GET['center']?>" into the input tags, should be something like: php Syntax (Toggle Plain Text)
<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:
php Syntax (Toggle Plain Text)
<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? Last edited by martin5211; Apr 14th, 2009 at 2:09 pm.
![]() |
Similar Threads
- Data not going into my database??! plz help (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in (PHP)
- pass php variables to mysql database (MySQL)
- PLS I NEED YOUR HELP! Help on Reading and Editing of already Written CODE on php! (PHP)
- Submit Form To MySQL Table (PHP)
- $_GET['id'] is not working????? (PHP)
- Unknown error and ')' Problem (PHP)
- mysql errors, from submit.php and index.php (PHP)
Other Threads in the PHP Forum
- Previous Thread: how to select record from unserialized Records
- Next Thread: Trying to open URL's from MySQL database
| Thread Tools | Search this Thread |
ajax apache api array back basic beginner binary broken cakephp checkbox class cms code computing cron curl database date delete display dynamic echo email error external file files filter folder form forms function functions gc_maxlifetime google host href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php problem query question radio random recursion regex remote script search server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validation validator variable video web xml youtube





