I extremely new to both mysql and php (mostly mysql), and i'm not even sure i got all of the basics, cause i'm more of a learning-by-doing-person. So my code is made up of different explanations all around the web, and some of it might be wrong. So i'm trying to get data from a database, put it into a html form, edit it, and update the database with the new data. So far the data gets loaded into the form correctly, and with a lot of troubleshooting i've come to the conclusion that even the upload works out as it should, except the fields are empty. So i guess that my problem must be in getting the data from the form, to the update query.
This is my code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<?php
require 'connect.php';
$result = $db->query("SELECT * FROM test") or die ($db->error);
while($row = mysqli_fetch_array($result))
{
$name = $row['name'];
$school = $row['school'];
$email = $row['email'];
$grade = $row['grade'];
$workshop = $row['workshop'];
$id = $row['id'];
?>
<form method="post" action="#">
<?=$id?>
<input name="nameid" type="text" value="<?=$name?>">
<input name="emailid" type="text" value="<?=$email?>">
<input name="gradeid" type="text" value="<?=$grade?>">
<input name="workshopid" type="text" value="<?=$workshop?>">
<input name="schoolid" type="text" value="<?=$school?>">
<?php }
session_start();
$_SESSION['storage'] = $_POST;
?>
<input name="update" type="submit" id="update" value="Update">
</form>
<?php
if(isset($_POST['update']))
{
$link = mysqli_connect("localhost", "892847", "123456789", "892847");
// Check connection
if($link === false){
die("Couldn't connect. " . mysqli_connect_error());
}
session_start();
$name = $_SESSION['storage']['nameid'];
$school = $_SESSION['school']['schoolid'];
$email = $_SESSION['email']['emailid'];
$grade = $_SESSION['grade']['gradeid'];
$workshop = $_SESSION['workshop']['grade'];
$id = $_SESSION['id'];
$sql = "UPDATE test SET name = '$name', email = '$email', school = '$school', grade = '$grade', workshop = '$workshop' WHERE id = '8'";
if(mysqli_query($link, $sql)){
echo "Records added successfully. $name";
print_r($_POST['nameid']);
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
}
?>
</body>
</html>
I'm aware that the session-chaos looks strange, but i read somewhere that a information isn't available across PHP-scripts, unless you make a session.
I'm really grateful for any kind of help - i've been fighting with this for about 48 hours