kankaro Posted January 28, 2008 Share Posted January 28, 2008 hello guys can you help me with my code. There's something fishy that i don't understand. can you guys help me out to solve these. here's the scenario. i've created a php code that will simply automatically add an integer that is inputed to the form into the database including the summation of the integer. for example 1+2+3+4+5 = 15 my aim is those numbers 1 2 3 4 and 5 that i inputed in the form will be inserted to the database including the total of those numbers in just one click of submit button but it doesn't work. i tried another way, when im going to click submit i'll just get the total of the sum of all the number and pass it into another page which process to insert that data into the database but the result is still the same it wont insert to the database. this my database design. |--------------------------------------------------------------------------------------------------- | Field | Type | Null | Key | Default | Extra |--------------------------------------------------------------------------------------------------- |id_no | int(10) | NO | Pri | Null | auto_increment |full_name |varchar(25) | NO | | | |1st_grade |float(4,2) unsigned | NO | | | |2nd_grade |float(4,2) unsigned | NO | | | |3rd_grade |float(4,2) unsigned | NO | | | |4th_grade |float(4,2) unsigned | NO | | | |total |float(6,2) unsigned | NO | | | ---------------------------------------------------------------------------------------------------- I will show my code on how i do it. this is my code to get the total of the number that i inputed and pass it on another page. <?php $first_grade = 00; $second_grade = 00; $third_grade = 00; $fourth_grade = 00; $total_grade = 00; function calculate($first_grade,$second_grade,$third_grade,$fourth_grade) { global $first_grade,$second_grade,$third_grade,$fourth_grade; $total = (($first_grade+$second_grade)+($third_grade+$fourth_grade)); return $total; } $first_grade = isset($_POST['first_grade']) ? $_POST['first_grade'] : ''; $second_grade = isset($_POST['second_grade']) ? $_POST['second_grade'] : ''; $third_grade = isset($_POST['third_grade']) ? $_POST['third_grade'] : ''; $fourth_grade = isset($_POST['fourth_grade']) ? $_POST['fourth_grade'] : ''; $total_grade = isset($_POST['total_grade']) ? $_POST['total_grade'] : ''; if(empty($_POST['fullname'])){ $fullname=FALSE; $msg = "You need to fill-up the form"; } else { $fullname=$_POST['fullname']; } ?> <?php if((isset($_POST['submit']) && ($fullname != '') && ($first_grade != '') && ($first_grade != '') && ($first_grade != '') && ($first_grade != ''))) { ?> <?php $total_grade = abs(calculate($first_grade,$second_grade,$third_grade,$fourth_grade)); } else { echo "$msg"; } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <table> <tr> <td>Name:</td> <td><input type="text" name="fullname" value="<?php echo $fullname; ?>" /></td> </tr> <tr> <td>First Grade:</td> <td><input type="text" name="first_grade" value="<?php echo $first_grade; ?>" /></td> </tr> <tr> <td>Second Grade:</td> <td><input type="text" name="second_grade" value="<?php echo $second_grade; ?>"/></td> </tr> <tr> <td>Third Grade:</td> <td><input type="text" name="third_grade" value="<?php echo $third_grade; ?>"/></td> </tr> <tr> <td>Fourth Grade:</td> <td><input type="text" name="fourth_grade" value="<?php echo $fourth_grade; ?>"/></td> </tr> <tr> <td>Total Grade:</td> <td><?php echo $total_grade; ?></td> </tr> <tr> <td align="center"><input type="submit" name="submit" value="submit"/></td> <?php echo "<td align=\"center\"><a href=\"addgrade.php?name=$fullname&first_grade=$first_grade&second_grade=$second_grade&third_grade=$third_grade&fourth_grade=$fourth_grade&total_grade=$total_grade\" target=\"_blank\">submit</a></td> </tr>"; ?> </table></form> And this is the code that will process for inserting my data to the database it will get the data that i pass and then process to insert in the database. <?php if(isset($_GET['add'])){ include('connect.php'); $query="INSERT INTO grade VALUES (null, '$_GET[name]', $_GET[first_grade], $_GET[second_grade], $_GET[third_grade], $_GET[fourth_grade], $_GET[total_grade])"; echo "$query"; $sqlResult=mysql_query($query); if(mysql_affected_rows($dbc)>0){ echo "Successfully Added"; } else{ echo "Process Failed, Error ecounter"; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET"> <table> <tr> <td>Fullname:</td> <td><input type="text" name="name" value="<?php echo "$_GET[name]"; ?>" /></td> </tr> <tr> <td>First Grade:</td> <td><input type="text" name="first_grade" value="<?php echo "$_GET[first_grade]"; ?> " /></td> </tr> <tr> <td>Second Grade:</td> <td><input type="text" name="second_grade" value="<?php echo "$_GET[second_grade]"; ?>"/></td> </tr> <tr> <td>Third Grade:</td> <td><input type="text" name="third_grade" value="<?php echo "$_GET[third_grade]"; ?>"/></td> </tr> <tr> <td>Fourth Grade:</td> <td><input type="text" name="fourth_grade" value="<?php echo "$_GET[fourth_grade]"; ?>"/></td> </tr> <tr> <td>Total Grade:</td> <td><input type="text" name="total_grade" value="<?php echo "$_GET[total_grade]"; ?>"/></td> </tr> <tr> <td align="center"><input type="submit" name="add" value="Add"/></td> </tr> </table></form> Quote Link to comment https://forums.phpfreaks.com/topic/88129-hey-guys-can-you-help-me-with-this/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.