Author Topic: Tractor Pulling Database  (Read 991 times)

0 Members and 1 Guest are viewing this topic.

Offline FarmgirlTopic starter

  • Irregular
  • Posts: 14
  • Gender: Female
    • View Profile
    • Torque Reaction
Tractor Pulling Database
« on: September 23, 2009, 04:49:28 PM »
I've just finished a little project which I started in order to help me understand PHP & MySQL better. It's been a steep learning curve, but I feel now that I have grasped the basics. So with this in mind, please feel free to comment on my efforts.

T.P.Org.Uk - Tractor Pulling Database

Simply mad about tractors...

Offline Adam

  • Guru
  • Fanatic
  • *
  • Posts: 4,702
  • Gender: Male
    • View Profile
Re: Tractor Pulling Database
« Reply #1 on: September 24, 2009, 08:50:44 AM »
Do you mean to critique the functionality (better suited to the BETA test forums) or the look of it?
Ronnie Wood, true or false?

Offline neil.johnson

  • Guru
  • Fanatic
  • *
  • Posts: 3,416
  • Gender: Male
    • View Profile
Re: Tractor Pulling Database
« Reply #2 on: September 24, 2009, 08:59:26 AM »
Be sure to santitize the input to any form before using in code. Put the following into your search field and see what happens (won't do any damage):
Code: [Select]
// put this into your search box
<script language="javascript">alert('xss attack');</script>
« Last Edit: September 24, 2009, 08:59:59 AM by neil.johnson »
Quote
To start, press any key. Where's the 'Any' key?

Offline FarmgirlTopic starter

  • Irregular
  • Posts: 14
  • Gender: Female
    • View Profile
    • Torque Reaction
Re: Tractor Pulling Database
« Reply #3 on: September 24, 2009, 04:00:12 PM »
Be sure to santitize the input to any form before using in code. Put the following into your search field and see what happens (won't do any damage):
Code: [Select]
// put this into your search box
<script language="javascript">alert('xss attack');</script>

Thanks for your input Neil, but how do I 'sanitize' the input?  It's not an area I am familiar with.  If you could point me in the right direction, I would be most grateful.

Simply mad about tractors...

Offline neil.johnson

  • Guru
  • Fanatic
  • *
  • Posts: 3,416
  • Gender: Male
    • View Profile
Re: Tractor Pulling Database
« Reply #4 on: September 24, 2009, 04:09:51 PM »
Data from a form post or url parameters is held in the $_POST or $_GET array (in the case of a form decided by the form method <form method="post>)
You should clean this data prior to placing in any function or database query. Some simple functions:

Code: [Select]
<?php
// data from form is in post array
$searchString $_POST['searchterm'];
// check that the value is not balnk
if(strlen(trim($searchString))) {
 
// remove any injected html
 
$searchString strip_tags(trim($searchString));
 
// perform search query and escape variable
 
$result mysql_query("SELECT * FROM tablename WHERE x LIKE '".mysql_real_escape_string($searchString)."%'");
 print 
"Your search for: ".$searchString." returned ".mysql_num_rows($searchString)." results"
}
else {
 print 
"Please enter a valid search term";
}
?>

Quote
To start, press any key. Where's the 'Any' key?

Offline FarmgirlTopic starter

  • Irregular
  • Posts: 14
  • Gender: Female
    • View Profile
    • Torque Reaction
Re: Tractor Pulling Database
« Reply #5 on: September 24, 2009, 04:26:08 PM »
Thank for that! I'll try it out. :)

Cheers
Simply mad about tractors...

Offline FarmgirlTopic starter

  • Irregular
  • Posts: 14
  • Gender: Female
    • View Profile
    • Torque Reaction
Re: Tractor Pulling Database
« Reply #6 on: October 04, 2009, 07:17:56 PM »
Well I think I've FIXED the problems...at least I HOPE I have!   :examine:
Simply mad about tractors...