SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Having trouble with function

    The code below is what I have on a page that is giving feedback to the sites administrator to see if people have a username and password, as we give them out after they have registered.

    PHP Code:
    <?

    $query  
    "SELECT * FROM Register Order by RegId desc";
    $result mysql_query($query);

    // Function to read if a client has a Username & Password 
    function myUserPass(){
    $queryPass "SELECT Username, Password, RegId FROM Register";
    $rapid mysql_query($queryPass);
    $rapid['Password'] = Horse;
        
    if (
    $rapid['Password'] == "Horse" ){
        echo 
    "2";
        echo 
    $rapid['Password'];
        } else {
        echo 
    "1";
        }
    }

    while(
    $row mysql_fetch_array($resultMYSQL_ASSOC))
    {

    // Query the database and get the count    
    $resultCount mysql_query("SELECT * FROM logdetails Where Log_Id={$row['RegId']}"); 
    $num_rows mysql_num_rows($resultCount);
    // End of query

    echo "<div style='position:relative; color:#000000; border-top:#666666 solid 1px; width:700px; height:257px'>".
    "<div style='position:relative; float:left; width:450px; height:257px; border-right:#666666 solid 1px;'><br>First Name: {$row['FirstName']} <br>" .
    "Last Name: {$row['LastName']} <br>" .
    "Company: {$row['Company']} <br>" .
    "Address: {$row['Address']} <br>" .
    "PostCode: {$row['PostCode']} <br>" .
    "Country: {$row['Country']} <br>" .
    "Email: <a href=mailto:{$row['Email']}]?subject=TourCheck>{$row['Email']} </a><br>" .
    "Tel: {$row['Tel']} <br>" 
    "Fax: {$row['Fax']} <br><br>".
    "Click <i><a href='#'>here</a></i> to view log in records. <span style='font-size:11px; color:#ff9000'>[$num_rows]</span><br><br>".
    "<i><a style='font-size:11px; color:#ff9000' href='logIn.php#topList'>Return To Top [^]</a></i><br><br></div>".
    "<div style='position:relative; width:249px; height:257px; float:right; background-color:#cccccc; font-size:12px;'><p style='padding-left:10px; padding-top:6px'>{$row['FirstName']} has logged in <span style='color:#ff0000;'>[$num_rows]</span> times.<br/><br/>Username: [<img width=11px src='../site_images/Tick.jpg' />] <br/><br/>Password: [ " myUserPass() . " ] </p></div></div>";

    ?>
    Where I'm having trouble is that last line calling a function which id does, but I'm not getting the result I wont.

    the myUserPass function is looking at the username pad password and then giving a 1 or 0 as to whether a password exists, but I cant get that bit working.

    I know there a lot there, but I thought it best to put the lot rather than picking it out.

  2. #2
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I deally what I would like is:

    PHP Code:
    function myUserPass(){
    $queryPass "SELECT Username, Password, RegId FROM Register";
    $rapid mysql_query($queryPass);
        
    if (
    $rapid['Password'] == "" ){
        echo 
    "2";
        echo 
    $rapid['Password'];
        } else {
        echo 
    "1";
        }


  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Okay. You've got a several issues here.
    1. Your function needs to know the RegId to look someone up. (Pass it as a parameter)
    2. Your query needs to look for that specific individual (WHERE clause)
    3. The line beginning "$rapid =" makes rapid a result set. Extract the row from the result set (mysql_fetch_row or mysql_fetch_array)
    3b. If it has no rows, you've got bigger problems, cause your script is feeding it bad RegId's.
    4. Once you've got the row extracted, you can check it for a password.
    4a. If it doesnt have one, you might want to insert one into the database (another query)
    5. Return the password instead of echo'ing it.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are only to show whether password exists for that user or not then 'ternary operator' will enough for you.
    Code php:
    $query  = "SELECT * FROM Register Order by RegId desc"; 
    $result = mysql_query($query) or die(mysql_error()); 
     
    while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
    { 
    	// Query the database and get the count     
    	$resultCount = mysql_query("SELECT * FROM logdetails Where Log_Id={$row['RegId']}");  
    	$num_rows = mysql_num_rows($resultCount); 
    	// End of query 
     
    	echo "<div style='position:relative; color:#000000; border-top:#666666 solid 1px; width:700px; height:257px'>". 
    	"<div style='position:relative; float:left; width:450px; height:257px; border-right:#666666 solid 1px;'><br>First Name: {$row['FirstName']} <br>" . 
    	"Last Name: {$row['LastName']} <br>" . 
    	"Company: {$row['Company']} <br>" . 
    	"Address: {$row['Address']} <br>" . 
    	"PostCode: {$row['PostCode']} <br>" . 
    	"Country: {$row['Country']} <br>" . 
    	"Email: <a href=mailto:{$row['Email']}]?subject=TourCheck>{$row['Email']} </a><br>" . 
    	"Tel: {$row['Tel']} <br>" .  
    	"Fax: {$row['Fax']} <br><br>". 
    	"Click <i><a href='#'>here</a></i> to view log in records. <span style='font-size:11px; color:#ff9000'>[$num_rows]</span><br><br>". 
    	"<i><a style='font-size:11px; color:#ff9000' href='logIn.php#topList'>Return To Top [^]</a></i><br><br></div>". 
    	"<div style='position:relative; width:249px; height:257px; float:right; background-color:#cccccc; font-size:12px;'><p style='padding-left:10px; padding-top:6px'>{$row['FirstName']} has logged in <span style='color:#ff0000;'>[$num_rows]</span> times.<br/><br/>Username: [<img width=11px src='../site_images/Tick.jpg' />] <br/><br/>Password: [ " . ((isset($row['Password']) && !empty($row['Password'])) ? $row['Password'] : 'No password exists') . " ] </p></div></div>"; 
    }

    See the following:
    PHP Code:
    ((isset($row['Password']) && !empty($row['Password'])) ? $row['Password'] : 'No password exists'
    You can change the returning value. I have echoed the password if it exists and simply 'No password exists' if not.

    Hope you understand what I mean!
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  5. #5
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK thank you guy, will have a look through your work and get back to you.

    I will say though having read the first reponse Im a little bit lost in the jargon, but will see if i can understand it

  6. #6
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    907
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WOW thats awsome, thank you very much guys, especially Raju as it worked perfectly...

    I can see where I was going wrong now too, so thank you again.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •