I have a table called "bookmarks" with 2 fields (name and url). I also have another table called "category" with 4 fields (opensource, other, web2.0 and php).
When I add data to the bookmarks table how to I associate it with one of the tables? Below is my code.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Bookmarks</title>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
<table align="center" border="0" cellpadding="0"
cellspacing="1" width="300">
<tbody>
<tr>
<td>
<form name="form1" method="post"
action="insert.php">
<table border="0" cellpadding="3"
cellspacing="1" width="100%">
<tbody>
<tr>
<td width="71"><font
style="font-size: 1.5em;">Name</font></td>
<td width="6">:</td>
<td width="301"><input name="name"
id="name" size="35" style="font-size: 1.5em;"
type="text"></td>
</tr>
<tr>
<td><font style="font-size: 1.5em;">URL</font></td>
<td>:</td>
<td><input name="url" id="url"
size="35" value="http://" style="font-size: 1.5em;"
type="text"></td>
</tr>
<tr>
<td colspan="3" align="center"><input
name="Submit" value="Submit" type="submit"></td>
</tr>
</tbody>
</table>
</form>
</td>
</tr>
</tbody>
</table>
<?php
$host="host"; // Host name
$username="user"; // Mysql username
$password="pass"; // Mysql password
$db_name="db"; // Database name
$tbl_name="bookmarks"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="500" border="0" cellspacing="2" cellpadding="0" align="center">
<tr>
<td><form name="form1" method="post" action="">
<table width="500" border="1" cellpadding="2" cellspacing="0" bgcolor="#CCCCCC" align="center">
<tr>
<td bgcolor="#FFFFFF" width="30"><font face='verdana'><font size='2'><strong>Delete</strong></td>
<td bgcolor="#FFFFFF" width="10"><font face='verdana'><font size='2'><strong>Id</strong></td>
<td bgcolor="#FFFFFF"><font face='verdana'><font size='2'><strong>URL</strong></td>
<td bgcolor="#FFFFFF" width="50"><font face='verdana'><font size='2'><strong>Category</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF" width="30"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF" width="10"><font face='verdana'><font size='1'><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><font face='verdana'><font size='1'><a target="_blank" href="<?php echo $rows['url']; ?>"><?php echo $rows['name']; ?></a>
<td bgcolor="#FFFFFF" width="50"><font face='verdana'><font size='1'><? echo $rows['id']; ?></td>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=index.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>