hang-up in my Code
as title : php hang-up with my code
can please tell me why Or What is the problem
here is my code
<?php
$group = $_GET['group'] ;
$email = $_GET['email'] ;
include("../includes/config.php") ;
if($group != '')
{
$query = mysql_query(" SELECT email FROM users WHERE `group`='$group' ") ;
$emails = '' ;
while($res = mysql_num_rows($query))
{
$emails .= $res[0] ;
}
}
$emails .= $email ;
echo $emails ; die();
?>
Before While loop
i 开发者_开发问答tried to check my query and its ok
after loop
There is no answer from the server
i'm using php 5.2.6
To avoid SQL injections you should replace
$group = $_GET['group'] ;
for
$group = mysql_real_escape_string($_GET['group']) ;
Then, you have to execute the query and then iterate over the resultset, not what you are doing which is iterate over the amount of rows in the result (which is constant for each resultset and always evaluates to true, creating an infinite loop)
$res = mysql_query($query);
while ($row = mysql_fetch_row($res)) {
$email .= $row[0];
}
Try using mysql_fetch_array
instead of mysql_num_rows
in your loop.
You typically would want to use mysql_fetch_array
instead of the mysql_num_rows
since the latter one returns number of rows and not the result.
精彩评论