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
JwV
Prac problems
May 28, 2008 09:15AM
Hi all

Hope somebody can help. During testing of the prac I created a course PC's maintance. so far no problem. then it happened. I did the following query where cname is equal to PC's maintance:

$query = "SELECT cid FROM course where cname= '$cname'";
$result_query = mysql_query($query);

Thought it work. But it did not. when I looked at the value of $query it showed the following : SELECT cid FROM course where cname= 'PC' and not SELECT cid FROM course where cname= 'PC's maintance'

Also found that a course name with a & in it gives problems. I guess there could be other chars that also give problems.

Please help anyone.
JwV
Re: Prac problems
May 28, 2008 10:04AM
Hi all

Me again. Did some editing to get make the display on some screens nicer and found that the PC's problem somehow solved it self. Still have a problem with the & char in a course name.

When I display $cname it sometimes displays PC\'s and at other times PC's. What would cause this.
Re: Prac problems
May 28, 2008 10:14AM
Hi Guys,

I am a lil confuse from the project side, it says main page will be 4 that i can understand but do we have to make pages like login page where the user or admin has to login for the further action??

Please Help...
avatar
Mac
Re: Prac problems
May 28, 2008 12:01PM
when you save to a db and there is an ' in the string like "it's", then there is a problem because " and ' in PHP used together create problems (simply stated). So php requires a slash in front of the ' to "escape" it, as it is known.

Google for addslashes

Login is not part of the project. You can add it of you want.
Re: Prac problems
May 29, 2008 09:10AM
Hi there.

Jwv I entered the same course to my university lol smile but i didn get any errors because i use the cid instead of cname. When i used the cname on a test page i got an error as well because of that character.

I tried this on my webserver and it worked as follows.

Ok say example im posting $_POST['']; or using a $_REQUEST['']; in my page.

<?php
$str = $_REQUEST['course'];

function checkaddslashes($str){
$str2 = str_replace("\'", "*****", $str);
if(strpos($str2,"'"winking smiley!== false)
return str_replace('*****', "\'", addslashes($str2));
else
return $str;
}
//I USED THIS TO VIEW WHAT THE VALUE OF $STR IS FOR TESTING
echo $str;


$query = "SELECT * FROM course WHERE cname='$str' ";

When i echo it it displays PC's Maintainance (with the back slash) & result in sql returns PC's Maintainance

That works so try it and let me know. First time i also used a function as this.
smile

Enjoy.
Re: Prac problems
May 30, 2008 11:40AM
Hi All,

Im having problems with my page refresh after deleting or updating a record.
when the user clicks back button, the old data still sits there...
only when you do a manual refresh (f5) does it update...
I've tried different approaches to solving this problem, from cookies to sessions, no luck.
currently im using html to auto refresh the page every 5 seconds or so
<META HTTP-EQUIV="refresh" CONTENT="5">
problem with this is that its very annoying... and the page keeps reload after 5 seconds

Can sum1 please suggest a more effective way to refresh...
Thanks
Re: Prac problems
May 30, 2008 11:49AM
Hi.

Howsit?

Since this isnt part of the prac i will give you my code smile. You browser is caching the page and the refresh is only refreshing the page, you need the browser to revisit the server and perform your queries etc again.

Add this to the top of the pages.

<?php
header("Cache-Control: no-cache, must-revalidate"winking smiley; // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"winking smiley; // Date in the past
?>

It works 100%.

Enjoy smile
avatar
Mac
Re: Prac problems
May 30, 2008 12:00PM
Well, ajax does this quite brilliantly (but not part of this course sad smiley

Not sure how you have constructed your pages, but typically you would update something, then provide a message of the success of the update, and <a href links where the use can click to take them back to a previous (or other pages). This forces a reload of the page.

if($iseet($update=='yes'winking smiley){

sql update query.....

echo "Updated! <a href=thispage.php>Go back</a>";
}
else
{
update form
}
JwV
Re: Prac problems
June 02, 2008 04:18PM
Hi all


ernistus >>> With a delete you can take the user baback to a cenral location. With a student update i recall the display page to reload the students info.

MuhammadA >>> Hi there, hope you are well. Thanks for the help. I found that where I was passing the data through HTMLspecialchars I did not seem to have the problem. I wonder if it treats the single quote in the same manner as addslashes.

Mac >>> Is it possible that we could download all the pracs in one large zip file after everyone has been marked so that we can see how the other students saw the prac.

Also Mac, could you recomend a good php forum that one could join after the course.

Good luck to all of you.
avatar
Mac
Re: Prac problems
June 03, 2008 06:44AM
Yes, I can send you all the files if everyone agrees. Plenty - they're all good. Just google for php forums.
Re: Prac problems
June 03, 2008 07:53AM
Hi..

Yeah that will be great to see other students assignments. Can see what we could have added to ours and other methods that could have been used.

smile
JwV
Re: Prac problems
June 04, 2008 02:29PM
Hi there

Have no problem sharing mine. Have found that in PHP there are many ways to something. So would like to see how others did it.

Hope the rest of you all feel the same.
Sorry, only registered users may post in this forum.

Click here to login