Jump to content

stripslashes help.


herghost

Recommended Posts

Hi all,

 

How do you  use strip slashes to allow a field with ' or / for example, I currently have the below, but if a hypen etc appears then the query fails.

 

Many Thanks

 

<?php


include('../include/dbconnect.php');
include('../include/auth.inc.php');
$redirect =  ('../index.php');
$query = 'SELECT user_id, username FROM users_credits WHERE username = "' . mysql_real_escape_string($_SESSION['username'], $conn) . '"';  
      
$result = mysql_query($query, $conn) or die(mysql_error($conn));

$row = mysql_fetch_array($result);
extract($row);
mysql_free_result($result);


// get data that sent from form
$cat=$_POST['cat'];
$os=stripslashes($_POST['os']);
$ram=stripslashes($_POST['ram']);
$graphics=stripslashes($_POST['graphics']);
$harddrive=stripslashes($_POST['harddrive']);
$detail=stripslashes($_POST['detail']);
$title=stripslashes($_POST['title']);

$datetime=date("d/m/y h:i:s"); //create date time

$query="INSERT INTO forum_question (id, user_id, cat, os, ram, graphics, harddrive, title, detail, username, datetime)

VALUES('', '$user_id', '$cat', '$os', '$ram', '$graphics', '$harddrive', '$title', '$detail', '$username', '$datetime')";
mysql_query($query) or die('Error, insert query failed');

$post_no = mysql_insert_id();
?>

Link to comment
https://forums.phpfreaks.com/topic/175348-stripslashes-help/
Share on other sites

Thanks Mr Adam,

 

I have added this to my database connect file, should do the trick!

 

//This stops SQL Injection in POST vars
  foreach ($_POST as $key => $value) {
    $_POST[$key] = mysql_real_escape_string($value);
  }

  //This stops SQL Injection in GET vars
  foreach ($_GET as $key => $value) {
    $_GET[$key] = mysql_real_escape_string($value);
  } 

Link to comment
https://forums.phpfreaks.com/topic/175348-stripslashes-help/#findComment-924140
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.