Please help Its urgent.....

Taking a variable from the login form and using it in another form and store the same variable in the database table, and retrieve the same values when that person logs in.
For example if there are two users - user1 and user2
when user1 log in only the values entered by user1 should be visible to him.
when user2 log in only the values entered by user1 should be visible to him.

My source code would be

Table source code -

CREATE TABLE IF NOT EXISTS books (
BookID int(11) NOT NULL AUTO_INCREMENT,
Title varchar(150) NOT NULL,
Author varchar(150) NOT NULL,
PublisherName varchar(150) NOT NULL,
CopyrightYear year(4) NOT NULL,
PRIMARY KEY (BookID)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;


– Dumping data for table books

INSERT INTO books (BookID, Title, Author, PublisherName, CopyrightYear) VALUES
(1, ‘Algebra’, ‘Almel’, ‘Chun Sa’, 2007),
(2, ‘Algebra’, ‘Almel’, ‘Chun Sa’, 2007),
(3, ‘Algebra’, ‘Almel’, ‘Chun Sa’, 2007),
(4, ‘Algebra’, ‘Almel’, ‘Chun Sa’, 2007),
(5, ‘Algebra’, ‘Almel’, ‘Chun Sa’, 2007),
(6, ‘Algebra’, ‘Almel’, ‘Chun Sa’, 2007),
(7, ‘Algebra’, ‘Almel’, ‘Chun Sa’, 2007),
(8, ‘Algebra’, ‘Almel’, ‘Chun Sa’, 2007);

Database Connection code-

<?php $conn = mysql_connect('localhost', 'root', ''); if (!$conn) { die('Could not connect: ' . mysql_error()); } mysql_select_db("adddel", $conn); ?>

Delete Source Code -

<?php include("db.php"); $id =$_REQUEST['BookID']; // sending query mysql_query("DELETE FROM books WHERE BookID = '$id'") or die(mysql_error()); header("Location: index.php"); ?>

My index page Source code -

Books
<tr>
	<td>Title:</td>
	<td><input type="text" name="title" /></td>
</tr>
<tr>
	<td>Author</td>
	<td><input type="text" name="author" /></td>
</tr>
<tr>
	<td>Publisher Name</td>
	<td><input type="text" name="name" /></td>
</tr>
<tr>
	<td>Copyright Year</td>
	<td><input type="text" name="copy" /></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><input type="submit" name="submit" value="add" /></td>
</tr>
<?php if (isset($_POST['submit'])) { include 'db.php';
		 		$title=$_POST['title'] ;
				$author= $_POST['author'] ;					
				$name=$_POST['name'] ;
				$copy=$_POST['copy'] ;
											
	 mysql_query("INSERT INTO `books`(Title,Author,PublisherName,CopyrightYear) 
	 VALUES ('$title','$author','$name','$copy')"); 
			
			
        }

?>

		<?php
		include("db.php");
		
			
		$result=mysql_query("SELECT * FROM books");
		
		while($test = mysql_fetch_array($result))
		{
			$id = $test['BookID'];	
			echo "<tr align='center'>";	
			echo"<td><font color='black'>" .$test['BookID']."</font></td>";
			echo"<td><font color='black'>" .$test['Title']."</font></td>";
			echo"<td><font color='black'>". $test['Author']. "</font></td>";
			echo"<td><font color='black'>". $test['PublisherName']. "</font></td>";
			echo"<td><font color='black'>". $test['CopyrightYear']. "</font></td>";	
			echo"<td> <a href ='view.php?BookID=$id'>Edit</a>";
			echo"<td> <a href ='del.php?BookID=$id'><center>Delete</center></a>";
								
			echo "</tr>";
		}
		mysql_close($conn);
		?>

Page View Source code

<?php require("db.php"); $id =$_REQUEST['BookID']; $result = mysql_query("SELECT * FROM books WHERE BookID = '$id'"); $test = mysql_fetch_array($result); if (!$result) { die("Error: Data not found.."); } $Title=$test['Title'] ; $Author= $test['Author'] ; $PublisherName=$test['PublisherName'] ; $CopyrightYear=$test['CopyrightYear'] ; if(isset($_POST['save'])) { $title_save = $_POST['title']; $author_save = $_POST['author']; $name_save = $_POST['name']; $copy_save = $_POST['copy']; mysql_query("UPDATE books SET Title ='$title_save', Author ='$author_save', PublisherName ='$name_save',CopyrightYear ='$copy_save' WHERE BookID = '$id'") or die(mysql_error()); echo "Saved!"; header("Location: index.php"); } mysql_close($conn); ?> Untitled Document
Title:
Author
Publisher Name
Copyright Year
 

Can anyone help me by creating a simple login page and adding the value of that person who is logged on into the books table for which ever record he creates. Please not multiple user would access the same database at the same time…

Can anyone please help me…

You need to add another table to store the users along with a unique user_id. You also need to add a user_id column to your books table. Then when you query the books data use a WHERE user_id=‘logged_in_user_id_number’

Sponsor our Newsletter | Privacy Policy | Terms of Service