<?php
session_start();
if(isset($_SESSION['is_user_logged_in']))
{
$x=mysql_connect("localhost","root","");
$y=mysql_select_db("online_book_shop",$x);
$n=$_SESSION['id'];
echo "<html>
<body background=modern-background-design.jpg>
<div align=center>
<h1 style=text-align:center;font-family:fantasy;color:red;font-size:36px> COMPLETE BOOK
DATABASE</h1></br>";
$z=mysql_query("select * from books order by serial asc");
echo"</br><br/><br/><br/><table border = 4 bgcolor=white align=center>";
echo"<tr> <td> Serial number</td> <td> Name </td> <td> Price </td> <td> Quantity remaining</td>
<td> Purchase</td> <td> Add to cart </td> <td> Add to wishlist </td> </tr> ";
while($r=mysql_fetch_array($z))
{
echo"<tr>";
echo"<td>";
echo $r[0];
echo "</td>";
echo "<td>";
echo $r[1];
echo"</td>";
echo "<td>";
echo $r[2];
echo "</td>";
echo"<td>";
echo $r[3];
echo"</td>";
echo"<td>";
echo "<html> <form name=\"f1\" method=\"post\" action=\"purchase.php\"><p align=\"center\" ><input
type=\"submit\" value=\"P u r c h a s e \" name=\"b1\" style=
\"height:25px;width:100px;color:#C35617;font-family:impact\" /></p></form> </html>";
echo"</td>";
echo"<td>";
echo "<html> <form name=\"f1\" method=\"post\" action=\"purchase.php\"><p align=\"center\" ><input
type=\"submit\" value=\"A d d to C a r t \" name=\"b2\" style=
\"height:25px;width:100px;color:#C35617;font-family:impact\" /></p></form> </html>";
echo"</td>";
echo"<td>";
echo "<html> <form name=\"f1\" method=\"post\" action=\"purchase.php\"><p align=\"center\" ><input
type=\"submit\" value=\" W i s h L i s t \" name=\"b3\" style=
\"height:25px;width:100px;color:#C35617;font-family:impact\" /></p></form> </html>";
echo"</td>";
echo"</tr>";
}
echo"</table>";
if ($_POST)
{
$x=mysql_connect("localhost","root","");
$y=mysql_select_db("ONLINE_BOOK_SHOP",$x);
if ($_POST['b1'])
{
$z1=mysql_query("update user set Purchase ='$r[1]' where id=$n");
echo "<br/>";
}
if ($_POST['b2'])
{
$z2=mysql_query("update user set Cart='$r[1]' where id=$n");
echo "<br/>";
}
if ($_POST['b3'])
{
$z3=mysql_query("update user set Wishlist='$r[1]' where id=$n");
echo "<br/>";
}
}
echo "<h3 style=text-align:center><a href=mainpage.php style=color: #43C6DB; text-decoration:
none;target=_blank> <br/><br/><br/>Return to the main page </a> </h3>";
echo "<br/><br/><br/><br/>";
}
?>
Basically I'm trying to update the "purchase", "cart" and "wishlist" columns in the "user" table in the "online_book_shop" database on the click of a button next to the book (depending on which button is clicked). The page loads but the functionality of the buttons is not working.