FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


help getting form info into mysql db





lastelement0
hey all.
im relatively new when it comes to working with php and mysql. currently i am trying to aid my professor in setting up a questionnaire. i have the form all set up however, i cannot figure out what i need to do to get the info sent somewhere. i was going to do by email to my professor but figured maybe by database would be the best way. if any of you can help me set up mysql to work to pull the information from the form and put it into a working db that can be viewed easily, that would be great.

here is the code for my form:
Code:
<html>
<head>Master's Questionaire</head>
<title>Master's Questionaire</title>
<body>

<form action="sendmail.php" method="post">
Name: <input name="name" type="text" /> <br /> <br />
Email: <input name="email" type="text" /> <br />
<br />

1. What types of courses do you teach? <br />
<input type="radio" value="CS" name="course">Computer Science<br />
<input type="radio" value="IT" name="course">Information Technology<br />
<input type="radio" value="Math" name="course">Mathematics<br />
<input type="radio" value="Others" name="course">Others<br />
<br /><br />

2. What is the highest education degree that you hold? <br />
<input type="radio" value="Master's" name="degree">Master's degree or higher<br />
<input type="radio" value="Bachelor's" name="degree">Bachelor's degree<br />
<input type="radio" value="Others" name="degree">Others<br />
<br /><br />

3. If you have a Master's degree, what area is your Master's degree in? <br />
<input type="radio" value="CSIT" name="master">Computer Science or Information Technology<br />
<input type="radio" value="Math" name="master">Mathematics <br />
<input type="radio" value="Education" name="master">Education <br />
<input type="radio" value="Others" name="master">Others <br />
<br /><br />

4. If you don't have a Master's degree, would you like to pursue one? <br />
<input type="radio" value="Yes" name="pursue">Yes<br />
<input type="radio" value="Maybe" name="pursue">Maybe<br />
<input type="radio" value="No" name="pursue">No<br />
<br /><br />

5. If you were to pursue a Master's degree, what area would that be in? <br />
<input type="radio" value="CSIT" name="area">Computer Science or Information Technology<br />
<input type="radio" value="Math" name="area">Mathematics <br />
<input type="radio" value="Education" name="area">Education <br />
<input type="radio" value="Others" name="area">Others <br />
<br /><br />

6. If Western New England College establishes a Master's program in Computing, would you consider enrolling in that program? <br />
<input type="radio" value="Yes" name="wnec">Yes<br />
<input type="radio" value="Maybe" name="wnec">Maybe<br />
<input type="radio" value="No" name="wnec">No<br />
<br /><br />

7. What will be your criteria to pursue a Master's degree in Computing(check all that apply)? <br />
<input type="checkbox" value="Length" name="criteria[]">Length of time to graduate<br />
<input type="checkbox" value="Time" name="criteria[]">Time in which classes are offered<br />
<input type="checkbox" value="Cost" name="criteria[]">Cost<br />
<input type="checkbox" value="Once" name="criteria[]">Once a week courses<br />
<input type="checkbox" value="Twice" name="criteria[]">Twice a week courses<br />
<input type="checkbox" value="Other" name="criteria[]">Other Criteria<br />
<br /><br />

7a. If you chose "Other Criteria" in the previous question, describe the other criteria. <br />
<textarea name="detail" rows="5" cols="50"></textarea><br />
<br /><br />

8. If cost was one of your criteria, which one of the following per course cost will influence your decision in pursuing a Master's program in Computing? <br />
<input type="radio" value="1500" name="cost">$1500 or above<br />
<input type="radio" value="1250" name="cost">$1250-$1500<br />
<input type="radio" value="1000" name="cost">$1000-$1250<br />
<input type="radio" value="750" name="cost">$750-$1000<br />
<br /><br />

8a. What is the influence percentage of your choice from the previous question? <br />
<input type="text" name="influence" />
<br /><br />

9. Assuming that your criteria were met and a program was available today, when would you start the program? <br />
<input type="radio" value="Now" name="time">Immediately<br />
<input type="radio" value="Months" name="time">In 6 Months<br />
<input type="radio" value="Year" name="time">Within a year<br />
<input type="radio" value="Years" name="time">In a couple of years<br />
<br /><br />

<input type="submit" value="Submit"/>
</form>

</body>
</html>



thanks
catscratches
W3Schools has a very good tutorial on PHP and how to use MySQL in PHP. Check it out at: http://www.w3schools.com/php/default.asp
lastelement0
ahhh thanks for the link. that ended up doing the trick. the only thing i couldnt find help with there was how to have an array displayed.

at first i was going to try and have all the selections be shown in one field. however, ive decided in order to best sort the data i'd have each checkbox be its own field. any help on how to achieve this would be great

here's the chunk of code that i;m referring to
Code:
7. What will be your criteria to pursue a Master's degree in Computing(check all that apply)? <br />
<input type="checkbox" value="Length" name="criteria[]">Length of time to graduate<br />
<input type="checkbox" value="Time" name="criteria[]">Time in which classes are offered<br />
<input type="checkbox" value="Cost" name="criteria[]">Cost<br />
<input type="checkbox" value="Once" name="criteria[]">Once a week courses<br />
<input type="checkbox" value="Twice" name="criteria[]">Twice a week courses<br />
<input type="checkbox" value="Other" name="criteria[]">Other Criteria<br />
<br /><br />
mathiaus
Code:
$critera_num = count($_POST['criteria']);

// Provide a list of POSSIBLE results
$criteria_list = array('Length', 'Time', 'Cost', 'Once', 'Twice', 'Other');

// Loop through them all
foreach($criteria_list as $key => $value) {
   // Default as 0
   $criteria[$value] = 0;
   
   $i = 0;
   // Loop through post array
   while($i < $critera_num) {
      // If we find it in the array
      if($_POST['criteria'][$i] == $value) {
         // change to set it as 1
         $criteria[$value] = 1;
      }
      
      $i++;
   }
}

// Your old INSERT query
$query = "INSERT INTO `tablename` ('blah', 'blah', 'length', 'time', 'cost', 'once', 'twice', 'other', 'blah') VALUES ('$blah1', '$blah2', '".$criteria['Length']."', '".$criteria['Time']."', '".$criteria['Cost']."', '".$criteria['Once']."', '".$criteria['Twice']."', '".$criteria['Other']."', '$blah3')";
Related topics
Build an online dictionary by PHP/MySQL
A PHP problem !
MySQL DB Backup script - minor problem
How do I make a MySQL dB ?
[RESOLVED] How do I make a MySQL dB ?
Separating contents of MySQL row and put them in variables?
Lineage II (C4 chronicle)
Need Help integrating php variable into mySQL SELECT query
form mail problems (quality help=frih$)
Help importing CSV file into MySQL database
Developing a Login Script for Website
cannot add data to mysql from PHP form
Mysql DB
a mysql db service
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.