Jump to content

Multiple Pages with the same survey questions


caseyphillips

Recommended Posts

I am trying to create a survey system for a small restaurant chain here in town and I few questions on what the best way to go about doing that is. Here is the way they want it to work.

 

They have a about 5 sites and want to have a survey for each one. Same questions but keeping the results separate in the mySQL database. I have the survey page working I just need recommendation on how to handle the different sites. I know there is some kind of way to have the results write to different tables within the database depending on which restaurant they are taking the survey for. In order to determine this I want to have a form or some kind of entry box where they can put in a code which they receive on their receipt that corresponds to a specific table.

 

So say they enter code 001 then the survey loads up and writes all their answers to the 001 table in the database.

 

I am sure this is rather easy to do I just need someone to suggest the most efficient way and point me in write direction.

 

Thanks for the help! 

Link to comment
Share on other sites

no need for a different table for each restaurant. just use the restaurant id as the identifier for each record in a single table.

 

Do you happen to have any links showing how one would do that?

 

Like right now I just have the code writing to the database fine how would I make it switch to the different id's?

 

 

Link to comment
Share on other sites

<?php
      if (isset($_POST['submitted'])) {

        $name = trim(strip_tags($_POST['name']));

        $address = trim(strip_tags($_POST['address']));

        $postcode = trim(strip_tags($_POST['postcode']));

        $telephone = trim(strip_tags($_POST['telephone']));

        $email = trim(strip_tags($_POST['email']));

	$question1 = ($_POST['question1']);

        $question2 = ($_POST['question2']);


	$dbid = mysql_connect ('localhost', '#####', '#####');

        mysql_select_db("#####",$dbid)

          or die ("Cannot find database");

        $query = "INSERT INTO `book` (`aid`, `name`, `address`, `postcode`, `telephone`, `email`, `question1`, `question2`) VALUES (1, '$name', '$address', '$postcode', $telephone, '$email', '$question1', '$question2')";

        $result = mysql_query($query,$dbid)

          or die("INSERT error:".mysql_error());

        echo 'Row inserted';

        exit;

      }

      ?>

       

      <html>

      <head>

      <title>Restaurant Survey</title>

      </head>

      <body>

      <form enctype="multipart/form-data" method="post" action="">

      Name: <input name="name" /><br />

      Address: <input name="address" /><br />

      Postcode: <input name="postcode" /><br />

      Telno: <input name="telephone" /><br />

      Email: <input name="email" /><br />
  <HR>
  
  How often do you dine with us ? <br />
  <input type="radio" name="question1" value="a1" /> Daily <br>
      <input type="radio" name="question1" value="a2"> Weekly<br>
      <input type="radio" name="question1" value="a3">Monthly<br>
  <input type="radio" name="question1" value="a4">Once Every Three Months<br>
      <input type="radio" name="question1" value="a5">Other<br>
      <HR>
  <i>The Server</i>
  <br>
  Was the server attentive and available when you needed him/her?<br>
  <input type="radio" name="question2" value="a1" checked> Yes <br>
      <input type="radio" name="question2" value="a2"> No<br>
      <input type="radio" name="question2" value="a3">N/A<br>
  
  Was your server knowledgeable and able to answer your questions about the food and beverages?
        Was the server attentive and available when you needed him/her?<br>
  <input type="radio" name="question3" value="Yes" checked> Yes <br>
      <input type="radio" name="question3" value="No"> No<br>
      <input type="radio" name="question3" value="Na">N/A<br>
  <HR>
  <i>The Food </i>
  <br>
  How would you rate the taste of your meal?<br>
  <input type="radio" name="question4" value="Excellent" checked> Excellent	 <br>
      <input type="radio" name="question4" value="Good"> Good<br>
      <input type="radio" name="question4" value="Average"> Average<br>
  <input type="radio" name="question4" value="Baverage"> Below Average<br>
      <input type="radio" name="question4" value="Poor">Poor<br>
  How would you rate the temperature of the food?<br>
  <input type="radio" name="question4" value="Excellent" checked> Excellent	 <br>
      <input type="radio" name="question4" value="Good"> Good<br>
      <input type="radio" name="question4" value="Average"> Average<br>
  <input type="radio" name="question4" value="Baverage"> Below Average<br>
      <input type="radio" name="question4" value="Poor">Poor<br>
  Please rate your visit on value for the money.<br>
  <input type="radio" name="question4" value="Excellent" checked> Excellent	 <br>
      <input type="radio" name="question4" value="Good"> Good<br>
      <input type="radio" name="question4" value="Average"> Average<br>
  <input type="radio" name="question4" value="Baverage"> Below Average<br>
      <input type="radio" name="question4" value="Poor">Poor<br>
      <br><input type="submit" name="submitted" value="Submit" ></form><br>

       
      </form>
      </body>

      </html>

 

This is what I've got so far by the way. Hope I'm doing this correctly heh he

Link to comment
Share on other sites

i would add a new hidden form field for the store id, then add that id to the survey record to identify which store the survey is for.

 

Yeah that actually would be a simple way to handle it. I could add checks for that store id to make sure it was valid correct. I don't want people just filling up the database with fake info.

 

Like have a field for them to put in their store number (001) from the first example and then check that to make sure it was a valid code to a real store.

 

Make sense?

Link to comment
Share on other sites

sure, just check to make sure the store exists before entering data into the database. if you have one table of stores with fields id, store_code and store_name, you could

 

SELECT id FROM stores WHERE store_code = '{$_POST['store_code']}'

 

if no records are returned, show an error, else insert the answers with the store id retrieved from the query above.

Link to comment
Share on other sites

sure, just check to make sure the store exists before entering data into the database. if you have one table of stores with fields id, store_code and store_name, you could

 

SELECT id FROM stores WHERE store_code = '{$_POST['store_code']}'

 

if no records are returned, show an error, else insert the answers with the store id retrieved from the query above.

 

Thanks a lot Blue. That is a very efficient solution to my problem. 

Link to comment
Share on other sites

sure, just check to make sure the store exists before entering data into the database. if you have one table of stores with fields id, store_code and store_name, you could

 

SELECT id FROM stores WHERE store_code = '{$_POST['store_code']}'

 

if no records are returned, show an error, else insert the answers with the store id retrieved from the query above.

 

Just a quick follow up do you mean a table apart from my survey data table? One that i just use to list the stores and their codes?

Link to comment
Share on other sites

sure, just check to make sure the store exists before entering data into the database. if you have one table of stores with fields id, store_code and store_name, you could

 

SELECT id FROM stores WHERE store_code = '{$_POST['store_code']}'

 

if no records are returned, show an error, else insert the answers with the store id retrieved from the query above.

 

Just a quick follow up do you mean a table apart from my survey data table? One that i just use to list the stores and their codes?

 

Nevermind I figured that part out... just having a hard time getting the right syntax for the error to interrupt the process.

 

SELECT id FROM stores WHERE store_code = '{$_POST['store_code']}'

 

is that supposed to be like this mysql_query(SELECT id FROM stores WHERE store_code = '{$_POST['store_code']}');  ??

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.