what's wrong with my script? Please help


#1

Anyone please help me… im trying to create a script where you input email address then it will show the corresponding userid.

What happen to my script is that only the last email address shows the userid.

[code]

<?php $text = trim($_POST['test']); //explode all separate lines into an array $textAr = explode("\n", $text); //trim all lines contained in the array. $textAr = array_filter($textAr, "trim"); //loop through the lines foreach ($textAr as $line) { echo "Line " . $line . "
"; $uid = mysql_query("SELECT uid FROM dr_users where mail LIKE '{$line}' ") or die(mysql_error()); $num_rows = mysql_num_rows($uid); while ($row = mysql_fetch_assoc($uid)) { echo $num_rows; echo "UID: " . $row['uid'] . "
"; } } [/code]

#2

The script has already run whether you hit submit or not. should be
[php]

<?php if($isset($_POST['submit'])) { $text = trim($_POST['test']); //trim all lines contained in the array $textAr = explode("\n", $text);//explode all separate lines into an array $textAr = array_filter($textAr, "trim");//loop through the lines $uid = array(); foreach ($textAr as $line){ echo "Line " . $line . "
"; $uid = mysql_query("SELECT uid FROM dr_users WHERE mail LIKE %'$line'% ") or die(mysql_error()); $num_rows = mysql_num_rows($uid); while ($row = mysql_fetch_assoc($uid)) { echo $num_rows; $uid[] = "UID: " . $row['uid'] . "
"; } } } ?> Please list each email on a new line Good luck

#3

richei

thanks for your reply. I triend your code and it says

Notice: Undefined variable: uid in C:\wamp\www\test\box.php on line 31 Call Stack #TimeMemoryFunctionLocation 10.0017375472{main}( )…\box.php:0 ?>

line 31 is this for($i = 0; $i < count($uid); $i++) {

Please help me…

Thanks,


#4

Never seen that time error, but try changing the query to

$srch="%".$line."%";
$uid = mysql_query(“SELECT uid FROM dr_users WHERE mail LIKE ‘{$srch}’”) or die(mysql_error());

change $uid to

$uid .= "UID: " . $row[‘uid’] . “
”;

change <?phpfor($i = 0; $i < count($uid); $i++) { echo $uid[$i]; // display the results}?>

to

<?php echo $uid; ?>

#5

thanks for your help i already fix my problem :slight_smile:


#6

i mean i already fix it :slight_smile: