Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
php form help needed please!!!!
Old 04-23-2006, 07:16 AM php form help needed please!!!!
Junior Talker

Posts: 1
Trades: 0
Hi I am creating a grade caculation website and am having trouble with submitting a form on my page.
my code gives option to user to select his course of study. From this selection my code pulls all modules from that course from my database and displays it on the screen. This all works ok.

after i display all modules and module weight(which i need to calc the grade average) i have put in a drop down list where the user can select his grade value.
My problem is how to submit these values. I have tried using action=$_SERVER[PHP_SELF] but this just reloads my origianl page where the user can select his course so then i have value of grade but lose info i have got from database.
I have also tried to post form to new php doc but then i also dont have values i have taken from database.

So i would like to know is there a way to submit the form to a php function where i can do calculation or a way to submit form without reloading page???

The last 20 or so lines of code are where i am havng diffficulty. I have posted my code below.

hope this makes some sense!! any help will be much appreciated.


PHP Code:
//connect to database
$conn mysql_connect("localhost""stuart""stuart") or die(mysql_error());
mysql_select_db("stuart",$conn) or die(mysql_error());
 
if (
$_POST[op] != "view") {
//haven't seen the selection form, so show it
$display_block "<h1>Select Your course</h1>";
 
//get parts of records
$get_list "select course_id, concat_ws(', ', course_name) as display_name from course";
 
$get_list_res mysql_query($get_list) or die(mysql_error());
 
if (
mysql_num_rows($get_list_res) < 1) {
//no records
$display_block .= "<p><em>Sorry, no records to select!</em></p>";
 
} else {
//has records, so get results and print in a form
 
$display_block .= "
 
<form method=\"post\" action=\"
$_SERVER[PHP_SELF]\">
<P><strong>Select a Record to View:</strong><br>
<select name=\"sel_id\">
<option value=\"\">-- Select One --</option>"
;
 
 
while (
$recs mysql_fetch_array($get_list_res)) {
$id $recs['course_id'];
$display_name stripslashes($recs['display_name']);
 
$display_block .= "<option value=\"$id\">$display_name</option>";
}
$display_block .= "
</select>
<input type=\"hidden\" name=\"op\" value=\"view\">
<p><input type=\"submit\" name=\"submit\" value=\"View Modules\"></p>
</FORM>"
;
 
 

 
 
} else if (
$_POST[op] == "view") {
 
//check for required fields
if ($_POST[sel_id] == "") {
header("Location: selcourse.php");
exit;
}
 
 
//get master_info
$get_master "select course_name as display_name from course where course_id = $_POST[sel_id]";
$get_master_res mysql_query($get_master);
$display_name stripslashes(mysql_result($get_master_res0,'display_name'));
$display_block "<h1>Showing Modules for $display_name</h1>";
 
 
 
//get all module for semester 1
$get_modules "select mod_code, mod_weight from module where course_id = $_POST[sel_id] && sem_num = 1";
$get_modules_res mysql_query($get_modules);
 
if (
mysql_num_rows($get_modules_res) > 0) {
 
 
 
$display_block .= "
<table celpadding=3 cellspacing=2 border=1 width=98%>
<tr>
<th>Semester 1</th>
<tr>
<tr>
<th>Course code</th>
<th>Weight</th>
<th>Result</th>
</tr>"
;
 
 
$sem1=0;
$modres=1;
 
while (
$add_info mysql_fetch_array($get_modules_res)) {
 
 
 
$modname $add_info[mod_code];
$modweight $add_info[mod_weight];
$sumcred1 $sumcred1+$modweight;
$numvalue[$sem1] = $modweight;
 
 
$display_block .= "<form method=\"post\"action=\"$_SERVER[PHP_SELF]\" >";
 
 
 
$display_block .= "<tr>
 
 
<td align=left>
$modname <br></td>
<td align=left>
$modweight <br></td>
 
 
<td align=left> 
 
<select name=\"
$modres\">
<option value=\"\">-- Select Result --</option>
<option value=\"4.00\">A1</option>
<option value=\"3.60\">A2</option>
<option value=\"3.20\">B1</option>
<option value=\"3.00\">B2</option>
<option value=\"2.80\">B3</option>
<option value=\"2.60\">C1</option>
<option value=\"2.40\">C2</option>
<option value=\"2.00\">C3</option>
<option value=\"1.60\">D1</option>
<option value=\"1.20\">D2</option>
<option value=\"0.00\">F</option>
<option value=\"0.00\">NG</option>
</select>
 
<br></td>
 
 
 
"
;
$sem1++;
$modres++;
}
 
 
 
$display_block .= "<td><input type=\"submit\" name=\"submit\" value=\"calculate\"></td></tr>
</form>"


Last edited by 0beron; 04-23-2006 at 11:31 AM..
stuart6521 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-23-2006, 02:04 PM Re: php form help needed please!!!!
Super Talker

Posts: 116
Trades: 0
no u cant execute a php function without reloading the page since the script is executed on the server itself. u wud need javascript to do calculations without reloading.
__________________


Please login or register to view this content. Registration is FREE

nasaboy007 is offline
Reply With Quote
View Public Profile Visit nasaboy007's homepage!
 
Reply     « Reply to php form help needed please!!!!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34046 seconds with 12 queries