hello,
this project is a template to make an update on a field in a table with on click.
If you have time table, and the users can insert time events, this means there is a Users table, where you store the user's username and password.
If a registered user logged in, the $_SESSION variable should built to store his/her UserID from this table.
If you don't tell us the details you won't get the right answer. Be more specific.
If a user can add events to his time table means other users mustn't see it, ergo,
in the update and the display.php you need to list the events related to that person only. In the UPDATE query you need to insert this $_SESSION["userID"] value to be sure that row related to that user.
If you can't coop with this code how to build as you like, tell me π
In display you need to set this line, and modify the $a array for your variable name you use:
if ( empty( $a["Invoiced"] ) )
$set = "Set Invoiced 1 ";
else
$set = "Set Invoiced 0 ";
echo "TimesheetID:" . $a["TimesheetID"] . "<br />";
print "<input onClick=\"dochange('" . $a['TimesheetID'] . "','" . !$a["Invoiced"] . "')\" type=\"button\" value=\"$set\" name=\"Name\"><br />";
And the
<script language=Javascript>
and other parts goes to this display.php at the end of your file.
correct the file name in this line:
req.open("GET", "index.php?id="+id+"&inv=" + inv ); //make connection
This code goes in a new file, if you set tblTimesheet_update.php into the javascript, call the .php file
<?php
// Save this file into tblTimesheet_update.php file
// This file generated by http://phpcode.hu/ajax_updater/
// Please leave this message
session_start();
if(empty($_SESSION["userid"]))
die("You need to log in!");
$dbhost = "xxxxxxxx";
$dbuser = "xxxxxxxx";
$dbpass = "xxxxxxxxxx";
$dbname = "xxxxxxxxx";
mysql_pconnect( $dbhost, $dbuser, $dbpass ) or die ( "Unable to connect to MySQL server" );
mysql_select_db( "$dbname" );
if ( !empty( $_GET["id"] ) AND isset( $_GET["inv"] ) ) {
$value = ( empty( $_GET["inv"] ) )?0:1;
$sql = sprintf( "UPDATE tblTimesheet SET Invoiced='%d' AND userID='%d' WHERE `TimesheetID`='%d'", $value , $_GET["id"] , $_SESSION["userid"] );
$res = mysql_query( $sql ) OR die( "Count not run the query!" );
die( " updated succesfully!" );
die();
}
?>