0

I am constructing a contact form and want the fields to pull in information from two different tables in the same mysql database. The first three fields display correctly but I am struggling to get the users details from the second table to display.

Here is the code I currently have.

<?php


$id =$_REQUEST['ID'];

$result = mysql_query("SELECT * FROM boomcat WHERE ID  = '$id'");
$test = mysql_fetch_array($result);
if (!$result) 
        {
        die("Error: Data not found..");
        }
                $image=$test['Image'] ;
                $id=$test['ID'] ;                   
                $name=$test['Name'] ;


?>  
<?php
$result = mysql_query("SELECT * FROM members WHERE member_id='".$_SESSION['SESS_MEMBER_ID'] ."'");
$test = mysql_fetch_array($result);
if (!$result)
{
    die("Error: Data not found..");
    }
    $first=$test['FirstName'] ;
    $email=$test['Email'] ;

  ?>


<table>


<form name="contactform" action="memcontact-process.php" method="post" onSubmit = "return contactcheck();">

<td><img class="img" width="100" height="100" src="../../<?php echo $image ?>"/></td>

        <td><input type="hidden" name="Image" value="<?php echo $image ?>" /></td>
    </tr>
            <tr>
        <td>ID:</td>
        <td><input type="text" style="border: 1px solid #aaa;" name="ID" value="<?php echo $id ?>" readonly="readonly"/> </td>
    </tr>
    <tr>
        <td>Item:</td>
        <td><input type="text" style="border: 1px solid #aaa;" name="Item" value="<?php echo $name ?>" readonly="readonly"/></td>
    </tr> 
        <td>Name:</td>
        <td><input type="text" style="border: 1px solid #aaa;" name="Name" value="<?php echo $first ?>" readonly="readonly"/></td>
    </tr>    
</table>



</body>
</html>


<?php
Andic
  • 13
  • 2
  • did you start the session? and is anything assigned to `$_SESSION['SESS_MEMBER_ID']`? check for errors everywhere. You're not doing that. – Funk Forty Niner Jan 14 '16 at 16:30
  • 1
    Please stop using MySQL. It is deprecated and gone as of PHP 7. Use MySQLi or PDO. – Chris G Jan 14 '16 at 16:31
  • there's also a stray ` – Funk Forty Niner Jan 14 '16 at 16:32
  • [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Jan 14 '16 at 16:36
  • Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jan 14 '16 at 16:36
  • Thank you for all your comments I will look in to moving away from mysql. – Andic Jan 15 '16 at 08:48

1 Answers1

0
<?php
$result2 = mysql_query("SELECT * FROM members WHERE member_id = '".$_SESSION['SESS_MEMBER_ID'] ."'");
$test2 = mysql_fetch_array($result2);
if (!$result2)
{
die("Error: Data not found..");
}
$first = $test2['FirstName'] ;
$email = $test2['Email'] ;

?>

Might be good to change the name of the second query to not match the first.

Try this!

Chris G
  • 787
  • 6
  • 20