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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.