Jump to content

PHP Problem


shlomk'e
 Share

Recommended Posts

hey im trying to program a pm model and i want people could send their msg to a number of people in one time so i use this:

<?phperror_reporting(E_ALL);if( isset( $_COOKIE['user'] ) ) { include("../config.php"); $title = $_POST['title']; $text = $_POST['text']; $name = $_COOKIE['user']; $date = date("d/m/y H:i"); $to = $_POST['to']; $a = 9999*9999; $b = 9999*9999*$a; $url = rand( $a, $b );if ($title == null || $title == "" || $text == "" || $text == null || $to == "" || $to == null) { header('Location: ../pm.php?act=send&error=gen'); exit;} else { $strings = split(" ",$to); $i = count( $strings );if ($i == 1) { $query = "SELECT username FROM members WHERE username='".$to."'"; $result = mysql_query($query);if (mysql_num_rows($result)>0) { mysql_query("INSERT INTO privatemsg (url, title, text, sendby, sendto, seen, date) VALUES ('$url', '$title', '$text', '$to', '$name', 'false', '$date')");} else { header('Location: ../pm.php?act=send&error=notexist'); exit;}} else { $c = 0;while ($c < $i) { $query = "SELECT username FROM members WHERE username='".$strings[$c]."'"; $result = mysql_query($query);if (mysql_num_rows($result)>0) { mysql_query("INSERT INTO privatemsg (url, title, text, sendby, sendto, seen, date) VALUES ('$url', '$title', '$text', '$strings[$c]', '$name', 'false', '$date')");} else { header('Location: ../pm.php?act=send&error=notexists'); exit;} $c++;}} header('Location: ../pm.php?send=true'); mysql_close($connect);} else {}?>
and it isnt working... someone can take a look?
Link to comment
Share on other sites

How about just describing the problem. Instead of saying "it's not working", say what it is and is not doing.Also, you need to escape the variables in your SQL statements. There might be a quote or something in one of the variables that would cause the query to fail. Use this function to sanitize everything in the query:http://www.php.net/manual/en/function.mysq...cape-string.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...