OK, I have posted a simular question in other post I had but it didn't match my topic and wasn't very detailed. I would like some help with the following:
I have a web site (my first PHP one) that I designed for myself to allow me to catalog my DVD and Video Game collection. I can update records in case someone borrows a disc or I trade it in. I have set up a user signup area as well as a login in/out.
I used two tutorials to help me make it this far:
Login Tutorial
Adding and Editing Database Data
I am wondering what it would take to all other people to sign up and catalog their dvd's and games. I mean, I already have the sign up form working and a table in my database for users. But how do I take my PHP scripts and make them so they know which users data to display (so my movies are shown in someone elses collection).
I have two tables in my database which are as follows:
TABLE users
id
username
password
email
city
state
TABLE discs
discid
title
system
rating
discs (how many per movie/game)
loaned
My PHP for the data display page is as such:
<?php
require('/home/public_html/db_connect.php');
// require our database connection
// which also contains the check_login.php
// script. We have $logged_in for use.
if($logged_in == 0) {
header("Location: /dvd_view.php");
}
// show content
$db_object->disconnect();
// when you are done.
?>
<?php include("/home/public_html/header.php"); ?>
<table width="725" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><img src="/images/title_dvd.gif" width="725" height="50"></td>
</tr>
<tr>
<td>
<table width="725" border="0" cellspacing="1" cellpadding="2" bgcolor="#000000">
<tr bgcolor="#333333">
<td width="334"><b>GAME TITLE</b></td>
<td width="75">
<div align="center"><b>RATING</b></div>
</td>
<td width="95">
<div align="center"><b># OF DISCS</b></div>
</td>
<td width="115">
<div align="center"><b>BORROWED</b></div>
</td>
<td width="80">
<div align="center"><b>DELETE</b></div>
</td>
</table>
<table width="725" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<?php
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("database_name",$db);
if ($submit) {
// here if no ID then adding else we're editing
if ($discid) {
$sql = "UPDATE discs SET system='$system',title='$title',rating='$rating',discs='$discs',loaned='$loaned' WHERE discid=$discid";
} else {
$sql = "INSERT INTO discs (system,title,rating,discs,loaned) VALUES ('$system','$title','$rating','$discs','$loaned')";
}
// run SQL against the DB
$result = mysql_query($sql);
echo "Record updated/edited!<p>";
} elseif ($delete) {
// delete a record
$sql = "DELETE FROM discs WHERE discid=$discid";
$result = mysql_query($sql);
echo "$sql Record deleted!<p>";
} else {
// this part happens if we don't press submit
if (!$discid) {
// print the list if there is not editing
// $result = mysql_query("SELECT * FROM discs",$db);
$result = mysql_query("SELECT discid, title, rating, discs, loaned FROM discs WHERE system = 'DVD' ORDER BY title",$db);
while ($myrow = mysql_fetch_array($result)) {
echo "<table width=725 border=0 cellspacing=1 cellpadding=2 bgcolor=#000000>";
echo "<tr bgcolor=#222222>";
echo "<td width=334><a href=\"{$_SERVER['PHP_SELF']}?discid={$myrow['discid']}\">{$myrow['title']}</td>";
echo "<td width=75><div align=center>{$myrow['rating']}</div></td>";
echo "<td width=95><div align=center>{$myrow['discs']}</div></td>";
echo "<td width=115><div align=center>{$myrow['loaned']}</div></td>";
echo "<td width=80>";
printf("<div align=center><a href=\"%s?discid=%s&delete=yes\">DELETE</a></div>", $PHP_SELF, $myrow["discid"]);
echo "</td>";
echo "</tr>";
echo "</table>";
}
}
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<?php
if ($discid) {
// editing so select a record
$sql = "SELECT * FROM discs WHERE discid=$discid";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$discid = $myrow["discid"];
$system = $myrow["system"];
$title = $myrow["title"];
$rating = $myrow["rating"];
$discs = $myrow["discs"];
$loaned = $myrow["loaned"];
// print the discid for editing
?>
<input type=hidden name="discid" value="<?php echo $discid ?>">
<?php
}
?>
<br><br>
<table width="327" border="0" cellspacing="0" cellpadding="0" align="center" bgcolor="BDBDBD">
<tr>
<td><img src="/images/spacer.gif" width="327" height="1"></td>
</tr>
<tr>
<td>
<table width="325" border="0" cellspacing="0" cellpadding="2" align="center" bgcolor="343434">
<tr>
<td width="125">System:</td>
<td width="200">
<input type="Text" name="system" value="DVD">
</td>
</tr>
<tr>
<td width="125">Title:</td>
<td width="200">
<input type="Text" name="title" value="<?php echo $title ?>">
</td>
</tr>
<tr>
<td width="125"> Disc Rating:</td>
<td width="200">
<input type="Text" name="rating" value="<?php echo $rating ?>">
</td>
</tr>
<tr>
<td width="125"># Of Discs:</td>
<td width="200">
<input type="Text" name="discs" value="<?php echo $discs ?>">
</td>
</tr>
<tr>
<td width="125">On Loan:</td>
<td width="200">
<input type="Text" name="loaned" value="<?php echo $loaned ?>">
</td>
</tr>
<tr>
<td width="125"> </td>
<td width="200"> </td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="Submit" name="submit" value="Enter information">
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="/images/spacer.gif" width="327" height="1"></td>
</tr>
</table>
</form>
<?php
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php include("/home/public_html/footer.php"); ?>
If you want to help me out and need any other information from me, please let me know! Thanks in advance!