Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating and inserting data into a PHP and MySQL Database
#10
Im quite surprised (in a worried way that is), that no one else has picked up on the first code block problem:

(03-13-2011, 05:08 PM)Peter L Wrote:
PHP Code:
$con mysql_connect('$dbhost''$dbuser''$dbpass'); 

So as shown in the code above, you are no longer taking the variables as what they stand for. Your treating them as literals because you have used single quotes around them, meaning that variables are no longer parsed.

Also i disagree with you ★Cooldude★ because you are using two clashing functions:
(01-14-2012, 04:46 PM)★Cooldude★ Wrote: Really?

PHP Code:
function sanitise($input){
return 
htmlentities(strip_tags(mysql_real_escape_string($input)));


strip_tags do exactly what their called, they strip the opening and closing tags (including the text inside of them), from the users input. However you're using htmlspecialchars over that again. This is rather pointless because you have already stripped the tags, and now you are trying to convert them?
I would keep it to just escaping the users data into the database (with the likes of mysql_real_escape_string, or addslashes), and then upon output of data from the database, i would use the function htmlspecialchars (to prevent XSS attacks). The reason being is that you may forget to use htmlspecialchars upon user input, which would leave you vulnerable upon output of data from your database because you have trusted all of the data inside your database (dont ever do that).
Reply


Messages In This Thread
RE: Creating and inserting data into a PHP and MySQL Database - by Haxalot - 03-24-2012, 10:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  database problem danjohnson 0 1,174 11-13-2012, 10:56 PM
Last Post: danjohnson
  vb6.0 + mysql Anurag.91 1 1,668 09-08-2012, 04:19 PM
Last Post: spesificrelax
  Database accessing in .NET MikeHenery9 1 1,458 07-14-2012, 06:37 PM
Last Post: 'Snorlax
  VB.NET MySql , Help please booterphhp 2 1,706 03-19-2012, 11:13 AM
Last Post: RainbowDashFTW
  [TUT] Include mySQL into php. MyNameIs940 48 23,147 01-14-2012, 04:45 PM
Last Post: Strafeness

Forum Jump:


Users browsing this thread: 1 Guest(s)