Hi, I need help with PHP/javascript/mysql
I am fairly new to this so excuse me for my bad programming skills. I have PHP page which has to update mysql table and HTML table onclick. It updates HTML table ok but as soon as I refresh page it updates all data in mysql and it should update in by click one by one. Hope you understand what I need. Thx in advance.
<?php
session_start();
require_once("connect.php");
//$query = "SELECT f.flexi, f.status, f.allocation, m.username
//FROM flexi f, members m";
$query = "SELECT * FROM flexi";
$result = mysql_query($query);
$query1 = 'UPDATE flexi SET allocation = "allocated", user = "'.$_SESSION["username"].'" WHERE flexi="flexi1"';
$result1 = mysql_query($query1);
$result1 = $_SESSION['allocate'];
$query2 = 'UPDATE flexi SET allocation = "allocated", user = "'.$_SESSION["username"].'" WHERE flexi="flexi2"';
$result2 = mysql_query($query2);
$result2 = $_SESSION['alloc'];
echo "<html>
<body>
<table border=1 id='mytable'>
<tr><th>Flexi</th><th>Status</th><th>Allocation</th><th>User</th></tr>";
if (isset($_SESSION['username'])) // he got it.
{
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo'
<head>
<script type="text/javascript">
function change()
{
var first="'.$_SESSION['username'].'";
var all="'.$_SESSION['allocate'].'";
var x=document.getElementById("mytable").rows
var y=x[1].cells
y[3].innerHTML=first;
y[2].innerHTML="allocated";
exit();
}
function cchange()
{
var second="'.$_SESSION['username'].'";
var all="'.$_SESSION['alloc'].'";
var x=document.getElementById("mytable").rows
var y=x[2].cells
y[3].innerHTML=second;
var all2="'.$_SESSION['alloc'].'";
y[2].innerHTML="allocated";
exit();
}
</script>
</head>
';
echo "<tr>";
echo "<td>{$row['flexi']}</td>";
echo "<td>{$row['status']}</td>";
echo "<td>{$row['allocation']}</td>";
echo "<td>{$row['user']}</td>";
echo "</tr>";
}
}
echo "<td><input type='button' style='float:right' onclick='change(this.form)' value='Allocate'></td>";
echo "<td><input type='button' style='float:right' onclick='cchange(this.form)' value='Allocate'></td>";
?>
</table>
</body>
</html>