Alright so I am trying to basically take what's in $row['cardid'] and set it into the value of my div tag. Then on the html file this is echoing to, it would run my function which uses that value from the div tag. Right now when I use the onclick, it pulls up but says my value is undefined. So my question is why is my variable undefined when I pull it up using html?
<?php
$q=$_GET["q"];
$con = mysql_connect("*", "*", "*");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("*", $con);
$sql="SELECT cardset, cardname, cardnumber, cardid FROM cards WHERE cardname LIKE '%".$q."%' OR cardset LIKE '%".$q."%'";
$result = mysql_query($sql) or die ('Error: '.mysql_error ());
echo "<table border='1'>
<tr>
<th>#</th>
<th>Cardname</th>
<th>Card Set</th>
</tr>";
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['cardnumber'] . "</td>";
// This is the troubled line.
echo '<td><div value="'.$row['cardid'].'" onclick="changeimage(this.value)">' . $row['cardname'] . '</div></td>';
echo "<td>" . $row['cardid'] . "</td>";
echo "<td>" . $row['cardset'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.