Im trying to call information from a database, the following code is inside a secure place when the members log in they should be able to see their own user details:

<?php
$hostname = "***********";
$username = "***********";
$password = "****";

if(!($link = mysql_connect("****", "****","****")))
 die("Could not connect to database.");
$databasename = "mdb_am663";
if(!(mysql_select_db($databasename,$link)))
  die("Could not open table.");


$member_id = $HTTP_GET_VARS['id'];
$strsql="SELECT email, firstname, surname, address_line1, ".
 "address_line2, city_county, postcode FROM ".
 "contacts WHERE id = '$member_id'";
if(!($rs= mysql_query($strsql, $link)))
  die("Could not open table."); <<<<<<<<<<<<<<---------------------------------
//only one row should be returned
$row = @ mysql_fetch_array($rs);



// now complete the form
echo "t<input type=\"hidden\" name=\"email\" value=\"$row[email]\"><br>\n";
echo "<input type=\"hidden\" name=\"first_name\" value=\"$row[firstname]\"><br>\n";
echo "<input type=\"hidden\" name=\"last_name\" value=\"$row[surname]\"><br>\n";
echo "<input type=\"hidden\" name=\"address1\" value = \"$row[address_line1]\"><br>\n";
echo "<input type=\"hidden\" name=\"address2\" value = \"$row[address_line2]\"><br>\n";
echo "<input type=\"hidden\" name=\"city\" value=\"$row[city_county]\"><br>\n";
echo "<input type=\"hidden\" name=\"state\" value=\"$row[postcode]\"><br>\n";
?>

where i have indicated with a "<<<<<<<<<<<<<<---------------------------------" this is where it sql ends for some reason telling me: Could not open table.

anybody have any ideas?

    Firstly change:

    $member_id = $HTTP_GET_VARS['id'];

    to:

    $member_id = $_GET['id'];

    since you were using some deprecated functionality of php. Anyway, please could you output the return value of mysql_error() before you call die() like so:

    if(!($rs= mysql_query($strsql, $link))){
        echo 'Mysql Error: '.mysql_error().'<br />';
        die("Could not open table.");
    }

    and then tell me what the output is.

      scross wrote:

      Firstly change:

      $member_id = $HTTP_GET_VARS['id'];

      to:

      $member_id = $_GET['id'];

      since you were using some deprecated functionality of php. Anyway, please could you output the return value of mysql_error() before you call die() like so:

      if(!($rs= mysql_query($strsql, $link))){
          echo 'Mysql Error: '.mysql_error().'<br />';
          die("Could not open table.");
      }

      and then tell me what the output is.

      i made the changes you told me to

      but it said: "Mysql Error: Unknown column 'id' in 'where clause'
      Could not open table."

      so i changed the "id" values to "member_id" and it gave me a blank white page.

      <?php
      $hostname = "********";
      $username = "********";
      $password = "********";
      
      if(!($link = mysql_connect("******", "*****","*****")))
       die("Could not connect to database.");
      $databasename = "mdb_am663";
      if(!(mysql_select_db($databasename,$link)))
        die("Could not open table.");
      
      
      $member_id = $_GET['member_id']; 
      $strsql="SELECT email, firstname, surname, address_line1, ".
       "address_line2, city_county, postcode FROM ".
       "contacts WHERE member_id = '$member_id'";
      if(!($rs= mysql_query($strsql, $link))){ 
          echo 'Mysql Error: '.mysql_error().'<br />'; 
          die("Could not open table."); 
      }
      //only one row should be returned
      $row = @ mysql_fetch_array($rs);
      
      
      // now complete the form
      echo "t<input type=\"hidden\" name=\"email\" value=\"$row[email]\"><br>\n";
      echo "<input type=\"hidden\" name=\"first_name\" value=\"$row[firstname]\"><br>\n";
      echo "<input type=\"hidden\" name=\"last_name\" value=\"$row[surname]\"><br>\n";
      echo "<input type=\"hidden\" name=\"address1\" value = \"$row[address_line1]\"><br>\n";
      echo "<input type=\"hidden\" name=\"address2\" value = \"$row[address_line2]\"><br>\n";
      echo "<input type=\"hidden\" name=\"city\" value=\"$row[city_county]\"><br>\n";
      echo "<input type=\"hidden\" name=\"state\" value=\"$row[postcode]\"><br>\n";
      ?>

        It gave you a blank page because that's what it's supposed to do 🙂
        All those input's aren't being displayed because their type is set to "hidden".
        And your code for the form should be this anyway:

        echo "t<input type=\"hidden\" name=\"email\" value=\"{$row['email']}\"><br>\n"; 
        echo "<input type=\"hidden\" name=\"first_name\" value=\"{$row['firstname']}\"><br>\n"; 
        echo "<input type=\"hidden\" name=\"last_name\" value=\"{$row['surname']}\"><br>\n"; 
        echo "<input type=\"hidden\" name=\"address1\" value = \"{$row['address_line1']}\"><br>\n"; 
        echo "<input type=\"hidden\" name=\"address2\" value = \"{$row['address_line2']}\"><br>\n"; 
        echo "<input type=\"hidden\" name=\"city\" value=\"{$row['city_county']}\"><br>\n"; 
        echo "<input type=\"hidden\" name=\"state\" value=\"{$row['postcode']}\"><br>\n";

        Now your values should be entered into the form correctly (read http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex )

          scross wrote:

          It gave you a blank page because that's what it's supposed to do 🙂
          All those input's aren't being displayed because their type is set to "hidden".
          And your code for the form should be this anyway:

          echo "t<input type=\"hidden\" name=\"email\" value=\"{$row['email']}\"><br>\n"; 
          echo "<input type=\"hidden\" name=\"first_name\" value=\"{$row['firstname']}\"><br>\n"; 
          echo "<input type=\"hidden\" name=\"last_name\" value=\"{$row['surname']}\"><br>\n"; 
          echo "<input type=\"hidden\" name=\"address1\" value = \"{$row['address_line1']}\"><br>\n"; 
          echo "<input type=\"hidden\" name=\"address2\" value = \"{$row['address_line2']}\"><br>\n"; 
          echo "<input type=\"hidden\" name=\"city\" value=\"{$row['city_county']}\"><br>\n"; 
          echo "<input type=\"hidden\" name=\"state\" value=\"{$row['postcode']}\"><br>\n";

          Now your values should be entered into the form correctly (read http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex )

          still blank page 🙁

            Yes, because, as I said, your page is full of inputs which have their type set to "hidden", so none of them are shown.

              scross wrote:

              Yes, because, as I said, your page is full of inputs which have their type set to "hidden", so none of them are shown.

              well vie tried

              echo $row['email']; also... no hope

                Ok, time to do some debugging...

                First add:

                error_reporting(E_ALL);

                at the top of your script (just after the opening php tag). Then remove the "@" off mysql_fetch_array like so:

                $row = mysql_fetch_array($rs);

                Then it would probably be wise, just after that line, to print out the value of $row using print_r like so:

                print_r($row);

                Ok, that should be enough. Please can you tell me the output now...

                  Write a Reply...