943,844 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1252
  • PHP RSS
Apr 14th, 2009
0

How do I pass values with a link into mySQL database using PHP?

Expand Post »
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...

PHP Syntax (Toggle Plain Text)
  1. $sql="INSERT INTO pre_vent (center, custID, yStart, yAcquired, yOther, comments)
  2. VALUES
  3. ('$_POST','$_POST[custID]','$_...
  4.  

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mmitchell73 is offline Offline
3 posts
since Apr 2009
Apr 14th, 2009
0

Re: How do I pass values with a link into mySQL database using PHP?

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.

php Syntax (Toggle Plain Text)
  1. $sql= sprintf("INSERT INTO pre_vent (center, custID, yStart, yAcquired, yOther, comments)
  2. VALUES
  3. ('%s','%s', ... )",
  4. mysql_real_escape_string($_GET['center']),
  5. mysql_real_escape_string($_GET['custID']),
  6. ... );
Last edited by martin5211; Apr 14th, 2009 at 1:18 pm.
Reputation Points: 52
Solved Threads: 23
Posting Whiz in Training
martin5211 is offline Offline
271 posts
since Aug 2007
Apr 14th, 2009
0

Re: How do I pass values with a link into mySQL database using PHP?

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....
PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Oklahoma SBDC Pre-Venture Survey</title>
  6. <link href="survey_styles.css" rel="stylesheet" type="text/css"/>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <img src="images/OSBDC_logo2sm.jpg" alt="Oklahoma SBDC" style="width: 300px; height: 116px" />
  12. <h2 style="font-family: arial, veranda, tahoma; font-size: 14pt;">Pre-Venture Survey</h2>
  13.  
  14.  
  15. <form method="post" action="presurvey.php">
  16.  
  17. <!--<p>
  18. Please enter your Survey Code: <input type="text" maxlength="2" size="3" name="center" />-<input type="text" name="custID" maxlength="5" size="10" />
  19. </p>-->
  20. <ol>
  21. <li>
  22. <p>Please indicate the year your business was either started or acquired (if never, please indicate by selecting "Not Applicable").<br /><br />
  23. Year Started: <select name="yStart">
  24. <option value="default"> </option>
  25. <option value="2009">2009</option>
  26. <option value="2008">2008</option>
  27. <option value="2007">2007</option>
  28. <option value="2006">2006</option>
  29. <option value="2005">2005</option>
  30. <option value="2004">2004</option>
  31. <option value="2003">2003</option>
  32. <option value="2002">2002</option>
  33. <option value="2001">2001</option>
  34. <option value="2000">2000</option>
  35. <option value="1999">1999</option>
  36. <option value="1998">1998</option>
  37. <option value="1997">1997</option>
  38. <option value="1996">1996</option>
  39. <option value="1995">1995</option>
  40. <option value="1994">1994</option>
  41. <option value="1993">1993</option>
  42. <option value="1992">1992</option>
  43. <option value="1991">1991</option>
  44. <option value="1990">1990</option>
  45. <option value="1989">1989</option>
  46. <option value="1988">1988</option>
  47. <option value="1987">1987</option>
  48. <option value="1986">1986</option>
  49. <option value="1985">1985</option>
  50. <option value="1984">1984</option>
  51. <option value="1983">1983</option>
  52. <option value="1982">1982</option>
  53. <option value="1981">1981</option>
  54. <option value="1980">1980</option>
  55. <option value="Other">Other</option>
  56. <option value="N/A">Not Applicable</option>
  57. </select>
  58. or Year Acquired: <select name="yAcquired">
  59. <option value="default"> </option>
  60. <option value="2009">2009</option>
  61. <option value="2008">2008</option>
  62. <option value="2007">2007</option>
  63. <option value="2006">2006</option>
  64. <option value="2005">2005</option>
  65. <option value="2004">2004</option>
  66. <option value="2003">2003</option>
  67. <option value="2002">2002</option>
  68. <option value="2001">2001</option>
  69. <option value="2000">2000</option>
  70. <option value="1999">1999</option>
  71. <option value="1998">1998</option>
  72. <option value="1997">1997</option>
  73. <option value="1996">1996</option>
  74. <option value="1995">1995</option>
  75. <option value="1994">1994</option>
  76. <option value="1993">1993</option>
  77. <option value="1992">1992</option>
  78. <option value="1991">1991</option>
  79. <option value="1990">1990</option>
  80. <option value="1989">1989</option>
  81. <option value="1988">1988</option>
  82. <option value="1987">1987</option>
  83. <option value="1986">1986</option>
  84. <option value="1985">1985</option>
  85. <option value="1984">1984</option>
  86. <option value="1983">1983</option>
  87. <option value="1982">1982</option>
  88. <option value="1981">1981</option>
  89. <option value="1980">1980</option>
  90. <option value="Other">Other</option>
  91. <option value="N/A">Not Applicable</option>
  92. </select><br />
  93. If other, please specify:
  94. <input type="text" name="yOther" size="8" maxlength="4" />
  95. </p></li>
  96.  
  97. <li><p>What was the major activity of your business or proposed business in 2007?<br />
  98. <table><tr><td><select name="majAct">
  99. <option value="default"> </option>
  100. <option value="Retail">Retailing</option>
  101. <option value="Services">Services (personal OR professional)</option>
  102. <option value="Wholesale">Wholesale (distribution, etc.)</option>
  103. <option value="Manufacturing">Manufacturing</option>
  104. <option value="Construction">Construction (all general, and other contractors)</option>
  105. <option value="Other">Other</option>
  106. </select></td></tr>
  107. <tr><td>If other, please specify:
  108. <input type="text" name="majActOther" /></td></tr></table>
  109. </p></li>
  110.  
  111. <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 />
  112. <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>
  113. <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>
  114.  
  115. <li><p>Please estimate the number of jobs saved as a result of the assistance received from the SBDC.<br />
  116. <table><tr><td>Existing full-time jobs saved:</td><td><input type="text" name="ftSaved" size="10" /></td></tr>
  117. <tr><td>Existing part-time jobs saved:</td><td><input type="text" name="ptSaved" size="10" /></td></tr></table></p></li>
  118.  
  119. <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 />
  120. <table><tr><td>2007 $<input type="text" name="gross2007" size="10" /></td></tr>
  121. <tr><td>2008 $<input type="text" name="gross2008" size="10" /></td></tr></table></p></li>
  122.  
  123. <li><p>Please estimate the amount of gross sales revenues maintained as a result of the SBDC's assistance.<br /><br />
  124. Existing revenues maintained $<input type="text" name="grossMain" size="10" /></p></li>
  125.  
  126. <li><p>Did the SBDC assist you in obtaining financing?
  127. <select name="assistFin">
  128. <option value="default"> </option>
  129. <option value="Yes">Yes</option>
  130. <option value="No">No</option>
  131. </select></p></li>
  132.  
  133. <li><p>Please estimate the total amount of debt and equity financing your business raised in 2007 and 2008. <br />
  134. <table>
  135. <tr><td>SBA Loans </td><td>$<input type="text" name="sbaLoans" /></td></tr>
  136. <tr><td>Other Loans/Debt Financing </td><td>$<input type="text" name="otherLoans" /></td></tr>
  137. <tr><td>Equity Raised from Investors </td><td>$<input type="text" name="equityRaised" /></td></tr>
  138. </table></p></li>
  139. </ol>
  140. <h2>How Are We Doing?</h2>
  141. <ol start="9">
  142. <li><p>Was the overall service you received from the Small Business Development Center beneficial?
  143. <select name="servBene">
  144. <option value="default"> </option>
  145. <option value="Yes">Yes</option>
  146. <option value="No">No</option>
  147. </select></p></li></ol>
  148.  
  149. <table cellpadding="10" border="0" cellspacing="0" style="text-align: center; vertical-align: middle; margin-left: -10px">
  150. <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>
  151. <td style="background-color: #BBF4DC">Average</td><td style="background-color: #BBF4DC">Below Average</td><td style="background-color: #BBF4DC">Poor</td></tr>
  152. <tr><td style="text-align: left"><ol start="10"><li>Knowledge and Expertise of Counselor:</li></ol></td>
  153. <td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Excellent" /></td>
  154. <td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Above Average" /></td>
  155. <td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Average" /></td>
  156. <td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Below Average" /></td>
  157. <td style="background-color: #E8FDF0"><input type="radio" name="counRating" value="Poor" /></td></tr>
  158. <tr><td style="text-align: left"><ol start="11"><li>Overall Working Relationship with the SBDC counselor:</li></ol></td>
  159. <td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Excellent" /></td>
  160. <td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Above Average" /></td>
  161. <td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Average" /></td>
  162. <td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Below Average" /></td>
  163. <td style="background-color: #E8FDF0"><input type="radio" name="counRating2" value="Poor" /></td>
  164. </tr>
  165. </table>
  166.  
  167. <ol start="12">
  168. <li><p>Woud you recommend that other business persons contact the Small Business Development Center?
  169. <select name="recommend">
  170. <option value="default"> </option>
  171. <option value="Yes">Yes</option>
  172. <option value="No">No</option>
  173. </select></p></li>
  174.  
  175. <li><p>Was comparable assistance available from a private consultant at a price you could afford?
  176. <select name="compServ">
  177. <option value="default"> </option>
  178. <option value="Yes">Yes</option>
  179. <option value="No">No</option>
  180. <option value="DontKnow">Don't Know</option>
  181. </select></p></li>
  182.  
  183. <p>Additional Comments or Suggestions:<br />
  184. <textarea name="comments" rows="5" cols="65"></textarea></p>
  185.  
  186. <p style="text-align: center">
  187. Thank you for taking our survey!<br />
  188. <input type="submit" value="Submit" /> <input type="reset" value="Reset" />
  189. </form>
  190. </body>
  191. </html>

And here's the code that sends it into my database and displays a thank you message...
PHP Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Oklahoma SBDC - Survey Submitted</title>
  6. <link href="survey_styles.css" rel="stylesheet" type="text/css"/>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <?php
  12.  
  13. $dbhost = 'localhost';
  14. $dbuser = 'melissa1_osbdc';
  15. $dbpass = 'prevent';
  16.  
  17. $con = mysql_connect($dbhost, $dbuser, $dbpass);
  18.  
  19. if (!$con)
  20. {
  21. die(mysql_error());
  22. }
  23.  
  24. mysql_select_db("melissa1_osbdcPre", $con);
  25.  
  26. $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)
  27. VALUES
  28. ('$_POST','$_POST[custID]','$_POST[yStart]','$_POST[yAcquired]',
  29. '$_POST[yOther]','$_POST[majAct]','$_POST[majActOther]',
  30. '$_POST[ft2007]','$_POST[pt2007]','$_POST[ft2008]',
  31. '$_POST[pt2008]','$_POST[ftSaved]','$_POST[ptSaved]',
  32. '$_POST[gross2007]','$_POST[gross2008]','$_POST[grossMain]',
  33. '$_POST[assistFin]','$_POST[sbaLoans]','$_POST[otherLoans]',
  34. '$_POST[equityRaised]','$_POST[servBene]','$_POST[counRating]',
  35. '$_POST[counRating2]','$_POST[recommend]','$_POST[compServ]',
  36. '$_POST[comments]')";
  37.  
  38. if (!mysql_query($sql,$con))
  39. {
  40. die('Error: ' . mysql_error());
  41. }
  42.  
  43. print("<h2>Thank you, your information has been submitted.</h2>");
  44.  
  45. mysql_close($con);
  46. ?>
  47.  
  48. </body>
  49. </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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mmitchell73 is offline Offline
3 posts
since Apr 2009
Apr 14th, 2009
1

Re: How do I pass values with a link into mySQL database using PHP?

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:

php Syntax (Toggle Plain Text)
  1. <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)
  1. <input type="hidden" name="center" value="<?php echo $_GET['center']?>" />
  2. <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.
Reputation Points: 52
Solved Threads: 23
Posting Whiz in Training
martin5211 is offline Offline
271 posts
since Aug 2007
Apr 14th, 2009
0

Re: How do I pass values with a link into mySQL database using PHP?

Thank you!! It works perfectly! You are awesome!
Last edited by mmitchell73; Apr 14th, 2009 at 2:40 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mmitchell73 is offline Offline
3 posts
since Apr 2009
Aug 26th, 2010
0

PHP!!!!!!!!

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........
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ram007 is offline Offline
1 posts
since Aug 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Random Images from mysql
Next Thread in PHP Forum Timeline: whats wrong with this?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC