Jump to content

[SOLVED] whats the correct syntax for adding an "addslashes()" to sql INSERT


RyanSF07

Recommended Posts

Hi All,

 

Apparently adding addslashes() and stripslashes() dirrectly to the code is better than turning on magic quotes in php.ini file. I'm new at this, and learning, but that seems to be what I've gathered so far.

 

So, i'm looking at different turtorials and trying different things without success.

 

This is the bare bones of what I'm working with:

 

$sql = "INSERT INTO $table (user_id, video_id, question) VALUES ('$_SESSION[id]', '$_SESSION[video_id]', addslashes('$question'))";

 

In one tutorial, the addslashes was included as:

"'.addslashes($question).'",

, but that didn't work either.

 

What is the correct syntax for adding the "addslashes()" and "stripslashes" commands to INSERT and SELECT queries?

 

Thank you very much for you help :)

Ryan

How are you getting the $question variable? If it's the same as others (by sessions), do this:

$question = $_SESSION[question];
$question = addslashes($question);

 

...and for your query:

$sql = "INSERT INTO $table (user_id, video_id, question) VALUES ('$_SESSION[id]', '$_SESSION[video_id]', '$question')";

I do it like this....may not be perfect but it works well......

 


$whatever = $_POST['whatever'];
$whatever = addslashes($whatever);

$news = $_POST['news'];
$news = addslashes($news);



$query = "INSERT INTO table_name (whatever,news) VALUES ('$whatever','$news')";
mysql_query($query);

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.