Welcome! Log In Create A New Profile

Advanced

Testing

Posted by wsbraun 
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
Testing
April 23, 2011 07:22PM
Greetings everyone

I am almost at the point where I can start writing the data mining section, but I need data.

Could I prevail on those who have time to browse the below site. Look around, play a bit.

http://nynaeve.tworivers.homelinux.com:8888/~trinity/StudentRegistration/

It is connected to email systems so please do use valid email addresses.

I am more than willing to give pointers and or code samples if there is a feature you would like to take inspiration from.

Regards
Bill Braun

--

Student Number: 7298-786-3
avatar Re: Testing
April 24, 2011 07:36PM
Will do,

Will also upload mine this evening for testing (hopefully).

Stefan
avatar Re: Testing
April 24, 2011 08:16PM
Doesnt seem to be working ...
avatar Re: Testing
April 25, 2011 04:52PM
avatar Re: Testing
April 27, 2011 12:18AM
@ Stefan

Checked yours out. Only looked through it briefly but seems perfectly fine to me. My email isn't working at the moment though so I couldn't check if it sends emails successfully. I totally forgot bout this so just throwing it out there in case it might help you, I read in the tut letter that 20% of our mark also goes for added functionality that requires a change in the database structure: "I give marks for added functionality that will require a change in the database structure, but which you do not need to code. Add a text file highlighting these added functionalities... " So yeah just in a reminder in case you forgot.

Will let you know if I get the email, although in any case you're handing it in tomorrow haha. But yeah from what I saw it seemed all good, all the best & good luck.thumbs up
avatar Re: Testing
April 27, 2011 01:20AM
Hey Johnny,

Thanks for the heads up but luckily I did spot that. Wrote a bit down. Hope it gives me a few extra marks. Have sent it off to Mac!

Good luck and thanks smiling smiley

Stefan
avatar Re: Testing
May 01, 2011 09:28PM
Here's mine, still going to add a "conformation page" when deleting stuff

http://www.spargweb.co.za/

Criticism welcome smiling smiley

A word to the wise ain't necessary - it's the stupid ones that need the advice.
Student Number:72793775
avatar Re: Testing
May 01, 2011 11:22PM
@ shaun

Checked it out and played around a bit. Seems to be fine as far as I'm concerned. Also I successfully received the emails. Haven't found any problems with deleting and editing. 1 minor thing I found though is just check you're "cancel" button when selecting edit. Keeps me on the same page think you just set the wrong link. Otherwise, job well done I rate smiling smiley
avatar Re: Testing
May 01, 2011 11:49PM
Also if you don't mind could you or someone take a look at this code of mine? I'm going to change the input1, input2 etc. names once it's working. This is for editing a student, and I am having some difficulty with it. Been putting it off for a while but have to start fixing it though I'm struggling. Doesn't want to display the previously entered info instead the fields are blank and I'm getting these errors:

Notice: Undefined index: sno in C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php on line 27

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php on line 29

And once I enter new info and submit it I get :
Notice: Undefined index: input8 in C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php on line 128
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
Notice: Undefined index: sno in C:\Program Files\EasyPHP-5.3.' at line 19

Here is my code:
Language: PHP
if (!isset($_POST[';submit';])) { $q = "SELECT * FROM student WHERE ID = $_GET[sno]"; $result = mysql_query($q); $person = mysql_fetch_array($result); }   ?>   <h1> You are editing a student </h1> <form action="<?php echo $_SERVER[';PHP_SELF';]; ?>" method="post">         <p>Course name:</p> <select name="input1"> <?php $q = "SELECT cname FROM course "; $result = mysql_query($q); WHILE ($course = mysql_fetch_array($result)) { echo "<OPTION>{$course[';cname';]}</option>"; } echo " </SELECT>" ?> <br>   <p>Surname:</p> <INPUT TYPE = "text" name = "input2"value= " <?php echo $person[';sname';]; ?>" /> <br> <p>Initials:</p> <INPUT TYPE = "text" name="input3"value="<?php echo $person[';init';]; ?>" /> <br> <p>Full First Name:</p> <INPUT TYPE = "text" name="input4"value="<?php echo $person[';fname';]; ?>" /> <br> <p>Title:</p> <INPUT TYPE = "text" name="input5"value="<?php echo $person[';title';]; ?>" /> <br> <p>Maiden or previous surname:</p> <INPUT TYPE = "text" name="input6"value="<?php echo $person[';msname';]; ?>" /> <br> <p>Date of Birth:</p> <INPUT TYPE = "text" name="input7"value="<?php echo $person[';dob';]; ?>" /> <br>   <p>Gender:</p> Male <input type="radio" name="input8" value="m" /> Female <input type="radio" name="input8" value="f" /><br/>   <br> <p>Language</p> <select name="input9"> <option >English</option> <option >Afrikaans</option> </select>   <br> <p>Identity Number:</p> <INPUT TYPE = "text" name="input10"value="<?php echo $person[';id';]; ?>" /> <br> <p>Home Telephone Code + Number:</p> <INPUT TYPE = "text" name="input11"value="<?php echo $person[';telh';]; ?>" /> <br> <p>Work Telephone Code + Number:</p> <INPUT TYPE = "text" name="input12"value="<?php echo $person[';telw';]; ?>" /> <br> <p>Cell Phone Number:</p> <INPUT TYPE = "text" name="input13"value="<?php echo $person[';cel';]; ?>" /> <br> <p>Fax Code + Number:</p> <INPUT TYPE = "text" name="input14"value="<?php echo $person[';fax';]; ?>" /> <br> <p>E-mail Address:</p> <INPUT TYPE = "text" name="input15"value="<?php echo $person[';email';]; ?>" /> <br> <p>Postal Address of student:</p> <textarea name="input16" COLS=50 ROWS=5 value="<?php echo $person[';address';]; ?>" /> </textarea> <br>     <input type= "hidden" name="sno" value="<?php echo $_GET[';sno';]; ?>" /> <INPUT TYPE = "Submit" name="submit" VALUE = "Update"/> </form>   <?php   if(isset($_POST[';submit';])) {           $u = "UPDATE student SET `cname` = ';$_POST[input1]';, `sname` = ';$_POST[input2]';, `init` = ';$_POST[input3]';, `fname` = ';$_POST[input4]';, `title` = ';$_POST[input5]';, `msname` = ';$_POST[input6]';, `dob` = ';$_POST[input7]';, `sex` = ';$_POST[input8]';, `lang` = ';$_POST[input9]';, `idno` =';$_POST[input10]';, `telh` = ';$_POST[input11]';, `telw` = ';$_POST[input12]';, `cel` = ';$_POST[input13]';, `fax` = ';$_POST[input14]';, `email` = ';$_POST[input15]';, `address` = ';$_POST[input16]';   WHERE ID = $_POST[sno]"; mysql_query($u) or die(mysql_error());   echo "User has been modified!"; header("Location: index.php");   } ?>

Also the text fields get all messed up when I submit new info they all display something like this in their fields
"br /> <b>Notice</b>: Undefined variable: person in <b>C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php</b> on line <b>60</b><br />"

I'm going to try and work on this again tomorrow. Any help would be appreciated smiling smiley
Re: Testing
May 02, 2011 08:52AM
@Johnny

the reason you are getting an undefined $person is because you have not defined it when the page first runs. This section is supposed to define the person but only does so on the second round, When someone clicks the submit button.
This is also where you are getting the mysql sno error, or could be at least. It helps me sometimes to take a step back and read the code like a story, and then check if the story makes sense.
Language: PHP
// Here you are checking if the user submitted via the POST method with a submit field. // It should probably be if ( !isset($_GET[';sno';]) ) if (!isset($_POST[';submit';])) { // And yet here you are checking for a sno field out of the GET method. $q = "SELECT * FROM student WHERE ID = $_GET[sno]"; // I would also change the previous line to // $q = "SELECT * FROM student WHERE sno = ". $_GET[';sno';; $result = mysql_query($q); $person = mysql_fetch_array($result); // For a bit of completeness you can also put the entire form here so that it is only displayed/processed when needed }

With the textarea there is no value attribute defined. To fill in a value use this method
Language: PHP
<textarea name="input16" COLS=50 ROWS=5 /><?php echo $person[';address';]; ?> </textarea>

When you create your update query, The $_POST array needs to be accessed with its string index
Language: PHP
`cname` = ';$_POST[';input1';]';,

The input8 error message could be due to the fact that input8 is a radio group. if neither is selected then it will not be put into the $_POST array. So put in
Language: PHP
isset($_POST[';input8';) ? $_POST[';input8';] : ';NA';
This will put in a NA if there was no answer to the question.

--

Student Number: 7298-786-3
avatar Re: Testing
May 02, 2011 01:11PM
Thanks wsbraun

Made the following changes that you recommended:
if (!isset($_POST['submit'])
$q = "SELECT * FROM student WHERE ID = $_GET[sno]";

Still getting this error:
Notice: Undefined index: sno in C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php on line 27

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php on line 29

When I change my update set from e.g `fax` = '$_POST[input14]', to `fax` = '$_POST['input14']', I get the following error:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\EasyPHP-5.3.3\www\Project\editstudent.php on line 121

Would my previous student_man.php page where the students are shown and you choose to edit them effect this in any way? Just checking if maybe the problem is in that section of coding?
avatar Re: Testing
May 02, 2011 01:36PM
oh and the error revolving around line 27 and 29 are these lines.

Language: PHP
if (!isset($_POST[';sno';])) //25 { //26 $q = "SELECT * FROM student WHERE sno = " . $_GET[';sno';]; //27 $result = mysql_query($q); //28 $person = mysql_fetch_array($result); //29 } //30
Re: Testing
May 02, 2011 02:08PM
try echo the update query and see what it is sending to the database.

you may need to use the mysql_real_escape_string to escape any dangerous user inputs.

I use this on every input coming in from the browser.
Language: PHP
function sanitize($data) { if (is_array($data)) { $retVal = array(); foreach ($data as $value) { $retVal[] = sanitize($value); } return $retVal; } // remove whitespaces (not a must though) $data = trim($data); // apply stripslashes if magic_quotes_gpc is enabled if(get_magic_quotes_gpc()) { $data = stripslashes($data); } // a mySQL connection is required before using this function $data = mysql_real_escape_string($data); return $data; }

--

Student Number: 7298-786-3
avatar Re: Testing
May 02, 2011 02:28PM
Well found the first mistake.. was ridiculous to be honest haha I made in error on my previous student_man.php page so $_GET['sno'] remained undefined. The ?sno=value link was incorrect so it never got that data. Bleh. Haha but still not quite done yet now for submitting it. Will see what progress I can make and come back to you if I'm stuck. Thanks for the help so far smiling smiley
Re: Testing
May 12, 2011 02:07PM
Sorry, only registered users may post in this forum.

Click here to login