I've a problem with my admin web page, wicth doesn't work when i need to do an user's update. That is my main page, where the page should show user's details on selection form:
<?php
if(isset($_POST['submit']))
{
session_start();
$data = $_SESSION['data'];
unset($_GET['data']);
header("location: modify.php");
}
?>
<html>
<head>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form action="" method="post">
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<?php
require_once('../conf.php');
$query_list = "SELECT * FROM studentinfo ORDER BY(id) DESC";
$result_list = mysql_query($query_list) or die('error in query_list');
// $n=1;
while($row = mysql_fetch_array($result_list))
{
?>
<option value="<?php echo $row[0]; ?>"><?php echo $row[2]; ?></option>
<?php
// $n=$n+1;
}
?>
</select>
<input type="submit" name="submit"/>
</form>
<br>
<div id="txtHint">
<b>listed here...</b>
</div>
</body>
</html>
there is my getuser.php page:
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
require_once('../conf.php');
session_start();
$q = intval($_GET['q']);
$getuser="SELECT *
FROM studentinfo
WHERE id = '".$q."'";
$result = mysql_query($getuser) or die('error in getuser');
echo "<table>";
?>
<tr>
<th>Id</th>
<th>Mac</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Department</th>
<th>City</th>
<th>State</th>
</tr>
<?php
if($row = mysql_fetch_array($result)) {
$_SESSION['data'] = $row;
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "<td>" . $row[2] . "</td>";
echo "<td>" . $row[3] . "</td>";
echo "<td>" . $row[4] . "</td>";
echo "<td>" . $row[5] . "</td>";
echo "<td>" . $row[6] . "</td>";
echo "<td>" . $row[7] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
at the end my modify.php page:
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
require_once('../conf.php');
session_start();
$data = $_SESSION['data'];
//clear get data
if(isset($_POST['submitbutton']))
{
echo "11111111";
$edit="UPDATE TABLE studentinfo
SET id=$data[0],
mac='$_POST['Mac']',
firstname='$_POST['FirstName']',
lastname='$_POST['LastName']',
email='$_POST['Email']',
department='$_POST['Department']',
city='$_POST['City']',
state='$_POST['State']'
WHERE id=$data[0]";
$result_edit=mysql_query($edit) or die ('edit user failed');
if(!$result_edit)
echo "edit done";
else
echo "edit failed";
}
//if(ISSET($_POST['submit']))
?>
<form action="" type="post">
<table>
<tr>
<th>Mac</th>
<th>FirstName</th>
<th>LastName</th>
<th>Email</th>
<th>Department</th>
<th>City</th>
<th>State</th>
</tr>
<tr>
<td>
<input type="text" name="Mac" value="prova"></input>
</td>
<td>
<input type="text" name="FirstName" value="<?php echo htmlspecialchars($data['firstname']); ?>" />
</td>
<td>
<input type="text" name="LastName" value="<?php echo $data[3]; ?>" />
</td>
<td>
<input type="text" name="Email" value="<?php echo $data[4]; ?>" />
</td>
<td>
<input type="text" name="Department" value="<?php echo $data[5]; ?>" /></td>
<td>
<input type="text" name="City" value="<?php echo $data[6]; ?>" />
</td>
<td>
<input type="text" name="State" value="<?php echo $data[7]; ?>" />
</td>
<td>
<input type="submit" name="submitbutton" />
</td>
</tr>
</table>
</form>
</body>
</html>
Now, it looks to work well until the modify page. i can't understand why in modify.php page i can't save variable on POST for the mysql upload. can someone help my to understant why don't work pls. Thanks.