Forum Moderators: open
if(isset($_POST['submit'])) {
$name = mysql_real_escape_string($_POST[name]);
$query = "SELECT * FROM groups WHERE group_name='$name'";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
$import = mysql_query("INSERT INTO groups (ip, group_name, group_atr, group_info) VALUES ('$ip', '$_POST[name]', '$_POST[atributes]', '$_POST[group_info]')");
print '<div align="left">Successfully added</div>';
} else
$import = mysql_query("INSERT INTO groups (ip, group_name, group_atr, group_info) VALUES ('$ip', '$_POST[name]', '$_POST[atributes]', '$_POST[group_info]')");
print '<div align="left">Successfully updated</div>';
}
}
$name = mysql_real_escape_string($_POST[name])
This line should be
$name = mysql_real_escape_string($_POST['name'])
Note the single quotes around 'name'
You would also need to do the same with your insert query
$import = mysql_query("INSERT INTO groups (ip, group_name, group_atr, group_info) VALUES ('$ip', '$_POST[name]', '$_POST[atributes]', '$_POST[group_info]')");
print '<div align="left">Successfully added</div>';
But I guess you tried that and got errors due to mis-matching of single quotes.
Try this instead:
***************************
if(isset($_POST['submit'])) {
$name = mysql_real_escape_string($_POST['name']);
$atributes = mysql_real_escape_string($_POST['attributes']);
$group_info = mysql_real_escape_string($_POST['group_info']);
$query = "SELECT * FROM groups WHERE group_name='$name'";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
$import = mysql_query("INSERT INTO groups (ip, group_name, group_atr, group_info) VALUES ('$ip', '$name', '$atributes', '$group_info')");
print '<div align="left">Successfully added</div>';
} else
$import = mysql_query("INSERT INTO groups (ip, group_name, group_atr, group_info) VALUES ('$ip', '$name', '$atributes', '$group_info')");
print '<div align="left">Successfully updated</div>';
}
}
***************************
To be more secure you should FILTER_SANITIZE_STRING as this will block more harmful stuff which someone may try to compromise your system.