filling in multiple forms

  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

hello all, I'm very very new to programming in PHP and I again need a little bit of help. I have a sort of working system but need to take it to that next step. This may look like I'm asking you to do it for me but trust me I am honestly pretty stuck and have hit a brick wall.

Let me start of by saying I know this is probably a huge ask, and I'd be very appreciative of anyone who can help me out. I don't know if this is even possible, I've been wracking my brains and I've read a few textbooks and I can't seem to work out how the hell to do this and I really need to get it done as soon as.

If it is not possible then can someone guide me as to how to work it out. Possibly chat about it on msn? I'm very keen to learn about it. I'd even offer some paypal appreciation. :)

ok, here we go...

I have a database set up with 3 tables. First one is a student table containing, username and password. I then have a table called moduleData which contains ModuleCode and lecturer. I then have a third table called Module which links them both with the fields username and moduleCode both as key fields. which holds records like "username, moduleCode" e.g. "368333, CS100" and "433444, CS200" etc..

I have a main menu which looks like this: http://img261.imageshack.us/img261/8826/picture5cc5.png

code:

Code: [ Select ]
<?php
session_start();
//session_register("moduleName");
?>

<html>

    <head>
        <title>Main Menu</title>
    </head>
    <body>
<?php

$host="localhost:8889"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="MyDB"; // Database name
$tbl_name="Module"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername=$_SESSION['myusername'];

//$sql = "SELECT `Module1` FROM `members`";
$sql = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
//$sql="SELECT * FROM $tbl_name WHERE Module1='$myModuleOne'";
$result=mysql_query($sql);

echo "Hello ";
echo $myusername;
echo ", and welcome to the main menu page!";
?>
<br><br><br>
<?php
echo "List of modules you are enrolled on: ";
?>
<br><br>
<?php
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    //echo "Module: {$row['ModuleCode']} <br>";
}
?>
<br><br><br>
<?php
$attquery = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
$attresult=mysql_query($attquery) or die ("could not connect");
$attnum=mysql_num_rows($attresult);
echo "You are currently enrolled on a total of ";
echo $attnum;
echo " modules.";
if ($attnum > 0)
{
echo "<center><table border=1>\n";
echo "<tr align=left valign=top>\n
        <td><h3>ModuleCode</h3></td>\n
        <td><h3>Go to form</h3></td>\n
    </tr>\n";
while ($attrow=mysql_fetch_array($attresult))
{
extract($attrow);
echo "<tr>\n
<td align=center>$ModuleCode</td>\n";
echo "<td align=center><form name=\"continue\" method=\"post\" action=\"pageForm.php\">
<input type=\"submit\" name=\"submit\" value=\"Fill in form\">
</form></td></tr>\n";
}
echo "</table></center>";
}
else
{
echo "<div align=center>Sorry No Module Code Avaliable!</div>";
}
?>
<br><br><br><br>
<form name="continue" method="post" action="pageForm.php">
<input type="submit" name="submit" value="Continue...">

</form>
    </body>
</html>
  1. <?php
  2. session_start();
  3. //session_register("moduleName");
  4. ?>
  5. <html>
  6.     <head>
  7.         <title>Main Menu</title>
  8.     </head>
  9.     <body>
  10. <?php
  11. $host="localhost:8889"; // Host name
  12. $username="root"; // Mysql username
  13. $password="root"; // Mysql password
  14. $db_name="MyDB"; // Database name
  15. $tbl_name="Module"; // Table name
  16. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  17. mysql_select_db("$db_name")or die("cannot select DB");
  18. $myusername=$_SESSION['myusername'];
  19. //$sql = "SELECT `Module1` FROM `members`";
  20. $sql = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
  21. //$sql="SELECT * FROM $tbl_name WHERE Module1='$myModuleOne'";
  22. $result=mysql_query($sql);
  23. echo "Hello ";
  24. echo $myusername;
  25. echo ", and welcome to the main menu page!";
  26. ?>
  27. <br><br><br>
  28. <?php
  29. echo "List of modules you are enrolled on: ";
  30. ?>
  31. <br><br>
  32. <?php
  33. while($row = mysql_fetch_array($result, MYSQL_ASSOC))
  34. {
  35.     //echo "Module: {$row['ModuleCode']} <br>";
  36. }
  37. ?>
  38. <br><br><br>
  39. <?php
  40. $attquery = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
  41. $attresult=mysql_query($attquery) or die ("could not connect");
  42. $attnum=mysql_num_rows($attresult);
  43. echo "You are currently enrolled on a total of ";
  44. echo $attnum;
  45. echo " modules.";
  46. if ($attnum > 0)
  47. {
  48. echo "<center><table border=1>\n";
  49. echo "<tr align=left valign=top>\n
  50.         <td><h3>ModuleCode</h3></td>\n
  51.         <td><h3>Go to form</h3></td>\n
  52.     </tr>\n";
  53. while ($attrow=mysql_fetch_array($attresult))
  54. {
  55. extract($attrow);
  56. echo "<tr>\n
  57. <td align=center>$ModuleCode</td>\n";
  58. echo "<td align=center><form name=\"continue\" method=\"post\" action=\"pageForm.php\">
  59. <input type=\"submit\" name=\"submit\" value=\"Fill in form\">
  60. </form></td></tr>\n";
  61. }
  62. echo "</table></center>";
  63. }
  64. else
  65. {
  66. echo "<div align=center>Sorry No Module Code Avaliable!</div>";
  67. }
  68. ?>
  69. <br><br><br><br>
  70. <form name="continue" method="post" action="pageForm.php">
  71. <input type="submit" name="submit" value="Continue...">
  72. </form>
  73.     </body>
  74. </html>



Each button links to the following form: http://img134.imageshack.us/img134/9237/picture6ig2.png

code:

Code: [ Select ]
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<?php
echo "Welcome ";
echo $_SESSION['myusername'];
echo " to the student evaluation form";
?>
<br><br>
<?php
echo "This is the evaluation page for module: ";
echo $_SESSION['ModuleCode'];
?>

<html>
<head>
<title>Student Form Entry Page</title>
</head>
<body>

<br>
<br>
<br>
<form name="form2" method="post" action="processStudentForm.php">
How clear do you understand the aims of the module?
<select name="question0">
<option value="0" selected >0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<br><br>

How well does the module achieve these aims?
<select name="question1">
<option value="0" selected >0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<br><br>

How readable were the notes?
<select name="question2">
<option value="0" selected >0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<br><br>

How useful were the notes in understanding the material covered?
<select name="question3">
<option value="0" selected >0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<br><br>

How interestig were the lectures?
<select name="question4">
<option value="0" selected >0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<br><br>

How useful were the lectures in understanding the material covered?
<select name="question5">
<option value="0" selected >0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

<br><br>

What do you consider to be the most positive aspects of the module?<br><br>
<textarea name="question6" cols="40" rows="5">
Enter your comments here...
</textarea><br>

<br><br>

Are there any ways in which you think the module could be improved?
<br><br>
<textarea name="question7" cols="40" rows="5">
Enter your comments here...
</textarea><br>

<input type="submit" name="submit" value="Submit!">

</form>


</body>
</html>
  1. <?
  2. session_start();
  3. if(!session_is_registered(myusername)){
  4. header("location:main_login.php");
  5. }
  6. ?>
  7. <?php
  8. echo "Welcome ";
  9. echo $_SESSION['myusername'];
  10. echo " to the student evaluation form";
  11. ?>
  12. <br><br>
  13. <?php
  14. echo "This is the evaluation page for module: ";
  15. echo $_SESSION['ModuleCode'];
  16. ?>
  17. <html>
  18. <head>
  19. <title>Student Form Entry Page</title>
  20. </head>
  21. <body>
  22. <br>
  23. <br>
  24. <br>
  25. <form name="form2" method="post" action="processStudentForm.php">
  26. How clear do you understand the aims of the module?
  27. <select name="question0">
  28. <option value="0" selected >0</option>
  29. <option value="1">1</option>
  30. <option value="2">2</option>
  31. <option value="3">3</option>
  32. <option value="4">4</option>
  33. <option value="5">5</option>
  34. </select>
  35. <br><br>
  36. How well does the module achieve these aims?
  37. <select name="question1">
  38. <option value="0" selected >0</option>
  39. <option value="1">1</option>
  40. <option value="2">2</option>
  41. <option value="3">3</option>
  42. <option value="4">4</option>
  43. <option value="5">5</option>
  44. </select>
  45. <br><br>
  46. How readable were the notes?
  47. <select name="question2">
  48. <option value="0" selected >0</option>
  49. <option value="1">1</option>
  50. <option value="2">2</option>
  51. <option value="3">3</option>
  52. <option value="4">4</option>
  53. <option value="5">5</option>
  54. </select>
  55. <br><br>
  56. How useful were the notes in understanding the material covered?
  57. <select name="question3">
  58. <option value="0" selected >0</option>
  59. <option value="1">1</option>
  60. <option value="2">2</option>
  61. <option value="3">3</option>
  62. <option value="4">4</option>
  63. <option value="5">5</option>
  64. </select>
  65. <br><br>
  66. How interestig were the lectures?
  67. <select name="question4">
  68. <option value="0" selected >0</option>
  69. <option value="1">1</option>
  70. <option value="2">2</option>
  71. <option value="3">3</option>
  72. <option value="4">4</option>
  73. <option value="5">5</option>
  74. </select>
  75. <br><br>
  76. How useful were the lectures in understanding the material covered?
  77. <select name="question5">
  78. <option value="0" selected >0</option>
  79. <option value="1">1</option>
  80. <option value="2">2</option>
  81. <option value="3">3</option>
  82. <option value="4">4</option>
  83. <option value="5">5</option>
  84. </select>
  85. <br><br>
  86. What do you consider to be the most positive aspects of the module?<br><br>
  87. <textarea name="question6" cols="40" rows="5">
  88. Enter your comments here...
  89. </textarea><br>
  90. <br><br>
  91. Are there any ways in which you think the module could be improved?
  92. <br><br>
  93. <textarea name="question7" cols="40" rows="5">
  94. Enter your comments here...
  95. </textarea><br>
  96. <input type="submit" name="submit" value="Submit!">
  97. </form>
  98. </body>
  99. </html>


I then have this script that adds the data from the form into a new table called StudentInputForm:

The database for this looks like this: http://img181.imageshack.us/img181/5719/picture7ts7.png

Code: [ Select ]
<?php
session_start();
ob_start();
$db_host = "localhost:8889"; // Host name
$db_user = "root"; // Mysql username
$db_pwd = "root"; // Mysql password
$db_name = "MyDB"; // Database name

// Connect to server and select database.
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name) or die ("Couldn't select database.");

// Define variables

$question0=$_POST['question0'];
$question1=$_POST['question1'];
$question2=$_POST['question2'];
$question3=$_POST['question3'];
$question4=$_POST['question4'];
$question5=$_POST['question5'];
$question6=$_POST['question6'];
$question7=$_POST['question7'];

// Insert value from each question into database
mysql_query("INSERT INTO `StudentInputForm` (question0, question1, question2, question3, question4, question5, question6, question7) VALUES ('$question0', '$question1', '$question2', '$question3', '$question4', '$question5', '$question6', '$question7')");


// Redirect to doesshow.php
header("location:doesshow.php");
ob_end_flush();
?>
  1. <?php
  2. session_start();
  3. ob_start();
  4. $db_host = "localhost:8889"; // Host name
  5. $db_user = "root"; // Mysql username
  6. $db_pwd = "root"; // Mysql password
  7. $db_name = "MyDB"; // Database name
  8. // Connect to server and select database.
  9. mysql_connect($db_host, $db_user, $db_pwd);
  10. mysql_select_db($db_name) or die ("Couldn't select database.");
  11. // Define variables
  12. $question0=$_POST['question0'];
  13. $question1=$_POST['question1'];
  14. $question2=$_POST['question2'];
  15. $question3=$_POST['question3'];
  16. $question4=$_POST['question4'];
  17. $question5=$_POST['question5'];
  18. $question6=$_POST['question6'];
  19. $question7=$_POST['question7'];
  20. // Insert value from each question into database
  21. mysql_query("INSERT INTO `StudentInputForm` (question0, question1, question2, question3, question4, question5, question6, question7) VALUES ('$question0', '$question1', '$question2', '$question3', '$question4', '$question5', '$question6', '$question7')");
  22. // Redirect to doesshow.php
  23. header("location:doesshow.php");
  24. ob_end_flush();
  25. ?>


What I'm trying to achieve is a database table with all the data in it from all the forms from multiple users, if that makes sense.

What I want is when you log in and you go to the mainMenu screen with the list of modules and a button for each, I would like the user to click the button next to the corresponding form and be taken to a form which says: Hello "<username>" welcome to the form for module number "CS100".

When they then click submit on that form all the info is added to the database StudentInputForm and the student is then taken back to the mainMenu which allows him/her to select the next module to fill in etc.. etc..and I would also like it to indicate that that form for that module has been filled in.

thank you for any advice, as I said, get in touch with me if this is a big task!

cheers.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

I guess I'm having issues with appending the moduleCode's values to a php array and then append that to php variables from a database call which returns a row, like this? I'm unsure.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

So, you want to make that module invalid to fill in for a user as soon as the user clicks submit and goes to the main menu page correct?

You will need to create a check if the field for that username in StudentInputForm exists, if it doesn't than show the button, but if it does, than don't show the button... something like the following... (as an example, may require a bit of changing on the SQL part...
PHP Code: [ Select ]
<?php
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "SELECT ModuleCode FROM StudentInputForm WHERE StudentNumber='$studentnumber'";
$result = "mysql_query($sql) or die(mysql_error())";
$num = mysql_num_rows(result);
if($num < '0')
{
 echo 'The user has not filled in the form... show the button';
} else {
 echo 'The user has filled in the form... don\'t show the button':
}
mysql_close();
?>
  1. <?php
  2. mysql_connect("$host", "$username", "$password") or die("cannot connect");
  3. mysql_select_db("$db_name")or die("cannot select DB");
  4. $sql = "SELECT ModuleCode FROM StudentInputForm WHERE StudentNumber='$studentnumber'";
  5. $result = "mysql_query($sql) or die(mysql_error())";
  6. $num = mysql_num_rows(result);
  7. if($num < '0')
  8. {
  9.  echo 'The user has not filled in the form... show the button';
  10. } else {
  11.  echo 'The user has filled in the form... don\'t show the button':
  12. }
  13. mysql_close();
  14. ?>

And you can put that if statement in the/a loop and put the button code accordingly.

Hope that this helped... :D
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

simmondsjon wrote:
I guess I'm having issues with appending the moduleCode's values to a php array and then append that to php variables from a database call which returns a row, like this? I'm unsure.

Oh, what do you mean by this?
  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

thanks for the help...

I need to make it a bit clearer I think.

I have a database as follows:

Image

I have the menu where you click the button next to the corresponding form which looks like (this is for student 368642):

Image

However at the moment its just a button which just takes the user to a plain form. i.e. takes the user to the same form as every other button in the list, i.e. its just a link to the form code above (the form code is above), each button isn't assigned to that particular module code which shows up next to it. I want to assign it and link the two. So that when you click the "fill in form" for module number CS100 then it will take you to a form that says "welcome, 368462, to the form for CS100".

So, and i'm guessing here, how do I get that CS100 value assigned to the form that opens when the "fill in form" button is clicked which is located next to CS100 in the table? And the same goes for CS101...

Does that make it clearer? please I really would like some help with this :)
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Oooh, ok lol sorry about that. Missunderstood. You will need to have a URL for that form in the MySQL database... lets say for simplicity, the URL for form CS100 is localhost/mysite/modules/cs100.php...
PHP Code: [ Select ]
<?php
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "SELECT ModuleCode FROM StudentInputForm WHERE StudentNumber='$studentnumber'";
$result = "mysql_query($sql) or die(mysql_error())";
while($row = mysql_fetch_assoc(result))
{
$url = $row['moduleCode'];
echo '<a href="localhost/mysite/modules/'. $url .'.php">Module '. $url .'</a>';
}
?>
  1. <?php
  2. mysql_connect("$host", "$username", "$password") or die("cannot connect");
  3. mysql_select_db("$db_name")or die("cannot select DB");
  4. $sql = "SELECT ModuleCode FROM StudentInputForm WHERE StudentNumber='$studentnumber'";
  5. $result = "mysql_query($sql) or die(mysql_error())";
  6. while($row = mysql_fetch_assoc(result))
  7. {
  8. $url = $row['moduleCode'];
  9. echo '<a href="localhost/mysite/modules/'. $url .'.php">Module '. $url .'</a>';
  10. }
  11. ?>

You would most likely need to adjust the code to your needs, but it's pretty easy...
  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

ok thanks.. I'll give that a go... that just lit a light bulb in my head.
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

Or you could just pass a hidden value along in the form :)
HTML Code: [ Select ]
<input type="hidden" name="modulecode" value="<? use php to generate the module code here ?>">
  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

neksus wrote:
Or you could just pass a hidden value along in the form :)
HTML Code: [ Select ]
<input type="hidden" name="modulecode" value="<? use php to generate the module code here ?>">


how would I do this? sorry i'm not very good.

By making a link like "localhost/CS100" I would have to make a form for each module page.

As there is 20 different modules this is a solution, however is there a way of doing it so it crates the pages dynamically?

If someone could just whack this code in so that it works i'd be so greatful!
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

I wouldn't do it the way neksus is saying... it's just on my preference...

If you want to create the form dynamically with PHP you will need to have all of the questions in a MySQL database and those retrieved and printed out on the page in order you want it to appear.

Same way that my last example is... just the fact of printing the questions out after retrieving them from the database :D

simmondsjon wrote:
ok thanks.. I'll give that a go... that just lit a light bulb in my head.

Good. Good :)
  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

so at the moment I have a link which says "go to form for CS100".

When clicked it takes me to localhost/CS100 which is a purpose built form for the module.

Is there a way I can just make one form but just change the name of it depending on which link I clicked? so it would say "here is the form for <moduleCode>"?

Would I really need to add it all to a database? surely there's an easier way...
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Well, if the form is the same but the name changes... than all you do is change the name for the moduleCode but other than that...

You can still have 1 PHP page for module... just have it be a URL of form.php for instance and have all your questions in the MySQL database. So that means, you will be retrieving the question. All you will need to do is set up telling the form.php which module to show, so it would be like a GET function...

This example assumes you have a url of something like localhost/form.php?moduleCode=CS100
PHP Code: [ Select ]
<?php
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if($_GET['moduleCode'] == 'CS100')
{
 $sql = "SELECT * FROM field1 WHERE moduleCode='". $_GET['moduleCode'] ."'";
} elseif($_GET['moduleCode'] == 'CS101')
{
 $sql = "SELECT * FROM field1 WHERE moduleCode='". $_GET['moduleCode'] ."'";
}
$result = "mysql_query($sql) or die(mysql_error())";
$row = mysql_fetch_assoc($result);
$modulceCode = $row['moduleCode'];
$question1 = $row['question1'];
$question2 = $row['question2'];
$question3 = $row['question3'];
$question4 = $row['question4'];
$question5 = $row['question5'];
$question6 = $row['question6'];
$question7 = $row['question7'];
$question8 = $row['question8'];
$question9 = $row['question9'];
$question10 = $row['question10'];
mysql_close();
?>
<p>Please fill in the following form <<?php echo $moduleCode; ?>></p>
<form action="action.php" method="post">
<div style="border: 0px;">
<?php echo question2; ?><br />
<input type="text" name="question2" /><br />
<?php echo question1; ?><br />
<input type="text" name="question1" /><br />
<?php echo question3; ?><br />
<input type="text" name="question3" /><br />
<?php echo question4; ?><br />
<input type="text" name="question4" /><br />
<?php echo question5; ?><br />
<input type="text" name="question5" /><br />
<?php echo question6; ?><br />
<input type="text" name="question6" /><br />
<?php echo question7; ?><br />
<input type="text" name="question7" /><br />
<?php echo question8; ?><br />
<input type="text" name="question8" /><br />
<?php echo question9; ?><br />
<input type="text" name="question9" /><br />
<?php echo question10; ?><br />
<input type="text" name="question10" /><br />
<input type="submit" name="submit" value="submit" />
<input type="reset" name="reset" value="reset" />
</div>
</form>
  1. <?php
  2. mysql_connect("$host", "$username", "$password") or die("cannot connect");
  3. mysql_select_db("$db_name")or die("cannot select DB");
  4. if($_GET['moduleCode'] == 'CS100')
  5. {
  6.  $sql = "SELECT * FROM field1 WHERE moduleCode='". $_GET['moduleCode'] ."'";
  7. } elseif($_GET['moduleCode'] == 'CS101')
  8. {
  9.  $sql = "SELECT * FROM field1 WHERE moduleCode='". $_GET['moduleCode'] ."'";
  10. }
  11. $result = "mysql_query($sql) or die(mysql_error())";
  12. $row = mysql_fetch_assoc($result);
  13. $modulceCode = $row['moduleCode'];
  14. $question1 = $row['question1'];
  15. $question2 = $row['question2'];
  16. $question3 = $row['question3'];
  17. $question4 = $row['question4'];
  18. $question5 = $row['question5'];
  19. $question6 = $row['question6'];
  20. $question7 = $row['question7'];
  21. $question8 = $row['question8'];
  22. $question9 = $row['question9'];
  23. $question10 = $row['question10'];
  24. mysql_close();
  25. ?>
  26. <p>Please fill in the following form <<?php echo $moduleCode; ?>></p>
  27. <form action="action.php" method="post">
  28. <div style="border: 0px;">
  29. <?php echo question2; ?><br />
  30. <input type="text" name="question2" /><br />
  31. <?php echo question1; ?><br />
  32. <input type="text" name="question1" /><br />
  33. <?php echo question3; ?><br />
  34. <input type="text" name="question3" /><br />
  35. <?php echo question4; ?><br />
  36. <input type="text" name="question4" /><br />
  37. <?php echo question5; ?><br />
  38. <input type="text" name="question5" /><br />
  39. <?php echo question6; ?><br />
  40. <input type="text" name="question6" /><br />
  41. <?php echo question7; ?><br />
  42. <input type="text" name="question7" /><br />
  43. <?php echo question8; ?><br />
  44. <input type="text" name="question8" /><br />
  45. <?php echo question9; ?><br />
  46. <input type="text" name="question9" /><br />
  47. <?php echo question10; ?><br />
  48. <input type="text" name="question10" /><br />
  49. <input type="submit" name="submit" value="submit" />
  50. <input type="reset" name="reset" value="reset" />
  51. </div>
  52. </form>

Obviously you would need to change it a bit to fit your needs...

Basically you will have a table with module code and questions in it which than you will be retrieving from...
------
Hope that this helped a bit :)
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

PHP Code: [ Select ]
if($_GET['moduleCode'] == 'CS100')
{
 $sql = "SELECT * FROM field1 WHERE moduleCode='". $_GET['moduleCode'] ."'";
} elseif($_GET['moduleCode'] == 'CS101')
{
 $sql = "SELECT * FROM field1 WHERE moduleCode='". $_GET['moduleCode'] ."'";
}
 
  1. if($_GET['moduleCode'] == 'CS100')
  2. {
  3.  $sql = "SELECT * FROM field1 WHERE moduleCode='". $_GET['moduleCode'] ."'";
  4. } elseif($_GET['moduleCode'] == 'CS101')
  5. {
  6.  $sql = "SELECT * FROM field1 WHERE moduleCode='". $_GET['moduleCode'] ."'";
  7. }
  8.  


Instead of running and coding a boat load of if statements you could simply run the get then run the query as the SQL statement is still the same.
PHP Code: [ Select ]
$moduleCode = $_GET['moduleCode'];
$sql = "SELECT * FROM field1 WHERE moduleCode = '$moduleCode'";
 
  1. $moduleCode = $_GET['moduleCode'];
  2. $sql = "SELECT * FROM field1 WHERE moduleCode = '$moduleCode'";
  3.  
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

:lol: neksus is right haha oops... forgot about that simple thing that popped up to my face some time ago
  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

ok guys, I really appreciate the help. But now I'm pretty confused.

So now I have this, how would I do the url bit you just mentioned?

the main menu code:

Code: [ Select ]
<?php
session_start();
?>

<html>

    <head>
        <title>Main Menu</title>
    </head>
    <body>
<?php

$host="localhost:8889"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="MyDB"; // Database name
$tbl_name="Module"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$myusername=$_SESSION['myusername'];

$sql = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
$result=mysql_query($sql);

echo "Hello ";
echo $myusername;
echo ", and welcome to the main menu page!";
echo "List of modules you are enrolled on: ";
?>
<br><br>
<?php
while($row = mysql_fetch_assoc($result))
{
$url = $row['ModuleCode'];
echo '<a href="'. $url .'.php" >Go to form for '. $url .'</a>', "<br>";
}
?>

<br><br><br>
<?php
$attquery = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
$attresult=mysql_query($attquery) or die ("could not connect");
$attnum=mysql_num_rows($attresult);

echo "You are currently enrolled on a total of ";
echo $attnum;
echo " modules.";

if ($attnum > 0)
{
echo "<center><table border=1>\n";
echo "<tr align=left valign=top>\n
        <td><h3>ModuleCode</h3></td>\n
        <td><h3>Go to form</h3></td>\n
    </tr>\n";
while ($attrow=mysql_fetch_array($attresult))
{
extract($attrow);
echo "<tr>\n
<td align=center>$ModuleCode</td>\n";

$url = $attrow['ModuleCode'];

echo "<td align=center><form name=\"pageForm\" method=\"post\" action=\"pageForm.php\">
<input type=\"submit\" name=\"submit\" value=\"Fill in form\">
</form></td></tr>\n";

}
echo "</table></center>";
}
else
{
echo "<div align=center>Sorry No Module Code Avaliable!</div>";
}
?>



<br><br><br><br>
<form name="continue" method="post" action="pageForm.php">
<input type="submit" name="submit" value="Continue...">

</form>


    </body>
</html>
  1. <?php
  2. session_start();
  3. ?>
  4. <html>
  5.     <head>
  6.         <title>Main Menu</title>
  7.     </head>
  8.     <body>
  9. <?php
  10. $host="localhost:8889"; // Host name
  11. $username="root"; // Mysql username
  12. $password="root"; // Mysql password
  13. $db_name="MyDB"; // Database name
  14. $tbl_name="Module"; // Table name
  15. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  16. mysql_select_db("$db_name")or die("cannot select DB");
  17. $myusername=$_SESSION['myusername'];
  18. $sql = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
  19. $result=mysql_query($sql);
  20. echo "Hello ";
  21. echo $myusername;
  22. echo ", and welcome to the main menu page!";
  23. echo "List of modules you are enrolled on: ";
  24. ?>
  25. <br><br>
  26. <?php
  27. while($row = mysql_fetch_assoc($result))
  28. {
  29. $url = $row['ModuleCode'];
  30. echo '<a href="'. $url .'.php" >Go to form for '. $url .'</a>', "<br>";
  31. }
  32. ?>
  33. <br><br><br>
  34. <?php
  35. $attquery = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
  36. $attresult=mysql_query($attquery) or die ("could not connect");
  37. $attnum=mysql_num_rows($attresult);
  38. echo "You are currently enrolled on a total of ";
  39. echo $attnum;
  40. echo " modules.";
  41. if ($attnum > 0)
  42. {
  43. echo "<center><table border=1>\n";
  44. echo "<tr align=left valign=top>\n
  45.         <td><h3>ModuleCode</h3></td>\n
  46.         <td><h3>Go to form</h3></td>\n
  47.     </tr>\n";
  48. while ($attrow=mysql_fetch_array($attresult))
  49. {
  50. extract($attrow);
  51. echo "<tr>\n
  52. <td align=center>$ModuleCode</td>\n";
  53. $url = $attrow['ModuleCode'];
  54. echo "<td align=center><form name=\"pageForm\" method=\"post\" action=\"pageForm.php\">
  55. <input type=\"submit\" name=\"submit\" value=\"Fill in form\">
  56. </form></td></tr>\n";
  57. }
  58. echo "</table></center>";
  59. }
  60. else
  61. {
  62. echo "<div align=center>Sorry No Module Code Avaliable!</div>";
  63. }
  64. ?>
  65. <br><br><br><br>
  66. <form name="continue" method="post" action="pageForm.php">
  67. <input type="submit" name="submit" value="Continue...">
  68. </form>
  69.     </body>
  70. </html>


and the form code:

Code: [ Select ]
<?php
session_start();
$host="localhost:8889"; // Host name
$username="root"; // Mysql username
$password="root"; // Mysql password
$db_name="MyDB"; // Database name
$tbl_name="Module"; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$ModuleCode = $_GET['ModuleCode'];
//$sql = "SELECT * FROM field1 WHERE ModuleCode = '$ModuleCode'";
$sql = "SELECT `ModuleCode` FROM `Module` WHERE ModuleCode='$ModuleCode'";


$result = "mysql_query($sql) or die(mysql_error())";
$row = mysql_fetch_assoc($result);
$ModuleCode = $row['ModuleCode'];
$question1 = $row['question1'];
$question2 = $row['question2'];
$question3 = $row['question3'];
$question4 = $row['question4'];
$question5 = $row['question5'];
$question6 = $row['question6'];
$question7 = $row['question7'];
$question8 = $row['question8'];
$question9 = $row['question9'];
$question10 = $row['question10'];
mysql_close();
?>
<p>Please fill in the following form <<?php echo $ModuleCode; ?>></p>
<form action="action.php" method="post">
<div style="border: 0px;">
<?php echo question1; ?><br />
<input type="text" name="question2" /><br />
<?php echo question2; ?><br />
<input type="text" name="question1" /><br />
<?php echo question3; ?><br />
<input type="text" name="question3" /><br />
<?php echo question4; ?><br />
<input type="text" name="question4" /><br />
<?php echo question5; ?><br />
<input type="text" name="question5" /><br />
<?php echo question6; ?><br />
<input type="text" name="question6" /><br />
<?php echo question7; ?><br />
<input type="text" name="question7" /><br />
<?php echo question8; ?><br />
<input type="text" name="question8" /><br />
<?php echo question9; ?><br />
<input type="text" name="question9" /><br />
<?php echo question10; ?><br />
<input type="text" name="question10" /><br />
<input type="submit" name="submit" value="submit" />
<input type="reset" name="reset" value="reset" />
</div>
</form>
  1. <?php
  2. session_start();
  3. $host="localhost:8889"; // Host name
  4. $username="root"; // Mysql username
  5. $password="root"; // Mysql password
  6. $db_name="MyDB"; // Database name
  7. $tbl_name="Module"; // Table name
  8. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  9. mysql_select_db("$db_name")or die("cannot select DB");
  10. $ModuleCode = $_GET['ModuleCode'];
  11. //$sql = "SELECT * FROM field1 WHERE ModuleCode = '$ModuleCode'";
  12. $sql = "SELECT `ModuleCode` FROM `Module` WHERE ModuleCode='$ModuleCode'";
  13. $result = "mysql_query($sql) or die(mysql_error())";
  14. $row = mysql_fetch_assoc($result);
  15. $ModuleCode = $row['ModuleCode'];
  16. $question1 = $row['question1'];
  17. $question2 = $row['question2'];
  18. $question3 = $row['question3'];
  19. $question4 = $row['question4'];
  20. $question5 = $row['question5'];
  21. $question6 = $row['question6'];
  22. $question7 = $row['question7'];
  23. $question8 = $row['question8'];
  24. $question9 = $row['question9'];
  25. $question10 = $row['question10'];
  26. mysql_close();
  27. ?>
  28. <p>Please fill in the following form <<?php echo $ModuleCode; ?>></p>
  29. <form action="action.php" method="post">
  30. <div style="border: 0px;">
  31. <?php echo question1; ?><br />
  32. <input type="text" name="question2" /><br />
  33. <?php echo question2; ?><br />
  34. <input type="text" name="question1" /><br />
  35. <?php echo question3; ?><br />
  36. <input type="text" name="question3" /><br />
  37. <?php echo question4; ?><br />
  38. <input type="text" name="question4" /><br />
  39. <?php echo question5; ?><br />
  40. <input type="text" name="question5" /><br />
  41. <?php echo question6; ?><br />
  42. <input type="text" name="question6" /><br />
  43. <?php echo question7; ?><br />
  44. <input type="text" name="question7" /><br />
  45. <?php echo question8; ?><br />
  46. <input type="text" name="question8" /><br />
  47. <?php echo question9; ?><br />
  48. <input type="text" name="question9" /><br />
  49. <?php echo question10; ?><br />
  50. <input type="text" name="question10" /><br />
  51. <input type="submit" name="submit" value="submit" />
  52. <input type="reset" name="reset" value="reset" />
  53. </div>
  54. </form>


I don't for the life of me get how these two will interact. I just want it to display the same form for each module, but for it just to change the name of the form depending on the corresponding form button :cry:

I see what you've done with the form, but I can't get it to work. And I cant see how it would link from the button on the main menu to display the corresponding form. Do i need to change my database? Sorry if i'm being really dull, you both must think I haven't got a nounce, can you please get it working for me I'd be so grateful. please?
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

First thing first... the SQL is wrong... The following is what you have...
Code: [ Select ]
$sql = "SELECT `ModuleCode` FROM `Module` WHERE ModuleCode='$ModuleCode'";

The following is what you need...
Code: [ Select ]
$sql = "SELECT * FROM `Module` WHERE ModuleCode='$ModuleCode'";

Ok, about the URL thing... basically here is how the URL would look like...
Quote:
localhost/form.php?moduleCode=cs100

Where you see cs100 that is what you change to the module code that you need... lets say that your module code is cs132, than you will change cs100 to cs132. I think it's fairly easy to comprehend but that may be because I have done this many times.

Good luck with all of this :) Hope that we are helping you more than we are confusing you :lol:
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

Firstly:
PHP Code: [ Select ]
<?php
session_start();
 
$host="localhost:8889";
$username="root";
$password="root";
$db_name="MyDB";
$tbl_name="Module";
 
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
 
$ModuleCode = $_POST['ModuleCode']; //!-- important!
 
$sql = "SELECT * FROM <span style="font-weight: bold">the database where your questions are</span>";
$result = mysql_query($sql);
 
echo '<form action="action.php" method="post">';
echo "<p>Please fill in the following for form ";
 
while($r=mysql_fetch_array($result) or die(mysql_error()){
 echo "$ModuleCode.</p><div style=\"border: 0px;\">";
 for($count = 1; $count <= 10; $count++){
   echo "$r[question$count]<br /><input type=\"text\" name=\"question$count\" /><br />";
 }
}
 
mysql_close();
 
  1. <?php
  2. session_start();
  3.  
  4. $host="localhost:8889";
  5. $username="root";
  6. $password="root";
  7. $db_name="MyDB";
  8. $tbl_name="Module";
  9.  
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. $ModuleCode = $_POST['ModuleCode']; //!-- important!
  14.  
  15. $sql = "SELECT * FROM <span style="font-weight: bold">the database where your questions are</span>";
  16. $result = mysql_query($sql);
  17.  
  18. echo '<form action="action.php" method="post">';
  19. echo "<p>Please fill in the following for form ";
  20.  
  21. while($r=mysql_fetch_array($result) or die(mysql_error()){
  22.  echo "$ModuleCode.</p><div style=\"border: 0px;\">";
  23.  for($count = 1; $count <= 10; $count++){
  24.    echo "$r[question$count]<br /><input type=\"text\" name=\"question$count\" /><br />";
  25.  }
  26. }
  27.  
  28. mysql_close();
  29.  
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

And secondly...
PHP Code: [ Select ]
<?php
session_start();
?>
 
<html>
<head>
<title>Main Menu</title>
</head>
<body>
 
<?php
 
$host="localhost:8889";
$username="root";
$password="root";
$db_name="MyDB";
$tbl_name="Module";
 
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
 
$myusername=$_SESSION['myusername'];
 
$sql = "SELECT * FROM Module WHERE StudentNumber='$myusername'";
$result=mysql_query($sql);
 
echo "Hello $myusername, and welcome to the main menu page! Here is the list of modules you are currently enrolled in: ";
 
while($row = mysql_fetch_assoc($result)) {
 $url = $row['ModuleCode'];
 echo '<a href="'. $url .'.php" >Go to form for '. $url .'</a>', "<br>";
}
 
$attquery = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
$attresult=mysql_query($attquery) or die ("could not connect");
$attnum=mysql_num_rows($attresult);
 
echo "<p>You are currently enrolled in a total of $attnum modules.";
 
if ($attnum > 0) {
 echo "<center><table border=1>\n
    <tr align=left valign=top>\n
    <td><h3>ModuleCode</h3></td>\n
    <td><h3>Go to form</h3></td>\n
    </tr>\n";
 while ($attrow=mysql_fetch_array($attresult)) {
    extract($attrow);
    echo "<tr>\n<td align=center>$ModuleCode</td>\n";
 
    $url = $attrow['ModuleCode'];
 
    echo "<td align=center><form name=\"pageForm\" method=\"post\" action=\"pageForm.php\">
<input type=\"hidden\" name=\"ModuleCode\" value=\"$ModuleCode\"><input type=\"submit\" name=\"submit\" value=\"Fill in form\"></form></td></tr>\n";
 
 }
 echo "</table></center>";
 
} else {
 echo "<div align=center>Sorry No Module Code Avaliable!</div>";
}
?>
 
<br><br><br><br>
<form name="continue" method="post" action="pageForm.php">
<input type="submit" name="submit" value="Continue...">
 
</form>
</body>
</html>
 
  1. <?php
  2. session_start();
  3. ?>
  4.  
  5. <html>
  6. <head>
  7. <title>Main Menu</title>
  8. </head>
  9. <body>
  10.  
  11. <?php
  12.  
  13. $host="localhost:8889";
  14. $username="root";
  15. $password="root";
  16. $db_name="MyDB";
  17. $tbl_name="Module";
  18.  
  19. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  20. mysql_select_db("$db_name")or die("cannot select DB");
  21.  
  22. $myusername=$_SESSION['myusername'];
  23.  
  24. $sql = "SELECT * FROM Module WHERE StudentNumber='$myusername'";
  25. $result=mysql_query($sql);
  26.  
  27. echo "Hello $myusername, and welcome to the main menu page! Here is the list of modules you are currently enrolled in: ";
  28.  
  29. while($row = mysql_fetch_assoc($result)) {
  30.  $url = $row['ModuleCode'];
  31.  echo '<a href="'. $url .'.php" >Go to form for '. $url .'</a>', "<br>";
  32. }
  33.  
  34. $attquery = "SELECT `ModuleCode` FROM `Module` WHERE StudentNumber='$myusername'";
  35. $attresult=mysql_query($attquery) or die ("could not connect");
  36. $attnum=mysql_num_rows($attresult);
  37.  
  38. echo "<p>You are currently enrolled in a total of $attnum modules.";
  39.  
  40. if ($attnum > 0) {
  41.  echo "<center><table border=1>\n
  42.     <tr align=left valign=top>\n
  43.     <td><h3>ModuleCode</h3></td>\n
  44.     <td><h3>Go to form</h3></td>\n
  45.     </tr>\n";
  46.  while ($attrow=mysql_fetch_array($attresult)) {
  47.     extract($attrow);
  48.     echo "<tr>\n<td align=center>$ModuleCode</td>\n";
  49.  
  50.     $url = $attrow['ModuleCode'];
  51.  
  52.     echo "<td align=center><form name=\"pageForm\" method=\"post\" action=\"pageForm.php\">
  53. <input type=\"hidden\" name=\"ModuleCode\" value=\"$ModuleCode\"><input type=\"submit\" name=\"submit\" value=\"Fill in form\"></form></td></tr>\n";
  54.  
  55.  }
  56.  echo "</table></center>";
  57.  
  58. } else {
  59.  echo "<div align=center>Sorry No Module Code Avaliable!</div>";
  60. }
  61. ?>
  62.  
  63. <br><br><br><br>
  64. <form name="continue" method="post" action="pageForm.php">
  65. <input type="submit" name="submit" value="Continue...">
  66.  
  67. </form>
  68. </body>
  69. </html>
  70.  
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

In neksus' while loop...
Code: [ Select ]
while($r=mysql_fetch_array($result) or die(mysql_error()){
echo "$ModuleCode.</p><div style=\"border: 0px;\">";
for($count = 1; $count <= 10; $count++){
    echo "$r[question$count]<br /><input type=\"text\" name=\"question$count\" /><br />";
}
}
  1. while($r=mysql_fetch_array($result) or die(mysql_error()){
  2. echo "$ModuleCode.</p><div style=\"border: 0px;\">";
  3. for($count = 1; $count <= 10; $count++){
  4.     echo "$r[question$count]<br /><input type=\"text\" name=\"question$count\" /><br />";
  5. }
  6. }

The $r[question$count] should be...
Code: [ Select ]
while($r=mysql_fetch_array($result) or die(mysql_error()){
echo "$ModuleCode.</p><div style=\"border: 0px;\">";
for($count = 1; $count <= 10; $count++){
    echo "$r['question$'. count]<br /><input type=\"text\" name=\"question$count\" /><br />";
}
}
  1. while($r=mysql_fetch_array($result) or die(mysql_error()){
  2. echo "$ModuleCode.</p><div style=\"border: 0px;\">";
  3. for($count = 1; $count <= 10; $count++){
  4.     echo "$r['question$'. count]<br /><input type=\"text\" name=\"question$count\" /><br />";
  5. }
  6. }

So the $r[question$count] changed to $r['question'. $count]

---

Also neksus, quit coding codes that are better than mine :lol:
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

neksus wrote:
Code: [ Select ]
...
$ModuleCode = $_POST['ModuleCode']; //!-- important!
...
  1. ...
  2. $ModuleCode = $_POST['ModuleCode']; //!-- important!
  3. ...


Shouldn't that be
Code: [ Select ]
...
$ModuleCode = $_GET['ModuleCode']; //!-- important!
...
  1. ...
  2. $ModuleCode = $_GET['ModuleCode']; //!-- important!
  3. ...

?
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

Nope. Look at my form code :)
  • may
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Holland [NL]

Post 3+ Months Ago

<?php echo question1; ?><br />
<input type="text" name="question2" /><br />
<?php echo question2; ?><br />
<input type="text" name="question1" /><br />
<?php echo question3; ?><br />

Doesnt that lack the $ in " echo question1; "
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

It sure does. And the questions weren't being selected from the db.
  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

hi guys

Code: [ Select ]
<?php
session_start();

$host="localhost:8889";
$username="root";
$password="root";
$db_name="MyDB";
$tbl_name="Module";

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$ModuleCode = $_POST['ModuleCode'];

$sql = "SELECT * FROM `Module` WHERE ModuleCode='$ModuleCode'";
$result = mysql_query($sql);

echo '<form action="action.php" method="post">';
echo "<p>Please fill in the following for form ";

while($r=mysql_fetch_array($result) or die(mysql_error()){
echo "$ModuleCode.</p><div style=\"border: 0px;\">";
for($count = 1; $count <= 10; $count++){
echo "$r['question$'. count]<br /><input type=\"text\" name=\"question$count\" /><br />";
}
}
mysql_close();
?>
<p>Please fill in the following form <<?php echo $ModuleCode; ?>></p>
<form action="action.php" method="post">
<div style="border: 0px;">
<?php echo question1; ?><br />
<input type="text" name="question2" /><br />
<?php echo question2; ?><br />
<input type="text" name="question1" /><br />
<?php echo question3; ?><br />
<input type="text" name="question3" /><br />
<?php echo question4; ?><br />
<input type="text" name="question4" /><br />
<?php echo question5; ?><br />
<input type="text" name="question5" /><br />
<?php echo question6; ?><br />
<input type="text" name="question6" /><br />
<?php echo question7; ?><br />
<input type="text" name="question7" /><br />
<?php echo question8; ?><br />
<input type="text" name="question8" /><br />
<?php echo question9; ?><br />
<input type="text" name="question9" /><br />
<?php echo question10; ?><br />
<input type="text" name="question10" /><br />
<input type="submit" name="submit" value="submit" />
<input type="reset" name="reset" value="reset" />
</div>
</form>
  1. <?php
  2. session_start();
  3. $host="localhost:8889";
  4. $username="root";
  5. $password="root";
  6. $db_name="MyDB";
  7. $tbl_name="Module";
  8. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  9. mysql_select_db("$db_name")or die("cannot select DB");
  10. $ModuleCode = $_POST['ModuleCode'];
  11. $sql = "SELECT * FROM `Module` WHERE ModuleCode='$ModuleCode'";
  12. $result = mysql_query($sql);
  13. echo '<form action="action.php" method="post">';
  14. echo "<p>Please fill in the following for form ";
  15. while($r=mysql_fetch_array($result) or die(mysql_error()){
  16. echo "$ModuleCode.</p><div style=\"border: 0px;\">";
  17. for($count = 1; $count <= 10; $count++){
  18. echo "$r['question$'. count]<br /><input type=\"text\" name=\"question$count\" /><br />";
  19. }
  20. }
  21. mysql_close();
  22. ?>
  23. <p>Please fill in the following form <<?php echo $ModuleCode; ?>></p>
  24. <form action="action.php" method="post">
  25. <div style="border: 0px;">
  26. <?php echo question1; ?><br />
  27. <input type="text" name="question2" /><br />
  28. <?php echo question2; ?><br />
  29. <input type="text" name="question1" /><br />
  30. <?php echo question3; ?><br />
  31. <input type="text" name="question3" /><br />
  32. <?php echo question4; ?><br />
  33. <input type="text" name="question4" /><br />
  34. <?php echo question5; ?><br />
  35. <input type="text" name="question5" /><br />
  36. <?php echo question6; ?><br />
  37. <input type="text" name="question6" /><br />
  38. <?php echo question7; ?><br />
  39. <input type="text" name="question7" /><br />
  40. <?php echo question8; ?><br />
  41. <input type="text" name="question8" /><br />
  42. <?php echo question9; ?><br />
  43. <input type="text" name="question9" /><br />
  44. <?php echo question10; ?><br />
  45. <input type="text" name="question10" /><br />
  46. <input type="submit" name="submit" value="submit" />
  47. <input type="reset" name="reset" value="reset" />
  48. </div>
  49. </form>


is there an error in this code? It wont show up in my browser when i 'run' it, all I get is a bank white page. If I comment out the while loop then it will show.
  • may
  • Proficient
  • Proficient
  • User avatar
  • Posts: 328
  • Loc: Holland [NL]

Post 3+ Months Ago

ah :) ps, do point out the security risk of pasing $_ method super globals directly into sql queries...

$username = $_GET['MyFormEntry'];
$sql = "select * from somewhere where username = '$username'";

Good luck btw :)
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

Yes, it was errored. Did you try my original solution? Try this, instead.

PHP Code: [ Select ]
while($r=mysql_fetch_array($result) or die(mysql_error()){
 echo "$ModuleCode.</p><div style=\"border: 0px;\">";
 for($count = 1; $count <= 10; $count++){
    $qtext = "question$count";
    echo "$r[$qtext]<br /><input type=\"text\" name=\"question$count\" /><br />";
 }
}
 
  1. while($r=mysql_fetch_array($result) or die(mysql_error()){
  2.  echo "$ModuleCode.</p><div style=\"border: 0px;\">";
  3.  for($count = 1; $count <= 10; $count++){
  4.     $qtext = "question$count";
  5.     echo "$r[$qtext]<br /><input type=\"text\" name=\"question$count\" /><br />";
  6.  }
  7. }
  8.  


may - I used post, not get ;)
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

may wrote:
ah :) ps, do point out the security risk of pasing $_ method super globals directly into sql queries...

$username = $_GET['MyFormEntry'];
$sql = "select * from somewhere where username = '$username'";

Good luck btw :)

The $username is selecting from the database and not inserting or altering it in any way...

@simmondsjon

Remove all of my code...
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

This was an accidental post... as I am not allowed to delete my own post I am forced to keep this as it is...


Anayway... I hope that you get it solved out :)
  • neksus
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 2194
  • Loc: Canada

Post 3+ Months Ago

Quote:
The $username is selecting from the database and not inserting or altering it in any way...

also a valid point ;)
  • simmondsjon
  • Novice
  • Novice
  • simmondsjon
  • Posts: 20

Post 3+ Months Ago

helloo, oo its nearly there, but,

Code: [ Select ]
<?php
session_start();

$host="localhost:8889";
$username="root";
$password="root";
$db_name="MyDB";
$tbl_name="Module";

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$ModuleCode = $_POST['ModuleCode'];

$sql = "SELECT * FROM `Module` WHERE ModuleCode='$ModuleCode'";
$result = mysql_query($sql);

echo $result;

echo '<form action="action.php" method="post">';
echo "<p>Please fill in the following for form ";

while($r=mysql_fetch_array($result) or die(mysql_error()){
echo "$ModuleCode.</p><div style=\"border: 0px;\">";
for($count = 1; $count <= 10; $count++){
$qtext = "question$count";
echo "$r[$qtext]<br /><input type=\"text\" name=\"question$count\" /><br />";
}
}
mysql_close();
?>
  1. <?php
  2. session_start();
  3. $host="localhost:8889";
  4. $username="root";
  5. $password="root";
  6. $db_name="MyDB";
  7. $tbl_name="Module";
  8. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  9. mysql_select_db("$db_name")or die("cannot select DB");
  10. $ModuleCode = $_POST['ModuleCode'];
  11. $sql = "SELECT * FROM `Module` WHERE ModuleCode='$ModuleCode'";
  12. $result = mysql_query($sql);
  13. echo $result;
  14. echo '<form action="action.php" method="post">';
  15. echo "<p>Please fill in the following for form ";
  16. while($r=mysql_fetch_array($result) or die(mysql_error()){
  17. echo "$ModuleCode.</p><div style=\"border: 0px;\">";
  18. for($count = 1; $count <= 10; $count++){
  19. $qtext = "question$count";
  20. echo "$r[$qtext]<br /><input type=\"text\" name=\"question$count\" /><br />";
  21. }
  22. }
  23. mysql_close();
  24. ?>


I now have this... but still getting a blank white screen when I test it.

Is this all right?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 45 posts
  • Users browsing this forum: No registered users and 103 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.