Hello all,
I have been teaching myself PHP through others writting; so bear with me if you find something foolish.

Having said so, I want to make a simple Music library with MySQL/PHP. I have made this very simple Login form as shown below. I want after someone successful login be redirected where he can populate things in Library. The he should be able to see it via another PHP file. Here are my Questions:
1. How do I redirect a page after successful login?
2. How do I make a dynamic table that I can alter its cells anytime? I mean when one adds his music the PHP file should print the table with cells full of all info.
3. Supplemently, can one recommend tutorial that can help me to achieve what I have said?

Thanks all :)

// This is login.php
<html>
	<head>
		<title> Login</title>
	</head>

	<body>
		<form action ="login.php" method = "post" >
			<p> User name 
			<input type = "text" name = "user" />
			</p>
			<p> Password  
			<input type = "password" name = "pass" />			
			<input type = "submit" value = "Go" />
			</p>
		</form>	
	<?php 
		$user = $_POST["user"];
		$pass = $_POST["pass"];
		if (($user=="elijah")&&($pass=="jesus" )) echo "Access provided, Enjoy $user !";
		else 	echo "Access denied, please $user contact your system Admin ";
	?>
	</body>

</html>

Here is the fill in form

//fill_in.php
<form action="/projects/LearningPHP/include/inc.get_results.php" method="post" >
	<p>Year:</p>
	<p><input type="text" name="album_year" /></p>
	
	<p>Album:</p>
	<p><input type="text" name="album_name" /></p>
	
	<p>Artist:</p>
	<p><input type="text" name="album_artist" /></p>
	
	<p>Owner:</p>
	<p><input type="text" name="album_owner" />
	
	<p><input type="submit" value="Send" />
	</p>
	
</form>

Here is the inc.get_result.php

//inc.get_result.php
<?php
$album_year = $_POST["album_year"];
$album_name = $_POST["album_name"];
$album_artist = $_POST["album_artist"];
$album_owner = $_POST["album_owner"];

foreach($_POST as $key=>$value){
 //print $key;
 // I have failed to display the data in table
}

?>

First of all you have to learn how to use session. On successfull login you should register a session variable that will tell other pages that the user is logged in. You could do it with the following code:

<?
if (($user=="elijah")&&($pass=="jesus" )) $_SESSION['logged_in']=1;
else $_SESSION['logged_in']=0;
?>

on every secure page before all the code starts you should always start the session and validate if user is still logged in:

<?
session_start();
if($_SESSION['logged_in']!=1 && $_SERVER['PHP_SELF']!='/login.php'){
header( 'Location: http://www.yoursite.com/login.php' ) ;
}
?>

then you have to decide how your users will store data. Will it be a mysql database? will it be a text file? its really up to you but when you decide it and manage to store that data, after retreiving it you could simply create a loop within your table to populate it with music:

<html>
<body>
<table>
<tr>
  <td>Title</td>
  </td>File Name</td>
</tr>
<? foreach($myMusicArray as $k=>$d){ ?>
<tr>
  <td><?=$d['title']?></td>
  <td><?=$d['filename']?></td>
</tr>
<? } //Foreach Loop ?>
</table>
</body>
</html>

This is just a simple example.. I hope you get the idea on how it supposed to work and expand on it... If you plan on learning php there are number of books that you could purchase that have simple tutorials. If you're a visual person you could sign up at lynda.com and watch tutorials on video. There are also alot of tutorials found on youtube.com. Good Luck.

Thanks sir, I will practice that!
Anyone who wants to add any valuable info in addition to this is welcomed too!
Thanks 3Magine

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.