Welcome! Log In Create A New Profile

Advanced

New prac thread

Posted by Mac 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
avatar
Mac
New prac thread
May 24, 2006 11:35AM
Let's start a new prac thread -t he other one's getting a bit long now!
Re: New prac thread
May 24, 2006 09:22PM
One more thing about the prac specification

on page 2 para 2Flow of information the statement number 5 about maintaining student data in the course_student table.
Well the only data there about the student is the sno, I see no reason why one would want to change this number. Given the normalised database, and the fact that the sno is an auto increment field and mainly that it is the primary key, I do not recommend any update of this field. I do see the need to delete from this table if one deletes the student or the course. (I had better check on this one).

Regarding the null(out of course scope and all), one more question, can mysql do what I want to do?
I do not want to spend hours on something which is not going to work anyway. I would rather work on php arrays to make the date selection in our project more user friendly. and then there is the session thing in 5c!!!!!!!

Re: New prac thread
May 25, 2006 11:42AM
Thanks for the advice Mac, but I still cannot get echo the $sno after inserting the student registration details. The data are going into the student table and the $sno is being generated. I just can't get it out again ...:

<?php
$title="Table Records";
include ("header.php"winking smiley;

$link_id=mysql_connect();
mysql_select_db("registration"winking smiley;

@extract($_POST);

if(isset($sno))

$sno=$_POST['sno'];

//define the query
$query="INSERT INTO student VALUES('', '$sname', '$init', '$fname', '$title', '$msname', '$dob', '$sex', '$lang', '$idno', '$telh', '$telw', '$cel', '$fax', '$email', '$address'winking smiley";




//executes the query
$results = mysql_query ($query);


?>
<table>
<?php
if (mysql_affected_rows() == 1) {
//if it updated

mysql_select_db("registration"winking smiley or die( "Unable to select database"winking smiley;
$result = mysql_query( "SELECT * from student WHERE sno='$sno'"winking smiley;


while($row = mysql_fetch_row($result));

{
$sno = $row[0];


echo "Your student number is: $sno";
}

?>
<table>
<tr>
<td>
Update Saved Successful

</td>
</tr>
<?php
} else {
//if it failed
?>
<tr>
<td>
Update Failed
</td>
</tr>

<?php
}
?>

<tr>
<td>
<form action="reg_students.php" method="post">
<input type="submit" name="submit" value="Ok" />
</form>
</td>
</tr>
</table>


<?php

mysql_close(); //Closes our SQL session

?>
Re: New prac thread
May 25, 2006 01:34PM
I am having a problem with the footer

I call the footer after closing the HTML ie
after </HTML>
<?php include("footer.php"winking smiley; ?>

in some files this works well, in other files the footer is included inside a table or the entire form is just blank

is it good practice to do as I have done?
if not then where should I call the footer?

why is this code influencing the html?

avatar
Mac
Re: New prac thread
May 25, 2006 06:25PM
Angus - you may want to delete a student who de-register, so you need to delete not only her details, but also update the student-course table. Maintain implies add/edit/delete - in this case probably just delete.
The footer problem I cannot comment on, since I don't know how it is called in your code. If it is included inside a table, then clearly you've positioned it wrongly in your code. Footer should always be the last line before the </body></html> HTML code.

Libby - I do not understand the logic in your code....and you're making it particularly difficult for me to correct you!!

You use

if(isset($sno)) //PLEASE USE BRACKETS. This is useless in any event since you generate the sno after this code!!!
$sno=$_POST['sno'];

//define the query
$query="INSERT INTO student VALUES('', '$sname', '$init', '$fname', '$title', '$msname', '$dob', '$sex', '$lang', '$idno', '$telh', '$telw', '$cel', '$fax', '$email', '$address'winking smiley";


You correctly generate the sno with the query here above, using an empty '' as the first field.

THEN you use this codeSELECT * from student WHERE sno='$sno'"winking smiley;


while($row = mysql_fetch_row($result));

{
$sno = $row[0];


???? You want to get the sno, using sno in your WHERE statement? It is not possible.

I suggest you use the exact code I posted and replace whatever you need to to make it relevant to your db and tables.


Re: New prac thread
May 25, 2006 11:29PM
This code seems to work ok at inserting into the student database and extracting the unique student number. Is there anything wrong with this approach? Seems almost too simple ... maybe I'm missing something

<?php

$link_id=mysql_connect();
mysql_select_db("registration"winking smiley;

@extract($_POST);


$sql = mysql_query("INSERT INTO student VALUES('', '$sname', '$init', '$fname', '$title', '$msname', '$dob', '$sex', '$lang', '$idno', '$telh', '$telw', '$cel', '$fax', '$email', '$address'winking smiley"winking smileyor die (mysql_error());

$sno = mysql_insert_id();

echo "Your student number is: $sno";

$results = mysql_query ($query);


?>
avatar
Mac
Re: New prac thread
May 26, 2006 08:04AM
The simpler the better. You insert the record, then do a query (you used the mysql_insert_id to get the id which is fine. There may be times when you need to extract something else than an id, in which case you will use a select query (like after an update, for example).

Here, most of what you may want to use is already in the $_POST. You may, for example, want to echo more than just the student id - perhaps a more friendly paragraph "Thank you $init $sname for your regsitration. We have captured the following details.......your student number is &sno. Please print a copy of this page....

Whatever. No need to extract this from the db since you already have it

Re: New prac thread
May 26, 2006 11:41AM
OK I include my code please note the correct position of teh footer call statement.

When I run this code in localhost. I get nothing on the screen exepting the header.
If I remove the footer line of code then I actually see all the input fields etc



<?php
$title = "Add a student";
include("header.php"winking smiley;
?>
<form method=post action='studentadd02.php'>
<html>
<head>
<script type="text/javascript"> <!-- //this code sets focus onto the input box--!>
function setfocus(formNum, elementNum) {
document.forms[formNum].elements[elementNum].focus();
}
</script>
<title>Add a student</title>
</head>
<body onLoad="setfocus(0,0)"> <!-- //this code sets focus onto the input box--!>
<b>Please Enter the New Student Details</b>
<br>
<br>
Student Surname:
<br>
<input name='sname' type='text' size='40' maxlength='40'>
<br>
Student Initials:
<br>
<input name='init' type='text' size='5' maxlength='5'>
<br>
Student First Name:
<br>
<input name='fname' type='text' size='40' maxlength='40'>
<br>
Student Title: &nbsp
<select name = title>
<option value = "Mr"> Mr</option>
<option value = "Miss"> Miss</option>
<option value = "Mrs"> Mrs</option>
<option value = "Prof"> Prof</option>
<option value = "Dr"> Dr</option>
<option value = "Me"> Me</option>
<option value = "Miss"> Miss</option>
<option value = "Adv">Adv</option>
</select>
<br>
<br>
Student Maden name:
<br>
<input name='msname' type='text'size='40'maxlength='40'>
<br>
Student Date of Birth (CCYYMMDD):
<br>
<input name='dob' type='text' size='8' maxlength='8'>
<br>
Student Gender (M/F): &nbsp
<select name = sex>
<option value = "M"> Male</option>
<option value = "F"> Female</option>
</select>
<br>
<br>
Student First Language:
<br>
<input name='lang' type='text' size='10' maxlength='10'>
<br>
Student Identity Number:
<br>
<input name='idno' type='text' size='13' maxlength='13'>
<br>
Student Home Tel Number (011 1234567):
<br>
<input name='telh' type='text' size='12' maxlength='12'>
<br>
Student Work Tel Number (011 1234567):
<br>
<input name='telw' type='text'size='12' maxlength='12'>
<br>
Student Cell Number (083 1234567):
<br>
<input name='cel' type='text' size='12' maxlength='12'>
<br>
Student Fax Number (011 1234567):
<br>
<input name='fax' type='text' size='12' maxlength='12'>
<br>
Student e-mail Address:
<br>
<input name='email' type='text' size='40' maxlength='40'>
<br>
Student Address (PO Box 1234 Pretoria 0001):
<br>
<input name='address' type='text'size='90'>
<br>
<br>
<input type='submit'value ='Submit New Student'>
<br>
</form>
<?php include("footer.php"winking smiley;?>
</body>
</html>

avatar
Mac
Re: New prac thread
May 26, 2006 11:49AM
But what is in footer.php?

If you include footer and the page is blank, then most likely you have a typing error in footer.php, since typo's stop the page from showing.
Re: New prac thread
May 26, 2006 12:23PM
footer is as follows



<!--NAVIGATION FOOTER-->
<br>
<br>
<br>
<br>
<hr>
<a href="index.php">Return to Home Page</a> | <a href="studentadd.php">Enrol as a Student for the First Time</a> | <a href="studentfind.php">Register for Courses</a>
</body>
</html>
Sorry, you do not have permission to post/reply in this forum.