Not writing to the database correctly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
almystersv
Forum Newbie
Posts: 1
Joined: Mon Feb 11, 2008 5:16 pm

Not writing to the database correctly

Post by almystersv »

Hi Guys.

I have this code that is allocating tasks to users on the system. At the moment the only thing being written to the database is one row that contains '0' in the 'taskID' column, '0' in the 'empID' column, and nothing in the 'emptaskweekDay' column.

I want it to write all the users tasks into the database so think i need to implement a loop in the taskAdminQuery page or something but not entirely sure.

Any help would be great. Thanks.

TaskAdmin.php

Code: Select all

<?php
    session_start();
    if (isset($_SESSION['username']) == false && ($_SESSION['type']) == 'user' && ($_SESSION['type']) == 'manager'){
        header("Location: login.php");
        exit();
    }
    require "connect.php";
    
    $query = "select * from task where weekday = 'Monday' OR weekday = 'Everyday' ORDER BY taskID";
    $result = mysql_query($query, $connection) or die ("Unable to perform query $query");
    
    $query2 = "select * from employee where active = 'y'";
    $result2 = mysql_query($query2, $connection) or die ("Unable to perform query $query2");
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Task Allocation</title>
 
<link rel="stylesheet" type="text/css"
href="mystylelogin.css" />
 
</head>
 
<body>
<?php
include ("headerAdmin.php");
include ("TasksHeaderAdmin.php");
?>
 
 
<div id="Adminheader">Monday Task Allocation</div>
 
<div id="AdminMainTable">
<table width="860" >
 <hr />
    <tr>
    <th width="142"><div align="left" class="style2">Task Name</div></th>
    <th width="262"><div align="left" class="style2">Description</div></th>
    <th width="140"><div align="left" class="style2">Weekday</div></th>
    <th width="140"><div align="left" class="style2">Assign</div></th>
    </tr>
        <?php
        //Build Select Menu
        $employee_list = '<select name="empName"><option>Select an Employee</option>';
        while ($row2 = mysql_fetch_array($result2))
        $employee_list .= '<option>'.$row2['fName'].'&nbsp;'.$row2['sName'].'</option>';
        $employee_list .= '</select>';
 
        while($row = mysql_fetch_array($result)) 
        { ?>
        <tr>
            <td height="27"><?php echo $row['taskName']; ?></td>
            <td><?php echo $row['taskDescription']; ?></td>
            <td><?php echo $row['weekday']; ?></td>
            <td>
            <form><?php echo $employee_list; ?></form></td>
        </tr>
        <?php } ?></td>
    </tr>
</table>
<form action="taskAdminQuery.php">
<input name="Save" type="submit" value="Allocate Tasks" />
</form>
</div>
</body>
</html>
TaskAdminQuery.php

Code: Select all

<?php
    require "connect.php";
    //$empName = $_GET['empName'];
    $empID = $_GET['empName'];
    $emptaskweekDay = $_GET['weekday'];
    $taskID = $_GET['taskID'];
    
    $query =  "insert into emptask values ('".$taskID."','".$empID."','".$emptaskweekDay."','N')";
    $result = @mysql_query($query, $connection) 
    or die ("Error:".mysql_error());
    
    $message1 = "Tasks Allocated Successfully.";
    header("Location: TaskAdmin.php?message1=$message1");
    exit();
    //}
?>
GuitarheadCA
Forum Newbie
Posts: 20
Joined: Fri Jul 13, 2007 12:59 am

Re: Not writing to the database correctly

Post by GuitarheadCA »

Your <form> element must encompass all of the <input> and <select> elements in the page. Try moving it up and see if that helps.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Not writing to the database correctly

Post by califdon »

Are you showing the entire content of those scripts?? First of all, you have 2 <form>s, what's the first one for?? In your second <form> there are no <input> data elements. Also, you fail to specify the method=GET. So it's not surprising that there is no data in the $_GET variables. It seems that you need to review the basics of HTML syntax for forms.
Post Reply