Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

desperate cry for help (1st question)

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

desperate cry for help (1st question)

Postby mcookie82 » 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;
----------------------------------------------------
|customerid|username|password|name|address|phone|
-----------------------------------------------------
|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
   require_once("timbmet_function.php");
   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;
         session_register("valid_user");
      } // End of if
      else
      {
         // Unsuccessful login
         do_html_header("Problem");
         echo "You could not be logged in.
               You must be logged in to view this page.";
         do_html_url("login.php", "Login");
         do_html_footer();
         exit;
      } // 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
<?

   require_once("timbmet_function.php");   
   
   // get html header   
   $customer = get_customer_details($username);
   do_html_header($customer["name"]);
   display_customer_details($customer);
   
   // get html footer
   do_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>";
        }
        else
          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).
mcookie82
New php-forum User
New php-forum User
 
Posts: 9
Joined: Thu Mar 20, 2003 7:14 am

Postby gcm2 » Sun Apr 20, 2003 11:26 am

Hi - I'm fairly new to PHP. This is my only novice observation about your posted code.

The message you're getting is when the is_array($customer)
fails
.

I tried some of this code, but I'm not using MySQL as a database (yet) - I'm using Access thru ODBC, and I couldn't really duplicate this problem.

Also, I can't get $customer["name"] to work - it wants a numerical index, not a string. Must be different with MySQL.

I'm probably not much help. But I will try to be helpful on this forum in the future. 8O
gcm2
New php-forum User
New php-forum User
 
Posts: 4
Joined: Sat Apr 19, 2003 6:33 pm
Location: Ft Worth, TX

Postby storm » Fri Apr 25, 2003 1:57 am

First of all, try changing your:
Code: Select all
@mysql_fetch_array()


to:

Code: Select all
@mysql_fetch_assoc()


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>";
print_r($returndata);
echo "\n</pre>";


This will display the actual results of your function so you know what's going on.
storm
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Apr 24, 2003 5:18 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Google Feedfetcher and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.