So here is my problem, I want to add to my database table an expiration date to a specific row trough HTML and PHP but I dont know what is wrong. For some reason it dont delete the specific row when the time runs out.
And is possible to add something to the database for example, on the php introduce the time to expire in a column?
I'm just starting with this PHP MySQLi interactions so the code will be probabily bad!
HTML:
<div class="modal fade" id="addModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">VIPS</h4>
</div>
<div class="modal-body">
<div class="container">
<form class="form-horizontal" action="insert.php" method="post" onsubmit="setTimeout('location.reload()', 10);">
<div class="form-group">
<label class="control-label col-sm-2" for="full name">SteamID</label>
<input class="form-control" type="text" id="identity" name="identity" placeholder="SteamID" ng-model="newUser.fullname"/>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="full name">Name</label>
<input class="form-control" type="text" placeholder="Name" id="Name" name="name" ng-model="newUser.fullname"/>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="full name">immunity</label>
<input class="form-control" type="text" id="immunity" name="immunity" placeholder="Imunidade" ng-model="newUser.fullname"/>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="full name">Time</label>
<select id="time" name="time" data-plugin-selectTwo class="form-control populate">
<optgroup label="Staff">
<option value="1">1 minute</option>
<option value="2">2 minute</option>
</optgroup>
</select>
<div class="form-group">
<label class="control-label col-sm-2" for="full name">Flags</label>
<select id="flags" name="flags" data-plugin-selectTwo class="form-control populate">
<optgroup label="Staff">
<option value="zo">Founder</option>
<option value="abcdefghjkp">Admin</option>
<option value="abcdfgjkq">Mod</option>
</optgroup>
</select>
<div class="modal-footer">
<button class="btn btn-primary" type="submit" value="ADICIONAR">Add</button>
<button class="btn btn-default" type="button" data-dismiss="modal">Close</button>
</div>
</div>
</form>
</div>
PHP:
<?php
$conn = new mysqli("", "", "", "");
if ($conn->connect_error) {
die("Connection failed");
}
// Escape user inputs for security
$identity = mysqli_real_escape_string($conn, $_REQUEST['identity']);
$name = mysqli_real_escape_string($conn, $_REQUEST['name']);
$flags = mysqli_real_escape_string($conn, $_REQUEST['flags']);
$immunity = mysqli_real_escape_string($conn, $_REQUEST['immunity']);
$time=$_POST['time'];
$sql = "SELECT COUNT(*) FROM sm_admins WHERE identity = ('$identity')";
if($count = $conn->query($sql)){
if($count == 1){
$sql = "INSERT INTO sm_admins
(identity, name, flags, immunity, '', '', now(),
DATE_ADD(NOW(), INTERVAL time='time' MINUTE))
VALUES ('$identity', '$name', '$flags', '$immunity')";
if($conn->query($sql)){
echo "Good Connection";
}
}else{
echo "Identity already exist";
}
}
// close connection
header('Location: panel.php');
mysqli_close($conn);
?>
Your current query is:
$sql = "INSERT INTO sm_admins
(identity, name, flags, immunity, '', '', now(),
DATE_ADD(NOW(), INTERVAL time='time' MINUTE))
VALUES ('$identity', '$name', '$flags', '$immunity')";
it needs to be changed so that the database knows what you want. Since I don't have all the fieldnames for you sm_admin table I'll use f1,f2, f3 etc so you'll need to replace to the appropriate fieldname
$sql = "INSERT INTO sm_admins
(identity, name, flags, immunity, f1, f2, f3, f4, f5 )
VALUES ('$identity', '$name', '$flags', '$immunity', '', '', now(),
DATE_ADD(NOW(), INTERVAL time='time' MINUTE))";
Edit:
Your original sql statement wouldn't work. The above correction will work but you'll need to change f1..f5 to your relevant fieldnames.
As for the automatic deletion of records you could use a cronjob or a mySQL event. Documentation can be found at https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html. Cronjob will depend upon your server.
Here is a skeleton mysql event schedule - read documentation for details.
DELIMITER $$
-- SET GLOBAL event_scheduler = ON$$ -- required for event to execute but not create
CREATE /*[DEFINER = { user | CURRENT_USER }]*/ EVENT `_u3a_work`.`xx`
ON SCHEDULE
/* uncomment the example below you want to use */
-- scheduleexample 1: run once
-- AT 'YYYY-MM-DD HH:MM.SS'/CURRENT_TIMESTAMP { + INTERVAL 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...] }
-- scheduleexample 2: run at intervals forever after creation
-- EVERY 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...]
-- scheduleexample 3: specified start time, end time and interval for execution
/*EVERY 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...]
STARTS CURRENT_TIMESTAMP/'YYYY-MM-DD HH:MM.SS' { + INTERVAL 1[HOUR|MONTH|WEEK|DAY|MINUTE|...] }
ENDS CURRENT_TIMESTAMP/'YYYY-MM-DD HH:MM.SS' { + INTERVAL 1 [HOUR|MONTH|WEEK|DAY|MINUTE|...] } */
/*[ON COMPLETION [NOT] PRESERVE]
[ENABLE | DISABLE]
[COMMENT 'comment']*/
DO
BEGIN
(sql_statements)
END$$
DELIMITER ;
...delete the specific row when the time runs out.
You can't do this with MySQL. You'll have to come up with a solution using PHP. In this case cron jobs may come in handy.
How to create cron job using PHP?
A work around would be to add a column with DATETIME to your table. Set the default value to NOW(). So when you insert a record to the table inserted date and time will be saved in that column.
Then when you are retrieving data add a condition to the search query to filter information by expiration date and time
... WHERE `dateTime` > '2018-07-22 00:05:48'
Related
Hi I have a form to add members with their birth date. The input field for birth date is:
<div class="form-group">
<label for="data_nascita" class="col-sm-3 control-label">Birth Date</label>
<div class="col-sm-9">
<input name="data_nascita" type="date" class="form-control" id="data_nascita" placeholder="gg/mm/aaaa" />
</div>
</div>
Data are correctly uploaded to MYSQL and date format is
$data_nascita = ($_POST['data_nascita']);
var_dump($data_nascita); => string(10) "2003-04-15"
In the database is stored correctly, and it appears as
2018-12-14 18:50:48
I want to have the possibility to edit the information about the person (i.e. changing the birth date), and I created an edit file where all the database information is retrieved and appears in form fields that can be edited and updated in MYSQL.
Everything works fine except for dates, which appears as gg/mm/aaaa
The code I used for retrieving data is as usual:
<?php
$query = "SELECT data_nascita FROM volontari WHERE id_volontari = '$id'";
$res = $mysqli ->query($query);
$row = $res->fetch_array (MYSQLI_ASSOC);
$data_nascita = gira_data_db($row['data_nascita']);
function gira_data_db($data)
{
$array = explode( "-" , $data);
$array2 = array($array[2], $array[1], $array[0]);
$testo = implode( "/" , $array2);
return $testo;
}
?>
<div class="form-group">
<label for="data_nascita" class="col-sm-3 control-label">Birth Date</label>
<div class="col-sm-9">
<input name="data_nascita" type="date" class="form-control" id="data_nascita" value="<?php echo $data_nascita ?>" />
</div>
</div>
The date retrieved is
var_dump(gira_data_db($row['data_nascita']);) => string(10) "15/04/2003"
However in my form field the data appears as 00/00/0000. If I echo the date in an input field type=text, it appears correct.
Am I doing something wrong?
The problem is when you explode by '-' array[2] is '14 18:50:48' and it's not valid value for input with date type.
simply change gira_data_db function as follows:
function gira_data_db($data)
{
return date("YYYY-MM-DD", strtotime($data));
}
I hope it would help you
One my form I have the option to choose from a select box, or to manually enter the information.
I want to prevent user from entering both. They should either choose from the select OR enter manually if their selection is not already there.
html code
<div class="row">
<div class="form-group col-sm-4">
<div class="row">
<div class="col-sm-3">
<label for="selectComplvl" class="regions" >Region</label></div>
<div class="col-sm-8">
<select class="form-control regionbox" id="region" value="" name="region">
<option>---Select---</option>
<?php
$region_sql = "SELECT * FROM `regions`";
$region_res = mysqli_query($con, $region_sql);
if(mysqli_num_rows($region_res) > 0){
while($region_row = mysqli_fetch_array($region_res)){
echo "<option value='".$region_row[id]."'>".$region_row[region]."</option>";
}
}
?>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group col-sm-4">
<div class="row">
<div class="col-sm-4">
<label for="feisEntered" class="feis">Feis Entered</label></div>
<div class="col-sm-8">
<select class="form-control feisbox" id="feisEntered" name="feisEntered">
<option>First choose a Region</option>
</select>
<div class="help-block with-errors"></div>
</div>
</div>
</div>
<div class="form-group col-sm-4">
<div class="row">
<div class="col-sm-3">
<label for="feisEntered" class="enterfeis">Or Enter</label></div>
<div class="col-sm-8">
<input id="inputfeis" type="text" name="feisEntered" class="form-control" placeholder="Feis name - MM/DD/YYYY">
<div class="help-block with-errors"></div>
</div>
</div>
</div>
</div>
And my query:
if(isset($_POST['submit'])){
$dancer=$_POST['dancer'];
$dancer = mysqli_real_escape_string($con,$dancer);
$level=$_POST['level'];
$level = mysqli_real_escape_string($con,$level);
$feisEntered=$_POST['feisEntered'];
$feisEntered = mysqli_real_escape_string($con,$feisEntered);
$danceName=$_POST['danceName'];
$danceName = mysqli_real_escape_string($con,$danceName);
$compNum=$_POST['compNum'];
$compNum = mysqli_real_escape_string($con,$compNum);
$competitor = $_POST['competitor'];
$competitor = mysqli_real_escape_string($con,$competitor);
$danceScore = $_POST['danceScore'];
$danceScore = mysqli_real_escape_string($con,$danceScore);
$placement = $_POST['placement'];
$placement = mysqli_real_escape_string($con,$placement);
$firstScore = $_POST['firstScore'];
$firstScore = mysqli_real_escape_string($con,$firstScore);
$secondScore = $_POST['secondScore'];
$secondScore = mysqli_real_escape_string($con,$secondScore);
$thirdScore = $_POST['thirdScore'];
$thirdScore = mysqli_real_escape_string($con,$thirdScore);
$judge = $_POST['judge'];
$judge = mysqli_real_escape_string($con,$judge);
$comments = $_POST['comments'];
$comments = mysqli_real_escape_string($con,$comments);
$query = "INSERT INTO reports (user_id, dancer_id1, dancer_name, competition_level1, feis_entered, dance_name1, competition_number1, number_competitors1, dancer_score1, dancer_placement1, firstpl_score1, 2ndpl_score1, 3rdpl_score1, judge_name1, judge_comment1) VALUES ('$id','$dancerID', '$dancer', '$level', '$feisEntered', '$danceName', '$compNum', '$competitor', '$danceScore', '$placement', '$firstScore', '$secondScore', '$thirdScore', '$judge', '$comments')";
$result = mysqli_query($con, $query);
}
So what I want to happen is a error message appears if they fill out both saying "Please choose only one". That way only one enters into database.
Never rely on just JS to validate input. Use JS to implement the behavior you speak of and then handle all possible outcomes in PHP. If someone is fiddling with your JS and bypasses the behavior you implement, you need to be able to handle that in your PHP code as well to make sure DB doesnt get unexpected input and break everything. Just like Justin said above, you could select one or the other, or throw an error. I recommend throwing an error and telling the user to make sure they have JS enabled.
In your HTML document, you should use Javascript to validate the user input before submitting the form to the PHP script. Then, in the PHP script, you should double-check that values were not received for both the select and the input (this could happen if the user does not have Javascript enabled, or they somehow bypass the validation) and determine what you want to do in that case (select one over the other, or exit with an error).
I am working with a fairly straight forward form yet for some reason it is not submitting NULL results and instead submits them as empty results.
<div class="span6">
<form action="" method="POST">
<div class="block-fluid without-head">
<div class="toolbar clearfix">
<div class="right">
<div class="btn-group">
<button type="submit" class="btn btn-small btn-warning tip" data-original-title="Submit Aritcle">
<span class="icon-ok icon-white"></span>
</button>
<button type="button" class="btn btn-small btn-danger tip" data-original-title="Delete Article">
<span class="icon-remove icon-white"></span>
</button>
</div>
</div>
<div class="left">
<div style="font-size: 11pt; font-family: -webkit-body; font-weight: bolder;">Article Exchange Request</div>
</div>
</div>
<div class="row-form clearfix">
<div class="span3">Title</div>
<div class="span9"><input type="text" name="title" value="" placeholder="main subject title"></div>
</div>
<div class="row-form clearfix">
<div class="span3">First Sentence</div>
<div class="span9"><input type="text" name="s1" value="" placeholder="Sentence with max of 200 characters"></div>
</div>
<div class="row-form clearfix">
<div class="span3">Second Sentence</div>
<div class="span9"><input type="text" name="s2" value="" placeholder="Optional sentence with max of 200 characters"></div>
</div>
<div class="row-form clearfix">
<div class="span3">Third Sentence</div>
<div class="span9"><input type="text" name="s3" value="" placeholder="Optional Sentence with max of 200 characters"></div>
</div>
<div class="row-form clearfix">
<div class="span3">Website Url</div>
<div class="span9"><input type="text" name="link" value="" placeholder="Url to be included in articles"></div>
</div>
<div class="row-form clearfix">
<div class="span3">Website Url Title</div>
<div class="span9"><input type="text" name="link_text" value="" placeholder="Url text to be included in articles limit 150 characters"></div>
</div>
<div class="row-form clearfix">
<div class="span3">Credit Offer</div>
<div class="span9"><input type="text" name="cost_value" value="" placeholder="Example: 100"></div>
</div>
</div>
</form>
</div>
The problem is someone can just come along and submit the form without entering any data at all, and it still submits, and adds empty results to every column in the database. Meaning no NULL values are being set in the database.
My form processing
<?
if (isset($_POST[cost_value])) {
$stmt = $db->prepare("SELECT credits from member_credits WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$row = $stmt->fetch();
$count = $row[credits];
if ($count > $_POST[cost_value]) {
$stmt = $db->prepare('INSERT INTO article_requests (title, s1, s2, s3, link, link_text, offer, username) VALUES (:title, :s1, :s2, :s3, :link, :link_text, :offer, :username)');
$stmt->bindValue(':title', $_POST[title]);
$stmt->bindValue(':s1', $_POST[s1]);
$stmt->bindValue(':s2', $_POST[s2]);
$stmt->bindValue(':s3', $_POST[s3]);
$stmt->bindValue(':link', $_POST[link]);
$stmt->bindValue(':link_text', $_POST[link_text]);
$stmt->bindValue(':offer', $_POST[cost_value]);
$stmt->bindValue(':username', $username);
$stmt->execute();
}
}
?>
What I expect to happen on submission is if no value is entered in the form it should be set to NULL... that would mean if no $_POST[cost_value] was set, the form wouldn't submit. As it stands now, it is ALWAYS seeing $_POST[cost_value] as being set - sometimes to a value such as $_POST[cost_value] = '100'; and other times $_POST[cost_value] = ''; but in both cases, the form will submit. Equally I have the database set so that only the values of s2 and s3 should be able to be null, however when everything is submitting empty instead of null, thats mostly useless.
What exactly am I missing? Why will it not say $_POST[cost_value] = NULL; if the user has not input a value? Why is it submitting ''?? I have a feeling its going to be something basic I am overlooking, I just don't see it....
UPDATE FOR CLARITY
I know there are a number of ways to fix this. I can use if then tests, I can use temporary variables, I can check for the value itself is something other than ''. I know WHAT the work arounds are. I don't understand WHY they are needed. Why is it I make forms every day of the week using if isset, and everyday that works. If a form has no values input from the user, the form won't submit because an if isset returns false. So why is it on this particular form it is submitting '' instead of saying !isset don't process.
// Assign a var to the post.
$DIRTY_Var = $_POST['varinputname'];
// ensure the var is cleaned (no funny business when submitting)
$CLEAN_Var = filter_var($DIRTY_Var,` FILTER_SANITIZE_STRING);
// check if the var is empty, or has value. If empty it will set the var to null;
if (!$CLEAN_Var) { return $CLEAN_Var = null; }
// validate input
$valid = true;
// insert data
if ($valid) {
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO Table ("
."ColumnNames"
.")"
."VALUES("
."?"
.")";
$q = $pdo->prepare($sql);
$q->execute(array($CLEAN_Var));
// Once INSERT is completed, we will redirect.
header("Location:" 'link.php'); exit;
}
Try
If(isset($_POST['cost_value']) && !empty($_POST['cost_value']){
// your code
}
I created a form you know; text fields, radio buttons and the submit button
within the said form, I have a div enclosing a section of the radio buttons hidden and a text field upon page load using inline CSS display:none;
If the end user chose yes, the hidden fields will be displayed using a jquery function. If the user chose No or Not Sure, the form will remain hidden or become hidden using the same jquery function.
If the user chose No or Not Sure, i want to automatically assign values for the hidden fields and store them in database.
Here is my form:
<div id = "relation" style = "display: none;">
<p class= "form-p" >Who are you related o?</p>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-4">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" autocomplete="off" name="family" value="Bride" required />Bride
</label>
<label class="btn btn-default">
<input type="radio" autocomplete="off" name="family" value="Groom" required />Groom
</label>
<label class="btn btn-default">
<input type="radio" autocomplete="off" name="family" value="Friend" required />Friend
</label>
<span class="error"><?php echo $famErr;?></span>
</div>
</div>
</div>
<p class = "form-p">Guests in your party, including yourself: </p>
<div class = "form-group">
<label class="control-label col-sm-4"></label>
<div class="col-xs-2">
<input type = "text" class = "form-control" name="num" placeholder = "0" required />
<span class="error"><?php echo $numErr;?></span>
</div>
</div>
</div> <!-- end of id relation-->
Here are the functions:
// function to add RSVP user entry to the database
public function user_attending_storage_RSVP($name, $email, $attend, $fam, $num){
$replies = "INSERT INTO rsvp (name, attending, family, total) VALUES (:name,:attending,:family,:total)";
try{
$query = $this->conn->prepare($replies);
$results = $query->execute(array(":name"=>$name, ":attending"=>$attend, ":family"=>$fam, ":total"=>$num));
}
catch(PDOException $e){
die($e->getMessage());
}
}
// function to add RSVP user entry to the database
public function user_not_attending_storage_RSVP($name, $email, $attend){
$replies = "INSERT INTO rsvp (name, attending, family, total) VALUES (:name,:attending,:family,:total)";
try{
$query = $this->conn->prepare($replies);
$results = $query->execute(array(":name"=>$name, ":attending"=>$attend, ":family"=>$fam, ":total"=>$num));
}
catch(PDOException $e){
die($e->getMessage());
}
}
Here's how I call the function on the webpage
// check for data in fields
if(isset($_POST['name']) ==true && isset($_POST['email']) ==true && isset($_POST['attending']) && isset($_POST['family']) && isset($_POST['num'])){
$name=test_input($_POST['name']);
$email=test_input($_POST['email']);
$attend=test_input($_POST['attending']);
$fam=test_input($_POST['family']);
$num=test_input($_POST['num']);
if($attend == "No" || $attend == "Not Sure"){
$fam = "nothing";
$num = 0;
//inserting user data from form into database
$genQuery->user_Not_attending_storage_RSVP($name, $email, $attend);
}
else{
//inserting user data from form into database
$genQuery->user_attending_storage_RSVP($name, $email, $attend, $fam, $num);
}
// send mail to user
$genQuery->user_invite_confirmation_RSVP($name, $email, $attend,$fam, $num);
}
You can use the getElementById() method...
if(getElementById('input_id').value() == 'no' || getElementById('user_id').value() == 'not sure'){getElementById('input_you_want_to_change).value('Defualt value')}
This will change the value if the user selects no or not sure. Then use PHP to store this new value in the database.
Background info:
I am trying to create a digital job raising system. Admin raises a job sheet and pulls in a client from "tblclient" table, fills out the details of the job and then assigns the job sheet to a employee user.
With this being said I am having difficulty pulling data from the clients table and users table then linking them to a row in the jobs table. I am new to PHP coding and am unsure how to script it out so my user can select the client and all the client details are attached to the job sheet and then coding it so the job sheet can be moved around between users.
This is so that when the job is complete the Admin can preview the job sheet with all the client details on it, job details and print with all the information on screen.
Is there any tutorials I can use for this procedure?
Notes:
I currently have a form that will insert the job data into the job table, I just don't know what code to use to pull in users/clients and link it to that specific job.
Thanks
<?php
include 'core/init.php';
include 'include/overall/overall_header.php';
protect_page();
admin_protect();
$today_date = date("Y-m-d");
?>
<div id="container">
<div id="content-container">
<div id="sidenav">
<?php include 'include/sidenav.php'; ?>
</div>
<div id="content">
<h1>Add a new job</h1>
<?php echo $today_date; ?>
<?php
if (isset($_GET['success']) && empty($_GET['success'])) {
echo 'Job added successfully!';
} else {
if (empty($_POST) === false && empty($errors) === true) {
$job_data = array(
'date' => $_POST['date'],
'description' => $_POST['description'],
'artworkbrief' => $_POST['artworkbrief'],
'extracosts' => $_POST['extracosts'],
'stock1' => $_POST['stock1'],
'orderno1' => $_POST['orderno1'],
'ordered1' => $_POST['ordered1'],
'stock2' => $_POST['stock2'],
'orderno2' => $_POST['orderno2'],
'ordered2' => $_POST['ordered2'],
'stock3' => $_POST['stock3'],
'orderno3' => $_POST['orderno3'],
'ordered3' => $_POST['ordered3'],
'subtotal' => $_POST['subtotal'],
'extracosts1' => $_POST['extracosts1'],
'total' => $_POST['total']
);
raise_job($job_data);
header('Location: raise_job.php');
exit();
}
}
?>
<select id="clientname" name="clientname">
<?php
$pdo = new PDO('mysql:host=localhost;dbname=formation_ims', 'root', 'form8tion');
#Set Error Mode to ERRMODE_EXCEPTION.
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('Select clientname from tblclients');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
echo '<option>'.$row['clientname'].'</option>';
}
?>
</select>
<div id="job-sheet">
<form action="" method="post">
<div class="row-3">
<div class="description">
<p>Description:</p>
<textarea type="text" name="description"></textarea>
</div>
</div>
<div class="row-4">
<div class="artwork-brief">
<p>Artwork Brief:</p>
<textarea type="text" name="artworkbrief"></textarea>
</div>
</div>
<div class="row-5">
<div class="extra-costs-container">
<div class="extra-costs">
<p>Extra Costs:</p>
<textarea type="text" name="extracosts"></textarea>
</div>
</div>
<div class="total-container">
<div class="sub-total">
Sub Total:
<input type="text" name="subtotal">
</div>
</div>
<div class="extra-num-container">
<div class="extra-costs-num">
Extra Costs:
<input type="text" name="extracosts1">
</div>
</div>
</div>
<div class="row-6">
<div class="stock-material-container">
<div class="stock-material">
<p>Stock/Material:</p>
<div class="stock-material-row">
<div class="stock-material-col01">
<input type="text" name="stock1">
</div>
<div class="stock-material-col02">
Order No.<input type="text" name="orderno1">
</div>
<div class="stock-material-col03">
Ordered:<input type="checkbox" name="ordered1">
</div>
</div>
<div class="stock-material-row">
<div class="stock-material-col01">
<input type="text" name="stock2">
</div>
<div class="stock-material-col02">
Order No.<input type="text" name="orderno2">
</div>
<div class="stock-material-col03">
Ordered:<input type="checkbox" name="ordered2">
</div>
</div>
<div class="stock-material-row">
<div class="stock-material-col01">
<input type="text" name="stock3">
</div>
<div class="stock-material-col02">
Order No.<input type="text" name="orderno3">
</div>
<div class="stock-material-col03">
Ordered:<input type="checkbox" name="ordered3">
</div>
</div>
</div>
</div>
<div class="total-container">
<div class="sub-total">
Sub Total:
<input type="text" name="subtotal">
</div>
</div>
<div class="extra-num-container">
<div class="extra-costs-num">
Extra Costs:
<input type="text" name="extracosts1">
</div>
</div>
</div>
</div>
<input type="submit" value="Submit">
</form>
</div>
</div>
<div class="clear"></div>
<?php include 'include/overall/overall_footer.php'; ?>
ahh yes, I understand what this code is doing but not familiar with the syntax. I got an error:
Parse error: syntax error, unexpected ';' in...
I think you left out an ")" but even after reinstating it, my dropdown menu isn't populated:
<select name='clientid'>
<?php
$query="SELECT * FROM tblclients";
$result=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_assoc($result)){
echo "<option value='".$row['Client_ID']."'>".stripslashes($row['ClientName']." </option>";
}
?>
`
When inputting your job, you will want a field in your form containing clientid and another containing userid. The following is an example of how that might be done.
<select name='clientid'>
<?php
$query="SELECT * FROM ClientTable";
$result=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_assoc($result)){
echo "<option value='".$row['ClientID']."'>".stripslashes($row['ClientName']."</option>";
}
?>
</select>
Then when you want to output the job with all it's information, when you run the query you should use the LEFT JOIN command, for example
$query="SELECT * FROM JobTable
LEFT JOIN UserTable ON UserTable.UserID=JobTable.UserID
LEFT JOIN ClientTable ON ClientTable.ClientID=JobTable.ClientID
WHERE JobID='".mysql_real_escape_string($jobid)."'";
$result=mysql_query($query) or die(mysql_error());
That grabs the appropriate client and user informations by their IDs (which I hope you've set up with auto-increment by the way)