UziLok Posted November 24, 2008 Share Posted November 24, 2008 hello, well as you can see here: got my function, function readUsers($fname, $uname, $email, $phone) { $sql = sprintf(" SELECT * FROM `crud_` WHERE `id` = '%s'", mysql_real_escape_string($id)); $res = @mysql_query($sql) or die(mysql_error()); if ($res) { $output = ''; while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $output .= "First Name :{$row['fname']} <br>" . "username :{$row['uname']} <br>" . "email : :{$row['email']} <br>" . "phone :{$row['phone']} <br>"; } return $output; }else{ return false; } } and then to output it in a page called showusers i have like this <?php include "crud_functions.php"; connect($conn); selectDB($conn, $dbname); //list users $listUsers = readUsers($fname, $uname, $email, $phone); echo $listUsers; ?> and the problem is that showusers turns blank.. so i need some help to understand why, might have missed something in the code as i tend to code fast when i am on a roll Thank you for the help in advance! ??? Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/ Share on other sites More sharing options...
htzone Posted November 24, 2008 Share Posted November 24, 2008 What is this line doing? mysql_real_escape_string($id)); It also has an extra ending parenthesis. Also, why does your function require variables that don't get used ($fname, $uname, $email, $phone)? Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-697428 Share on other sites More sharing options...
UziLok Posted November 24, 2008 Author Share Posted November 24, 2008 it's the ending of the one up () and i think you know what mysql_real_escape_string is Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-697431 Share on other sites More sharing options...
htzone Posted November 24, 2008 Share Posted November 24, 2008 I know what it is, but where is $id coming from? Dumb mistake about the parenthesis on my part. Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-697437 Share on other sites More sharing options...
UziLok Posted November 24, 2008 Author Share Posted November 24, 2008 and why is that ? id coming from db... Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-697440 Share on other sites More sharing options...
UziLok Posted November 25, 2008 Author Share Posted November 25, 2008 code update!. function readUsers($id) { $sql = sprintf("SELECT * FROM `crud_` WHERE `id` = %d", (int)$id); $res = @mysql_query($sql) or die(mysql_error()); if ($res) { $output = ''; while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) { $output .= "First Name :{$row['fname']} <br>" . "username :{$row['uname']} <br>" . "email : :{$row['email']} <br>" . "phone :{$row['phone']} <br>"; } return $output; }else{ return false; } } Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-698468 Share on other sites More sharing options...
waynew Posted November 25, 2008 Share Posted November 25, 2008 And whats the result of this code? Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-698472 Share on other sites More sharing options...
UziLok Posted November 25, 2008 Author Share Posted November 25, 2008 still the same.. blank page ??? Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-698490 Share on other sites More sharing options...
UziLok Posted November 25, 2008 Author Share Posted November 25, 2008 when i do $listUsers = readUsers(1); instead of $id i get back a row, but as suspected only one. :S on var dump, i get string(0); when run on $id Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-698494 Share on other sites More sharing options...
waynew Posted November 25, 2008 Share Posted November 25, 2008 Debug it with output by placing echo statements inside your conditional (IF, ELSE IF etc) statements. Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-698501 Share on other sites More sharing options...
UziLok Posted November 25, 2008 Author Share Posted November 25, 2008 i get string string(102) outside from any (IF, ELSE IF etc) maybe take out the the where id part and just use like that ? .. Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-698515 Share on other sites More sharing options...
UziLok Posted November 25, 2008 Author Share Posted November 25, 2008 <solved><solved> Link to comment https://forums.phpfreaks.com/topic/133982-solved-small-function-problem-assistance-would-be-great/#findComment-698543 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.