What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Need help in PHP

Need help in PHP
Author: Message:
Odin.EXE
Full Member
***

Avatar

Posts: 198
35 / Male / –
Joined: Jul 2003
O.P. Need help in PHP
Hi all, I'm working on a project but the function that I want doesn't work.

There is this button called "add student" and a new row will appear when I clicked that button. However the data I wrote in the previous first row will disappear when I click that button for a 2nd row.

Here is the code
code:
<?php
session_start();
if (isset($_POST['AddStudent'])) {
// If user click on Add new student button
    $temp = $_SESSION['numberOfStudents'];
    $temp = $temp + 1;
    $_SESSION['numberOfStudents'] = $temp;
}
/*else if (isset($_POST['FinalCheckBtn'])) {
// If user click on Final Check button go to Final check page
header('Location: http://localhost/SJAA/final_check.php') ;
}*/
else {
// if User enter this page the first time from "create new class page "
    // the variable that hold the credentials to connect to the database
    $dbserver = "localhost";
    $dbuser = "root";
    $dbpassword = "";
    $dbname = "fyp - sem 1";
    // connect to DB
    mysql_connect($dbserver, $dbuser, $dbpassword) or die(mysql_error());
    // select the correct db.
    mysql_select_db($dbname) or die(mysql_error());


    // Read variables from the $_POST array
    $class_name = $_POST['class_name'];
    $class_venue = $_POST['class_venue'];
    $date_of_lesson =$_POST['date_of_lesson'];
    $time_of_lesson =$_POST['time_of_lesson'];
    $class_duration =$_POST['class_duration'];
    $date_of_exam =$_POST['date_of_exam'];
    $class_in_charge =$_POST['class_in_charge'];   
    $contact =$_POST['contact'];
    $email =$_POST['email'];

    // Prepare the query

    $sql = "INSERT INTO b_class (class_name,class_venue,date_of_lesson,time_of_lesson,class_duration,date_of_exam,class_in_charge,contact,email) VALUES
                ('$class_name','$class_venue','$date_of_lesson','$time_of_lesson','$class_duration','$date_of_exam','$class_in_charge','$contact','$email')";

    // Execute the query
    mysql_query($sql) or die(mysql_error());
    $_SESSION['numberOfStudents'] = 0;
    $_SESSION['class_name']=$_POST['class_name'];
    $_SESSION['class_venue'] = $_POST['class_venue'];
    $_SESSION['date_of_lesson'] = $_POST['date_of_lesson'];
    $_SESSION['time_of_lesson'] = $_POST['time_of_lesson'];
    $_SESSION['class_duration'] = $_POST['class_duration'];
    $_SESSION['date_of_exam'] = $_POST['date_of_exam'];
    $_SESSION['class_in_charge'] = $_POST['class_in_charge'];
    $_SESSION['contact'] = $_POST['contact'];
    $_SESSION['email'] = $_POST['email'];
   

}
?>
<html>
<form enctype="multipart/form-data" action = 'student_details.php' method='post' />
<img style="width: 190px; height: 184px;" alt="" src="images/Picture1.jpg">

<head><title>Students' Particulars</title></head>
<h1>Students' Particulars</h1>
<h3> Please enter student's particulars. All fields are to be filled. </h3>
<table style="text-align: left; width: 333px; height: 144px;"
border="1" cellpadding="2" cellspacing="2">
  <tbody>
    <tr>
      <td><?php
echo "Class Name: ";
echo $_SESSION['class_name'];?> </td>
</tr>
    <tr>
      <td><?php
echo "Class Venue: ";
echo $_SESSION['class_venue'];?> </td>
</tr>
<tr>
      <td><?php
echo "Date of Lesson: ";
echo $_SESSION['date_of_lesson'];?> </td>
</tr>
<tr>
      <td><?php
echo "Time: ";
echo $_SESSION['time_of_lesson'];?> </td>
</tr>
<tr>
      <td><?php
echo "Class Duration: ";
echo $_SESSION['class_duration'];?> </td>
</tr>
<tr>
      <td><?php
echo "Tentative Date of Exam: ";
echo $_SESSION['date_of_exam'];?> </td>
</tr>
<tr>
      <td><?php
echo "Class-In-Charge: ";
echo $_SESSION['class_in_charge'];?> </td>
</tr>
<tr>
      <td><?php
echo "Contact: ";
echo $_SESSION['contact'];?> </td>
</tr>
<tr>
      <td><?php
echo "Email: ";
echo $_SESSION['email'];?> </td>
</tr>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>NRIC no.</th>
<th>Age</th>
</tr>
<br>
<input type="submit" value="Add new Student" name="AddStudent">
</form>
<?php
$cnt = 0;
echo "<form enctype='multipart/form-data' action = 'final_check.php' method='post'>";
while ($cnt < $_SESSION['numberOfStudents']) {
   
   
    $NameCnt = "Name".$cnt;
    $NRICcnt = "NRICno".$cnt;
    $AgeCnt = "Age".$cnt;

    if (isset($_POST[$NameCnt])) {
?>
        <tr>
        <td><input type = 'text' name = 'student_name<?php echo $cnt ?>' value='<?php echo $_POST[$NameCnt] ?>'></td>
        <td><input type = 'text' name = 'nric<?php echo $cnt ?>' value='<?php echo $_POST[$NRICcnt] ?>'></td>
        <td><input type = 'text' name = 'age<?php echo $cnt ?>' value='<?php echo $_POST[$AgeCnt] ?>'></td>
        </tr>
<?php
    }
    else {
?>
        <tr>
        <td><input type = 'text' name = 'student_name<?php echo $cnt ?>'></td>
        <td><input type = 'text' name = 'nric<?php echo $cnt ?>'></td>
        <td><input type = 'text' name = 'age<?php echo $cnt ?>'></td>
        </tr>
<?php
    }

$cnt = $cnt +1;
}
?>

</table>
<br>
<br>
<tr>
            <td></td>
            <table style="text-align: left;"
            <td><input type = 'submit' value = 'Continue' name='FinalCheckBtn'></td>
           
        </tr>
    </table>
</form>
</html>

[Image: ashtearxf7.jpg]
06-28-2009 10:35 AM
Profile E-Mail PM Find Quote Report
NanaFreak
Scripting Contest Winner
*****


Posts: 1476
Reputation: 53
32 / Male / Flag
Joined: Jul 2006
RE: Need help in PHP
you would need to post the data to the page, and add it back in...

i hope you get that... i dont really feel like creating a page for that...

if you need more explanation just ask...
06-28-2009 10:41 AM
Profile PM Find Quote Report
Odin.EXE
Full Member
***

Avatar

Posts: 198
35 / Male / –
Joined: Jul 2003
O.P. RE: Need help in PHP
Hmm sorry to be honest it wasn't me working on this. It was more like my friend. So I have no idea what is it about. :(
[Image: ashtearxf7.jpg]
06-28-2009 10:48 AM
Profile E-Mail PM Find Quote Report
segosa
Community's Choice
*****


Posts: 1407
Reputation: 92
Joined: Feb 2003
RE: Need help in PHP
I think you need to read http://www.tizag.com/mysqlTutorial/mysql-php-sql-injection.php
The previous sentence is false. The following sentence is true.
06-29-2009 09:36 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On