I'm making a project to add information into database Mysql. Here is the deal we have to make 3 forms with sessions and provide a registration of and user by STEPS, and this sessions to keep the records and if I'm on step 2 I can roll back and edit something in step 1 or step 3. This should be done with sessions. I had make something and I want your help to advice me how can I continue. I will post my code to the moment.
I know the code is Lame, but I'm learning now. Thank you! This is the first step of my registration. How could I continue?
<?php
session_start();
// $_SESSION
$fname = '';
if (isset($_SESSION['user_fname']) && !empty($_SESSION['user_fname'])) {
$fname = $_SESSION['user_fname'];
}
$connection = mysql_connect("localhost","root","");
if (!$connection) {
die('Mysql Could not been established ' . mysql_error());
}
else{
$db_name = "phplab_course_project";
mysql_select_db($db_name, $connection);
if(isset($_POST['submit'])){
if($_POST['user_fname']!="" && $_POST['user_mname']!="" && $_POST['user_lname']!="" && $_POST['user_login']!="" && $_POST['user_email']!="" && $_POST['user_phone']!=""){
$sql = "insert into users(user_fname, user_mname, user_lname, user_login, user_email, user_phone )
values('".$_POST['user_fname']."', '".$_POST['user_mname']."', '".$_POST['user_lname']."', '".$_POST['user_login']."', '".$_POST['user_email']."', '".$_POST['user_phone']."');";
mysql_query($sql, $connection);
printf("The data is inserted id %d\n", mysql_insert_id());
}
}
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
Лични данни<br>
<br><td>Firstname*</td>
<td>
<input type="text" name="user_fname" value="<?php echo $fname;?>" required />
</td>
<td></td>
</tr>
<tr>
<td>Surname </td>
<td><input type="text" name="user_mname" /></td>
<td></td>
</tr>
<tr>
<td>Lastname* </td>
<td><input type="text" name="user_lname" required /></td>
<td></td>
</tr>
<tr>
<td>Username (login)* </td>
<td><input type="text" name="user_login" required /></td>
<td></td>
</tr>
<tr>
<td>Mail* </td>
<td><input type="text" name="user_email" required /></td>
<td></td>
</tr>
<tr>
<td>Phone </td>
<td><input type="text" name="user_phone" /></td>
<td></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name='submit' value="Save"/></td>
<td></td>
</tr>
</table>
</form>
</body>
</html>