I am having some minor errors and was wondering if anyone could help!
I am creating a attendance system for a college.
This Scenario:
Student logs in successfully and then wants to view his/her attendance for a particular course.
Problem: I want it to show me both checked and uncheked data from mysql, it currently shows an empty checkbox (when its meant to be checked) also at the moment it is showing numerous duplicated data, is it possible i could limit that, say for example show one record per week , it shows all data and duplicates it.
<?php
$q3= "SELECT attendance.week_number_id, attendance.week_number, courses.course_id, students.student_id, course_attendance.present, course_attendance.notes
FROM courses, course_attendance, attendance, students
WHERE course_attendance.student_id= ".$_SESSION['student_id']." AND course_attendance.course_id= courses.course_id AND course_attendance.week_id= attendance.week_number_id AND courses.course_id='101'
";
$result = mysql_query($q3) or die(mysql_error());
echo "<table border='1' align='center'><tr> <th><strong>Week Number</strong></th> <th><strong>Present</strong></th> <th><strong>Notes</strong></th> </tr> ";
while($row = mysql_fetch_assoc($result))
{
extract($row);
echo
"</td><td width='200' align='center'>" .$row['week_number'].
"</td><td width='400' align='center'><input type='checkbox' name='present'" .$row['present'].
"</td><td width='400' align='center'>" .$row['notes'].
"</td><tr>";
}
echo "</table>";
?>
Note: I am connected successfully to database, mysql is up and running, i am using sessions, currently it does show data for the student but does not show the existing checked or uncheked value, the checkbox is empty.
Can anyone help
In your code, you're not properly defining the checkbox to be checked. Make a code that adds checked="true" if the 'present' field is 1.
<?php
$q3 = " SELECT attendance.week_number_id, attendance.week_number, courses.course_id, students.student_id, course_attendance.present, course_attendance.notes
FROM courses, course_attendance, attendance, students
WHERE course_attendance.student_id= ".$_SESSION['student_id']." AND course_attendance.course_id= courses.course_id AND course_attendance.week_id= attendance.week_number_id AND courses.course_id='101'";
$result = mysql_query($q3) or die(mysql_error());
echo "
<table border='1' align='center'>
<tr>
<th><strong>Week Number</strong></th>
<th><strong>Present</strong></th>
<th><strong>Notes</strong></th>
</tr>
";
while($row = mysql_fetch_assoc($result)) {
$checked = '';
if($row['present'] == 1) {
$checked = ' checked="true"';
}
echo "
<tr>
<td width='200' align='center'>" . $row['week_number'] . "</td>
<td width='400' align='center'>
<input type='checkbox' name='present'" .$checked . "/>
</td>
<td width='400' align='center'>" . $row['notes'] . "</td>
</tr>
";
}
echo "</table>";
?>
Your
echo
"</td><td width='200' align='center'>" .$row['week_number'].
"</td><td width='400' align='center'><input type='checkbox' name='present'" .$row['present'].
"</td><td width='400' align='center'>" .$row['notes'].
"</td><tr>";
statement should be
$present = "";
if(.$row['present']==1)
{
$present = "checked =checked/>";
}
else
{
$present = "/>";
}
echo
"" .$row['week_number'].
"" .$row['notes'].
"";
Hope this helps you. Thanks
$checked = '';
if($present == 1) {
$checked = 'checked="checked"';
}
echo "</td><td width='200' align='center'>" .$row['week_number'].
"</td><td width='400' align='center'><input type='checkbox' name='present'" .$checked . "/>" .
"</td><td width='400' align='center'>" .$row['notes'].
"</td><tr>";
}
echo "</table>";
Try.
Related
I need to be able to display the results of the submitted form with radio buttons. I want the ID to display with either of the results '1' or '2' from the radio button values.
i.e. ID: 13 - Value: 2
if the row id is set within name the radio buttons work fine but I'm not sure how to display the results from it
if the name of the radio button is set to 'ans' it links all radio buttons together, when I want them working per id
Please see my below code to explain a little better - I'm just not sure how to echo this
<?php
$sql = "SELECT * FROM 'tz_todo' ORDER BY 'position' ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table border='1' width='100%' bordercolor='#000000' style='border-collapse: collapse'><tr class='t1' bgcolor='#00204F'><th>
<font color='#FFFFFF'>ID</font></th><th><font color='#FFFFFF'>CHECK</font></th>
<th width='50'>
<font color='#FFFFFF'>OK</font></th><th width='50'><font color='#FFFFFF'>FAIL</font></th></tr>";
// output data of each row
while ($row = $result->fetch_assoc()) {
echo "<tr><td>
<p align='center'>" . $row["id"] . "</td><td>
<p align='center'>" . $row["text"] . "</td><td align='center' width='50'><input type='radio' name='" . $row["id"] . "' value='1'><br></td>
<td align='center' width='50'><input type='radio' name='" . $row["id"] . "' value='2'><br></td></tr>";
}
echo "</table><input type='submit' value='Submit' name='submit' class='buttons'> ";
} else {
echo "0 results";
}
$conn->close();
?>
</form>
<?php
if (isset($_POST['submit'])) {
echo("????????????????????????????????????");
}
?>
I've now amended it slightly and have it generating results but now the IDs aren't linked to the two radio buttons (1 and 2)
<?php
$sql = "SELECT * FROM `tz_todo` ORDER BY `position` ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table border='1' width='100%' bordercolor='#000000' style='border-collapse: collapse'><tr class='t1' bgcolor='#00204F'><th>
<font color='#FFFFFF'>ID</font></th><th><font color='#FFFFFF'>CHECK</font></th>
<th width='50'>
<font color='#FFFFFF'>OK</font></th><th width='50'><font color='#FFFFFF'>FAIL</font></th></tr>";
// output data of each row
while ($row = $result->fetch_assoc()) {
$rowid = $row["id"];
echo "<tr><td>
<p align='center'>" . $row["id"] . "</td><td>
<p align='center'>" . $row["text"] . "</td><td align='center' width='50'><input type='radio' name='ans' value='1'><br></td>
<td align='center' width='50'><input type='radio' name='ans' value='2'><br></td></tr>";
}
echo "</table><input type='submit' value='Submit' name='submit' class='buttons'> ";
} else {
echo "0 results";
}
$conn->close();
?>
</form>
<?php
if (isset($_POST['ans'])) {
$answer = $_POST['ans'];
if ($answer == "1") {
echo 'OK';
} elseif ($answer == "2") {
echo 'FAIL';
}
}
?>
Please let me know if you would like me to explain a little better or differently
Thanks,
Tom
I think I understand your problem. You should name the radio button this way for example
name='ans" . $row["id"] . "'
This way, radio buttons will work together for each row.
Instead of using the name field within the radio button, I've merged it all into the value field:
<input type='radio' name='radio' value='".$rowid." - 1'>
but then I have the problem that you can only select 1 radio button for all rows
I want some information that is stored in my database to be an header in a table.
Basically its got a list of competitors down the side with theirs scores running in rows. Each competitor has their own row. At the top of the table is the name of the event they took part in. I cant manage to make the event name come from the database so got to edit the page each time I add a set of scores.
I have attempted as you will see in the code below;
<?php
require("db_connect.php");
$result = mysql_query("SELECT *, (ct1 + ct2 + ct3 + ct4 + ct5 + ct6) AS results FROM resultsopen WHERE ct='1'");
if(mysql_num_rows($result) == 0) { echo 'No competitors found'; } else {
echo "<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" align=\"center\">
<tr align=\"center\">
<td>Competitor</td>
<td>Member No</td>
<td>" . $row['cta'] . "</td>
<td>E2</td>
<td>E3</td>
<td>E4</td>
<td>E5</td>
<td>E6</td>
<td>E7</td>
<td>Overall</td>
<td></td>
</tr>";
$x=1;
while($row = mysql_fetch_array($result))
{
if($x%2): $rowbgcolor = "#FFFFFF"; else: $rowbgcolor = "#EEEEEE"; endif;
echo "<tr align=\"center\" bgcolor=\"" .$rowbgcolor. "\">";
echo "<td>" . $row['competitor'] . "</td>";
echo "<td>" . $row['memberno'] . "</td>";
echo "<td>" . $row['ct1'] . "</td>";
The line in question is <td>" . $row['cta'] . "</td>
The other lines are just text which I manually change each time.
I also know that mysql should be changed to mysqli but I am not confident in the change just yet.
Scenario: I have a web form where the user can manually enter data (see below). The user will submit the form and the data will be automatically added to the database.
date, order_ref, first_name, last_name, postcode, country, quantity, scott_packing, packing_price, courier_price, dispatch_type, job_status
On another page, the user will be able to only view all the jobs that are currently being (this data is taken from the database) processed and add the tracking number and edit the packing_price,courier_price and job_status and submit the new data.
http://i754.photobucket.com/albums/xx182/rache_R/Screenshot2014-04-23at104045_zps2a628d50.png
Issue: When the user clicks the 'submit all' button, the user is supposed to be redirected to the thank you page which simply notifies the user that their entry has been successful however at the moment, the user is only directed to a blank page which contains the navigation menu. I have checked the database to see if the data has been updated but nothing has changed. How do i get my update statement to work so that the user can update the existing jobs?
This is the code for the page that displays all the jobs:
<?
session_start();
if(!session_is_registered(myusername))
{
header("location:../index.php");
}
include("../template/header.php");
include("../controllers/cn.php");
$sql = "SELECT * FROM Jobs";
$qry = mysql_query($sql);
echo "<div class='content'>";
echo "<form class='form_edit' method='post' action='updatejob.php'>";
echo "<table id='job_list' cellpadding='0' cellspacing='0'>
<tr>
<th>Job No</th>
<th>Date</th>
<th>Qty</th>
<th>Postcode</th>
<th>Country</th>
<th>Packed by Scott</th>
<th>Packing Price</th>
<th>Courier Price</th>
<th>Tracking No</th>
<th>Dispatch Type</th>
<th>Job Status</th>
</tr>";
while($row = mysql_fetch_array($qry))
{
echo "<tr>";
echo "<td width='80' style='text-align: center;'>" . $row['order_ref'] . "</td>";
echo "<td width='100' style='text-align: center;'>" . $row['date'] . "</td>";
echo "<td width='100' style='text-align: center;'>" . $row['quantity'] . "</td>";
echo "<td width='100' style='text-align: center;'>" . $row['postcode'] . "</td>";
echo "<td width='100' style='text-align: center;'>" . $row['country'] . "</td>";
echo "<td width='100' style='text-align: center;'><input type='CHECKBOX' id='scott_packing' name='scott_packing' value='". $row['scott_packing'] . "'></td>";
echo "<td width='100' style='text-align: center;'><input type='text' id='packing_price' name='packing_price' value='". $row['packing_price'] . "'/></td>";
echo "<td width='100' style='text-align: center;'><input type='text' id='courier_price' name='courier_price' value='". $row['courier_price']."'/></td>";
echo "<td width='100' style='text-align: center;'><input type='text' id='tracking_number' name='tracking_number' value='". $row['tracking_number'] . "'/></td>";
echo "<td width='100' style='text-align: center;'>" . $row['dispatch_type'] . "</td>";
echo "<td width='100' style='text-align: center;'><select name='job_status' id='job_status'>
<option value='". $row['job_status'] ."'>". $row['job_status']. " <option value='dispatched'>Dispatched</td>";
//echo "<td width='100' style='text-align: center;'><a href='editjob.php'>edit</td>";
echo "</tr>";
}
echo "</table>";
echo "<input type='submit' name='submit' value='submit all'/>";
echo "</form>";
mysql_close();
?>
And here is the code that is supposed to update the data:
<?
session_start();
if(!session_is_registered(myusername)){
header("location:../index.php");
}
include("../template/header.php");
include("../controllers/cn.php");
if (isset($_POST['submit']))
{
$order_ref = $_POST['order_ref'];
$packing_price = $_POST['packing_price'];
$courier_price = $_POST['courier_price'];
$tracking_number = $_POST['tracking_number'];
$job_status = $_POST['job_status'];
$sql_qry = "UPDATE Jobs SET '$packing_price, $courier_price, $tracking_number, $job_status' WHERE order_ref = '$order_ref'";
$query = mysql_query($sql_query);
if(!$query)
{
die('Could not update data' .mysql_error());
} else
{
header("location: updatesuccess.php");
exit;
}
mysql_close();
}
?>
Your update query is wrong. The query of update should be like
UPDATE table_name SET field1=new-value1, field2=new-value2
[WHERE Clause]
In this case it will be something like
UPDATE Jobs SET packing_price='$packing_price',courier_price='$courier_price',tracking_number='$tracking_number',job_status='job_status' WHERE order_ref = '$order_ref'";
and also you missed out the name property for input fields. If you don't specify it you can't access it like $_POST['packing_price'] where packing_price is be the name of the input field.
Also add method="post" to the form like
echo "<form class='form_edit' action='updatejob.php' method='post'>";
Try with this query
$sql_qry = "UPDATE Jobs SET column1 = '$packing_price', column2 ='$courier_price', .... WHERE order_ref = '$order_ref'";
And like Roland Jansen stated you are missing the name attributes on your input tags
t
I have data shown about a band that matches a id selected, im then using the band_id and getting it to use it else where.
I would like to do the same with Name field but I am having a few problems, its just getting the word array in to the var $name.
code
<?php
require 'core/init.php';
$Band_id = $_GET['id'];
$name = ['Name']; // trying to get the band name
$result = mysql_query("SELECT * FROM bands WHERE Band_id = $Band_id");
echo "<table border = '1'>
<tr>
<th>Band Name</th>
<th>Venue</th>
<th>Category</th>
<th>Stock</th>
<th>Buy Ticket</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr><form name=\"myform\" action=\" order.php\" method=\"post\">";
echo " <input name=\"band\" type=\"hidden\" value=\"". $Band_id."\" >";
echo " <input name=\"bandn\" type=\"hidden\" value=\"". $name."\" >";
echo "<td>" .$row['Name']. "</td>";
echo "<td>" .$row['Venue']. "</td>";
echo "<td>" .$row['Category']. "</td>";
echo "<td>" .$row['Stock']. "</td>";
echo "<td><button>Buy Ticket</button></td>";
echo "</tr> </form>";
}
echo "</table>";
?>
$name = ['Name'] wont work above the query, and generally wont work at all as its invalid syntax for what you're trying to do. Where you have used $name use $row['Name']
I have working code that brings in data from my database as follows:
require("database.php");
$result = mysqli_query($con,"SELECT * FROM menuitem");
echo "<table width='1024' border='0' cellpadding='10' cellspacing='5' align='center'>
<tr>
<th></th>
<th>Menu Items</th>
<th>Description</th>
<th>Price</th>
<th>Add to Order</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'><img src=\"" . $row['picturepath'] . "\" /></td>";
echo "<td align='center'>" . $row['name'] . "</td> <td align='center'> <input type='button' value='More Info'; onclick=\"window.location='more_info.php?';\"> </td>";
echo "<td align='center'>" . $row['price'] . "</td> <td align='center'> <input type='button' value='Add to Order' onclick=''> </td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
However, the columns that I am calling have over 20 items. I want to limit the amount of items the page displays to 4 items per page, and then create multiple pages listing the remaining items in the database.
So far I have tried adding in the if then statement, but that didn't work very well. I'm not sure if that is even the correct way to go about it.
SELECT * FROM menuitem LIMIT $startPositionVariable,$howManyItemsPerPageVariable
a separate query should determine how many total entries there are to begin with and determine how many pages accordingly.