Jump to content

mysql security


c_pattle

Recommended Posts

I have a form that when submitted inserts the input values into a database.  I was wondering what measures I can take to make sure that it is as secure a possible.  Below I have added some basic code.  Any help on how to modify this code to protect against injection attacks etc would be great. 

 


if(isset($_POST['form_submit'])) {

	$submit_sql = "insert into websites (website_name, website_description,website_url) values (\"" . $_POST['website_name'] . "\",\"" . $_POST['website_description'] . "\",\"" . $_POST['website_url'] . "\")";

	$submit_rs = mysql_query($submit_sql, $mysql_conn);
}

Link to comment
https://forums.phpfreaks.com/topic/216572-mysql-security/
Share on other sites

yes it's set to "ON" should I change it?

 

Also this is my code.  Is this the right way to do it?

 


if(isset($_POST['form_submit'])) {

$_SESSION[website_name'] = mysql_real_escape_string($_POST['website_name'], $mysql_conn);
$_SESSION['website_description'] = mysql_real_escape_string($_POST['website_description'], $mysql_conn);
$_SESSION['website_url'] = mysql_real_escape_string($_POST['website_url'], $mysql_conn);

$submit_sql = "insert into websites (website_name, website_description,website_url) values (\"" . $_SESSION['website_name'] . "\",\"" . $_SESSION['website_description'] . "\",\"" . $_SESSION['website_url'] . "\")";

$submit_rs = mysql_query($submit_sql, $mysql_conn);
}

Link to comment
https://forums.phpfreaks.com/topic/216572-mysql-security/#findComment-1125289
Share on other sites

magic_quotes_gpc should be turned off, yes. As a minimum, you should check for it in your code if you're writing a script that needs to be as portable as possible. That way, you don't end up double-escaping things. Have a look through the examples in the documentation for get_magic_quotes_gpc().

 

if( get_magic_quotes_gpc() ) {
     // run your GET/POST/COOKIE vars through stripslashes()
}

Link to comment
https://forums.phpfreaks.com/topic/216572-mysql-security/#findComment-1125294
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.