Jump to content

inserting information into a mysql database *FIXED*


sk1tL1L

Recommended Posts

i'm creating a message system, and it keeps echoing "error" so i don't know what the prblem is!
[code]<?php
include ("config.php");
$to=$_POST['username'];
$message=$_POST['message'];

// Insert data into mysql
$sql="INSERT INTO messages(to, from, message)VALUES('$to', '$member', '$message')";
$result=mysql_query($sql);

if($result){
echo "The PM has been sent to $to!";
}

else {
echo "ERROR";
}

// close connection
mysql_close();
?>[/code]
[size=10pt][b][color=red]FIXED[/color][/b][/size]
Link to comment
Share on other sites

Your server may automatically addslashes everything... but just to be safe you probably want to do it in your script.  Someone could put
[code=php:0]
');  DELETE FROM `messages`;
[/code]
or other things and it would execute it in the sql query...

[code=php:0]
foreach($_POST as $k => $v) {
$_POST[$k] = addslashes($v);
}
is what i normally use....
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.