desperate cry for help (1st question)

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 9
Joined: Thu Mar 20, 2003 7:14 am

Sun Apr 13, 2003 7:53 am

me again (sigh)

in my desperate attempts to try and do this damn php site, i have yet again come across another problem (which is pribably another one of those problems that ould be easily solved with one line of code).

Anyway here i go.

If u have looked at my previous posts you would know that i always seem to have trouble with the site that i have o make (im getting better, but not quick enough).

Ive gone though my book from cover to cover, and i find the odd bit of code, but it never ever works for me, im sure im doing something wrong. Anyway what im trying to do is to basically show the customer details on a page all by itself, so that the customer can view (and maybe edit, but that seems a long way off yet).

i have the table, that looks like;
|1 | travisp | 123dsds |travis|here | 01234|

etc....U get the idea.

Anyway i have the code for the members page;

Code: Select all

   // Include function files for this page
   session_start(); // Start a session for this user
   if ($userid && $password) // They have just tried to log in
      if (login($userid, $password))
         // If they are in the database register the userid
         $valid_user = $username;
      } // End of if
         // Unsuccessful login
         echo "You could not be logged in.
               You must be logged in to view this page.";
         do_html_url("login.php", "Login");
      } // End of else
   } // End of if
   do_html_header("Members Page"); // Display header for members page
   check_valid_user(); // Use method from user_function to check user
   display_user_menu(); // Display menu of options for user
   do_html_footer(); // Display footer for members page

Basically this is the first page u'll c once u log in. In the display_user_menu() function at the bottom, there will be a link for the customer info page, which at the moment has the code;

Code: Select all


   // get html header   
   $customer = get_customer_details($username);
   // get html footer


where get_customer_details() and display_customer_details() have the following codes, respectfully

Code: Select all

   function get_customer_details($username)

         $conn = db_connect();
         $query = "select * from customers where username='$username'";
         $result = @mysql_query($query);
            if (!$result)
           return false;
         $result = @mysql_fetch_array($result);
            return $result;
   function display_customer_details($customer)
        // display all details about this customer
        if (is_array($customer))
          echo "<table><tr>";
          echo "<td><ul>";
          echo "<li><b>Name:</b> ";
          echo $customer["name"];
          echo "<li><b>Phone:</b> ";
          echo $customer["phone"];
          echo "<li><b>Postcode:</b> ";
          echo $customer["postcode"];
            echo "</ul></td></tr></table>";
          echo "The details of this customer cannot be displayed at this time.";
           echo "<hr>";

Ive only done a few customer details like phone and name just to test them out. Anyway, all i get is the bit at the bottom that says The details of this customer ..... at this time.

Obviously ive done something wrong along the way. Is there someother method that would be infinately easier to carry out. There has to be asim pretty much pulling out my hair at the moment as i know this should be simple, but ive tried alot of other ways and well they all failed. PLEASE, PLEASE, PLEASE help me.

markie :lol:

(ps, if u can solve this for me could u please consider going to the next post, i dont think that one is as hard, but ive been pulling my air out about that one aswell).

New php-forum User
New php-forum User
Posts: 6
Joined: Thu Apr 24, 2003 5:18 pm

Fri Apr 25, 2003 1:57 am

First of all, try changing your:

Code: Select all



Code: Select all


That will force an associative array. Second, make sure your $customer array is being loaded properly by the function. To do this, at the end of each function, before you call return, use the code:

Code: Select all

echo "\n<pre>";
echo "\n</pre>";

This will display the actual results of your function so you know what's going on.

Post Reply