Forum Moderators: coopster

Message Too Old, No Replies

update query problems

         

nshack31

1:32 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



i have a database with fields as follows..


Timeid-----day---------time
--1-------Monday--------5 - 7pm
--2-------Tuesday-------5 - 7pm
--3-------Wednesday-----5 - 7pm
--4-------Thursday------5 - 7pm
--5-------Friday--------4.30pm - 6.30pm
--6-------Saturday------5 - 6pm
--7-------Sunday--------5 - 6pm

I wish to have the time for each day displayed in a text field so i use the following...

 $query = "SELECT * FROM coursetimes"; 
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$day=$row['day'];
$daytime=$row['time'];
$timeid=$row['timeid'];

$data_cells .=<<<HTML
<tr>
<td><p>$day:</p></td>
<td><input type = "text" size="15" name = "$day" value = "$daytime" maxlength="10"></td>
</tr>
HTML;
}

this works fine but on the form if the user edits the times in the text field and clicks update i wish the database times to be updated, how can i do this?! im using...


if (isset($_GET['update']))
{
$query="UPDATE coursetimes SET time = '$daytime' WHERE timeid = '$timeid'";
mysql_query($query) or die(mysql_error());
$complete = "updated";
}

but this is not working :( can anybody help?
thanks

omoutop

1:40 pm on Feb 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



according to your code you should have :
if (isset($_GET['update']))
{
$query="UPDATE coursetimes SET time = '$day' WHERE timeid = '$timeid'";
mysql_query($query) or die(mysql_error());
$complete = "updated";
}

Note the SET time='$day" : you have named your textfields as $day.

nshack31

1:54 pm on Feb 17, 2006 (gmt 0)

10+ Year Member



hi sorry i pasted the wrong code, it should be ...


$query = "SELECT * FROM coursetimes";
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$day=$row['day'];
$daytime=$row['time'];
$timeid=$row['timeid'];

$data_cells .=<<<HTML
<tr>
<td><p>$day:</p></td>
<td><input type = "text" size="15" name = "$timeid" value = "$daytime" maxlength="10"></td>
</tr>
HTML;
}

which is working, and the update which is not working is...


if (isset($_GET['update']))
{
$query="UPDATE coursetimes SET time = '$daytime' WHERE timeid = '$timeid'";
mysql_query($query) or die(mysql_error());
$complete = "updated";
}

can anybody help me with the update please?!

thanks

omoutop

2:07 pm on Feb 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



try this one (havent self tested so cant be sure)..
==in form==
<input type = "text" size="15" name = "day_$timeid" value = "$daytime" maxlength="10">

==in update==
//query to table
while .....
{
// make new var (day_Monday, day_Friday, etc)
$my_id = "day_".$row['Timeid'];
$my_val = $$my_id;
if ($my_val!="")
{
$query="UPDATE coursetimes SET time = '$my_val' WHERE timeid = '".$row['Timeid']."'";
{
}