Hello, I have this function that is use to update a record. It was originally designed to pull all data from one table. But I had to change that so that I could pull the data from two tables. What I want to do is to alter a record depending on the status. If the status is normal for example I want to update it, but if the record is suppose to be another status I want to be able to insert a new record into the other table and delete the old record. Anyway, here's my code:
function update($up)
{print_r($up);
$db=@mysql_connect("localhost","root");
mysql_select_db("nti_admin",$db);
if($up[x]='Normal')
{
$select=mysql_query("SELECT FROM time_work WHERE uname='$up[uname]'",$db);
print"$select[status]";
if($up[status]==$select[status] && $up[id]==$select[id])
{
mysql_query("UPDATE time_work
SET date='$up[date]',
status='$up[status]',
hours='$up[hours]',
project='$up[project]',
activity='$up[activity]',
rdproj='$up[rdproj]',
comments='$up[comments]'
WHERE id='$up[id]'",$db);
}
else
{
$sql = "INSERT INTO time_off (uname,date,status,hours,comments) VALUES (\"$up[uname]\", \"$up[date]\", \"$up[status]\", \"$up[hours]\",\"$up[comments]\")";
}
}
else if($up[x]!='Normal')
{
$row=mysql_query("SELECT FROM time_off WHERE uname='$up[uname]'",$db);
print"$row[status]";
if($up[status]==$row[status] && $up[id]==$row[id])
{
mysql_query("UPDATE time_off
SET date='$up[date]',
status='$up[status]',
hours='$up[hours]',
comments='$up[comments]'
WHERE id='$up[id]'",$db);
}
Hopefully someone has an idea for me.
Thanks in advance,
M