PHP MySQL not displaying all table rows - php

I'm new to programming and web development and stuff so for fun I've created a database of all my blurays/DVDs and created an html page with php to connect to the mysql database and then somebody enters their name and selects a year and it displays all the movies from the that year of release. This is all done locally. However, for some reason when its ran it does not display all rows. Sometimes it pulls only 1 row, sometimes it pull 2 or 3 rows. Just wondering if somebody can tell me what's wrong. I have two .php files. The form and the processor. The select statement I used works just fine in the MySQL console and displays all data correctly there. Lastly, I know that CSS could be put to better use here with alignments and table borders, etc., but that's not what I'm focused on right now.
Form
<?php
//variables
$strHost = "localhost";
$strUser = "root";
$strPass = "";
$strDB = "movies";
$strYear = "";
$intYearMin = 1900;
$intYearMax = 2025;
$dblYearIncrement = 1;
$strYearOptions = "";
//populate dropdown list
for ($i=$intYearMin; $i<=$intYearMax; $i+=$dblYearIncrement) {
$strYearOptions .= "<option value=\"$i\">$i</option> \n";
}
?>
<!DOCTYPE hmtl>
<html>
<head>
<title>My Movie Listing: The Form</title>
<!-- Link style sheet link rel="stylesheet" href="../styles/styleDefault.css" /> -->
<link rel="stylesheet" type="text/css" href="./movies.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
function Start(){
document.getElementByID("txtName").focus();
}
</script>
</head>
<body onload="Start();">
<h1>
My Movies <br />
<img src="./filmreel1.png" alt="Film Reel" width="68" height="60" />
</h1>
<h2> Movie listing by year: </h2>
<form action="movies_1_proc.php" method="post" id="frmSale">
<ul>
<li>Your name: <input size="30" name="txtName" id="txtName" /></li>
<li>
Year:
<select name="Year">
<option value="xxx">Choose . . . </option>
<?php echo $strYearOptions; ?>
</select>
</li>
</ul>
<p class="centered">
<input type="submit" name="cmdSubmit" value="See What's Available" />
</p>
</form>
<body>
<html>
Processor and displays results
<?php
//initialization
$strHost = "localhost";
$strUser = "root";
$strPass = "";
$strDB = "movies";
//get data from html form
$dblMaxYear = $_POST['Year'];
$strName = $_POST['txtName'];
$strTableBlock = "";
//build sql string based on form data
$strSQL = "SELECT * FROM movies WHERE Year = $dblMaxYear ORDER BY IF(LEFT(title,2) = 'A ',
SUBSTRING(title FROM 3),
IF(LEFT(title,3) = 'An ',
SUBSTRING(title FROM 4),
IF(LEFT(title,4) = 'The ',
SUBSTRING(title FROM 5),
title)))";
//create dbms connection and open db
$strConn = mysqli_connect($strHost,$strUser,$strPass,$strDB);
//submit a query
$strResult= mysqli_query($strConn,$strSQL);
//process query
$arrRow = mysqli_fetch_assoc($strResult);
/*echo "<br />$strResult<br />";*/
while ($strRow = mysqli_fetch_array($strResult)) {
$strYear = $strRow['Year'];
$strRuntime = $strRow['Runtime'];
$strTitle = $strRow['Title'];
$strDirector = $strRow['Director'];
$strFormat = $strRow['Format'];
$strRating = $strRow['Rating'];
$strGenre = $strRow['Genre'];
$strRTscore = $strRow['RTscore'];
$strTableBlock .= "
<tr>
<td>$strYear</td><td>$strTitle</td><td>$strDirector</td><td>$strRuntime</td><td>$strFormat</td><td>$strRating</td><td>$strGenre</td><td>$strRTscore</td>
</tr> \n";
}
//wrapup database processing
mysqli_free_result($strResult);
mysqli_close($strConn) or die("Crash");
//output formatting
$strMaxYear = $dblMaxYear;
?>
<!DOCTYPE hmtl>
<html xmlns="http://w3.org/1999/xhtml">
<head>
<title>My Movies Listing: The Processor</title>
<!-- Link style sheet link rel="stylesheet" href="../styles/styleDefault.css" /> -->
<link rel="stylesheet" type="text/css" href="./movies.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!--<style type="text/css">
table{
//margin:auto;
margin-left:auto;
margin-right:auto;
background-color:white;
}
.rightaling{
text-align:right;
}
</style>-->
</head>
<body>
<h1 align = "center">
My Movies <br />
<img src="./filmreel1.png" alt="Film Reel" width="68" height="60" />
</h1>
<h2 align = "center"> Movies From Year <?php echo $strMaxYear; ?> for <?php echo $strName; ?>:</h2>
<table border="2" align="center">
<tr><th>Year</th><th>Title</th><th>Director</th><th>Runtime</th><th>Format</th><th>Rating</th><th>Genre</th><th>RT%</th></tr>
<?php echo $strTableBlock ?>
</table>
<body>
<html>

Related

Trying to access certain information from database

I asked this question before but did not get any actual answers. I created a website for my wife's jewelry. She wants a product page for each style she makes (bracelets, necklaces, etc.).
I created the database with a category section that has all the different categories she makes. The only problem I have is I cannot get the information to show up on the product page. I get errors such as
Notice: Undefined variable: item_number in C:\xampp\htdocs\pinkys_pearls\bracelets.php on line 83.
Here is my code for the page:
<?php
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
?>
<?php
// Connect to the MySQL database
include_once("storescripts/connect_to_mysql.php");
$con = mysqli_connect("$db_host","$db_username","$db_pass","$db_name");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_errno());
exit();
//Initializing variable
$item_number = "item_number";
$description = "description";
$category = "category";
$price = "price";
$qty = "qty";
$sql = "SELECT category FROM products WHERE category='Bracelets';";
$result = mysqli_query($con, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
// get all the product details
while($row = mysqli_fetch_assoc($result)); {
echo $item_number = $row["item_number"];
$price = $row["price"];
$desc = $row["description"];
$category = $row["category"];
}
}
else {
echo "Data to render this page is missing.";
exit();
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Bracelets</title>
<meta charset="utf-8">
<meta http-equiv="x=UA-comparable" content="IE-edge">
<meta name="description" content="Pinky's Pearls is a website where one of a kind jewelry designed by Nichole <q>Nicki</q> can be seen and purchased">
<meta name="keywords" content="jewelry, beads, bracelets, rings, pendants, necklaces, pearls, crystal">
<meta name="viewpoint" content="width=device-width, initial-scale=1">
<meta name="author" content="samuel jaycox">
<link href="style.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="shortcut icon" type="image/png" href="pictures/pinky.png">
<script src="https://use.fontawesome.com/0c9491c5b9.js"></script>
</head>
<body>
<div align="center" id="wrapper">
<div id="banner-wrapper">
<!---Company Header-->
<header>
<div id="header">
<img class="bracelet_header" src="pictures/headers/bracelets.jpg" alt="Bracelets">
<audio autoplay="autoplay" loop="loop" id="background-music">
<source src="music/Albinoni-adagio-in-g-minor-acoustic-guitar.mp3" type="audio/mpeg">
<source src="music/Albinoni-adagio-in-g-minor-acoustic-guitar.wav" type="audio/wav">
</audio>
</div>
</header>
<!---end of Company Header-->
<br>
<?php include_once("templates/template_navigation.php"); ?>
<br>
<br>
<br>
<!--Start Comment page Body Content-->
<div id="body-content">
<div class="bracelet_body">
<table width="100%" border="2" cellspacing="0" cellpadding="15">
<tr>
<td width="19%" valign="top">
<img src="pictures/inventory/<?php echo $pid; ?>.png" width="142" height="188" alt="<?php echo $item_number; ?>" /><br />
View Full Size Image
</td>
<td width="81%" valign="top">
<h3><?php echo $item_number; ?></h3>
<p><?php echo "$".$price; ?>
<br /><br />
<?php echo $desc; ?>
<br />
</p>
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />
<input class="button" type="submit" name="button" id="button" value="Add to Shopping Cart" />
</form>
</td>
</tr>
</table>
</div>
</div>
<!--end of Comment body-->
<?php include_once("templates/template_footer.php"); ?>
</body>
</html>
What can I do to fix this?
You are missing a closing curly bracket at a critical point -
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_errno());
exit();
// RIGHT HERE
//Initializing variable
$item_number = "item_number";
$description = "description";
$category = "category";
With out it, none of your variables are initialized, your SQL query is never run, etc.
Once you've fixed that, try again and if there are still related issues edit the question, otherwise start a new question for a new issue.

Session Variables in Datatables Plugin

I am creating a PHP/MySQL based application and it need to be able to carry over session variables into the DataTable plugin I use on a page in my app. The application is rather complicated, so I will explain how it works before I ask specific questions.
On index.php, there is a dropdown menu that shows the departments that use this application within my organization. The department list is generated by a mySQL table that has their department name and department code. The $dept variable stores the department code value from the selected option in the dropdown menu on submit. In turn, the $_SESSION["department"] variable stores $dept and redirects to the checkin page if successful.
<?php
require_once('connection.php');
session_start();
if (isset($_POST['submit']))
{
$dept = $_POST['dept'];
$_SESSION["department"] = $dept;
header("Location: checkin.php");
}
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Visitor Management</title>
<link rel="stylesheet" href="css/foundation.min.css" />
<link rel="stylesheet" href="css/app.css" />
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/24365087-b739-4314-af6e-741946b60bef.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/b05259d9-ca62-44a8-8a19-d3facdbd64df.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/2603d516-f938-4b52-ae3a-11d25bb4c555.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/510266cf-74ab-4fa8-9b39-dd37b90d6ab0.css"/>
</head>
<body>
<!-- nav -->
<div class="top-bar">
<div class="top-bar-left">
<ul class="menu">
</ul>
</div>
<div class="top-bar-right">
</div>
</div>
<div class="row text-center" style="margin-top: 5%;">
<h1>Syracuse University</h1>
<h2>Visitor Management</h2>
<br/>
<form id="dept" method="post" name="dept">
<?php
echo "<select name='dept'>";
echo '<option>'.'Please select a department'.'</option>';
$query = mysqli_query($VisitorManagement, "SELECT * FROM departments");
while($row=mysqli_fetch_array($query))
{
echo "<option value='". $row['code']."'>".$row['name']
.'</option>';
}
echo '</select>';
?>
<input type="submit" class="button" value="Submit" name="submit">
</form>
</div>
<script src="js/vendor/jquery.min.js"></script>
<script src="js/vendor/what-input.min.js"></script>
<script src="js/foundation.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
The session variable is then carried throughout the site and is used to determine which table needs to be shown. For instance, in checkin.php, we need to display staff members in a dropdown list. We have multiple tables based on the departments using the application. One table we have is called ts_staff If the session variable is stored as the string ts, we do the following steps to make sure the app is connecting to the right database:
We store the session variable from index.php into a global variable on checkin.php $dept = $_SESSION[department];
We create another new variable to concatenate the global variable and the _staff string which is used in all our mySQL staff tables: $staffTable = $dept . "_staff";
Lastly, we use the $staffTable variable as the database table that needs to be displayed: $query = mysqli_query($VisitorManagement, "SELECT * FROM {$staffTable}");
Here's the full checkin.php code:
<?php
// connect to database
require_once('connection.php');
session_start();
//get session variable, if empty, unset and logout
if(empty($_SESSION['department'])) {
session_unset();
session_destroy();
header("Location: index.php");
} else {
$dept = $_SESSION[department];
}
//submit values on submit
if (isset($_POST['submit']))
{
// store form data values
$suid = mysqli_real_escape_string($VisitorManagement, $_POST['suid']);
$staff = mysqli_real_escape_string($VisitorManagement, $_POST['staff']);
$checkinTable = $dept . "_checkin";
// insert varaibles into table rows
$sql = "INSERT INTO {$checkinTable} (suid, staffMember) VALUES ('$suid', '$staff')";
// check if row was inserted correctly
if (mysqli_query($VisitorManagement, $sql)) {
header('Location: thank-you.php');
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($VisitorManagement);
}
}
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Visitor Management</title>
<link rel="stylesheet" href="css/foundation.min.css" />
<link rel="stylesheet" href="css/app.css" />
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/24365087-b739-4314-af6e-741946b60bef.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/b05259d9-ca62-44a8-8a19-d3facdbd64df.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/2603d516-f938-4b52-ae3a-11d25bb4c555.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/510266cf-74ab-4fa8-9b39-dd37b90d6ab0.css"/>
</head>
<body>
<!-- nav -->
<div class="top-bar">
<div class="top-bar-left">
<ul class="menu">
<li>Check-In</li>
</ul>
</div>
<div class="top-bar-right">
<ul class="menu">
<li>Admin Login</li>
<li>Logout</li>
</ul>
</div>
</div>
<div class="row text-center" style="margin-top: 5%;">
<h1>Syracuse University</h1>
<!-- replace with whatever department they select -->
<h2>Technical Services</h2>
</div>
<div class="row">
<form id="checkin" method="post" name="checkin">
<div class="row">
<div class="medium-12 columns">
<label>Please Swipe Your SUID Card
<input type="text" placeholder="SUID Number Here" id="suid" name="suid" required>
</label>
</div>
<div class="medium-12 columns">
<label>Who Are You Here to See?
<?php
$staffTable = $dept . "_staff";
echo "<select name='staff'>";
echo '<option value="">'.'Please select a staff member'.'</option>';
$query = mysqli_query($VisitorManagement, "SELECT * FROM {$staffTable}");
while($row=mysqli_fetch_array($query))
{
echo "<option value='". $row['fullName']."'>".$row['fullName']
.'</option>';
}
echo '</select>';
// close connection
mysqli_close($VisitorManagement);
?>
</label>
</div>
<div class="medium-12 columns">
<input type="submit" class="button" value="Submit" name="submit">
</div>
</div>
</form>
</div>
<script src="js/vendor/jquery.min.js"></script>
<script src="js/vendor/what-input.min.js"></script>
<script src="js/foundation.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
The problem is that on reports.php, I am using the DataTables plugin to dynamically organize and filter a table, but I need to be able to carry the session variable over into the plugin so it knows to organize the specific table based on what the user selected on the index.php screen.
reports.php just calls DataTables and using another page, response.php to turn the data from the table into JSON to be displayed. Here's reports.php:
<?php session_start();
if(empty($_SESSION['department'])) {
session_unset();
session_destroy();
header("Location: index.php");
} else {
$dept = $_SESSION[department];
}
$checkinTable = $dept . "_checkin";
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Visitor Management</title>
<link rel="stylesheet" href="../css/foundation.min.css" />
<link rel="stylesheet" href="../css/app.css" />
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/24365087-b739-4314-af6e-741946b60bef.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/b05259d9-ca62-44a8-8a19-d3facdbd64df.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/2603d516-f938-4b52-ae3a-11d25bb4c555.css"/>
<link type="text/css" rel="stylesheet" href="http://fast.fonts.net/cssapi/510266cf-74ab-4fa8-9b39-dd37b90d6ab0.css"/>
<link type="text/css" rel="stylesheet" href="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.css"/>
</head>
<body>
<?php
if (!isset($_SESSION['user'])) {
header("Location: ../login.php"); // If session is not set that redirect to Login Page
}
?>
<div class="top-bar admin">
<div class="top-bar-left">
<ul class="menu">
<li class="menu-text">Visitor Management</li>
</ul>
</div>
<div class="top-bar-right">
<ul class="menu">
<li>Logout</li>
<li>Help</li>
</ul>
</div>
</div>
<div class="medium-2 columns dash">
<ul>
<li>Dashboard</li>
<li>Staff</li>
<li class="active">Reports</li>
</ul>
</div>
<div class="medium-10 columns">
<div class="row checkin">
<h2>Reports</h2>
<table class="checkin" id="checkin">
<thead>
<tr>
<th>ID</th>
<th>SUID #</th>
<th>Staff Member</th>
<th>Student Name</th>
<th>Student Email</th>
<th>Check In Date/Time</th>
</tr>
</thead>
</table>
<!--<div class="float-left">
Export to Excel
</div>
<div class="float-right">
</div>-->
</div>
</div>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script src="../js/vendor/what-input.min.js"></script>
<script src="../js/foundation.min.js"></script>
<script src="../js/app.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.js"></script>
<script>
$(document).ready(function() {
$('#checkin').DataTable({
"bProcessing": true,
"serverSide": false,
"dom": 'lBfrtip',
"buttons": [
{
extend: 'collection',
text: 'Export',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
],
"ajax":{
url :"response.php", // json datasource
type: "post", // type of method ,GET/POST/DELETE
data: {}
}
});
});
</script>
</body>
</html>
Here's response.php:
<?php
//include connection file
include_once("../connection.php");
// initilize all variable
$params = $columns = $totalRecords = $data = array();
$params = $_REQUEST;
//define index of column
$columns = array(
0 => 'id',
1 => 'suid',
2 => 'staffMember',
3 => 'studentName',
4 => 'studentEmail',
5 => 'checkinDateTime'
);
$where = $sqlTot = $sqlRec = "";
// check search value exist
if( !empty($params['search']['value']) ) {
$where .=" WHERE ";
$where .=" ( studentName LIKE '".$params['search']['value']."%' ";
$where .=" OR staffMember LIKE '".$params['search']['value']."%' ";
$where .=" OR studentEmail LIKE '".$params['search']['value']."%' ";
$where .=" OR suid LIKE '".$params['search']['value']."%' ";
$where .=" OR checkinDate LIKE '".$params['search']['value']."%' )";
}
// getting total number records without any search
$sql = "SELECT id, suid, staffMember, studentName, studentEmail, date_format(checkinDateTime, '%b %d, %Y, %h:%i %p') as checkinDateTime FROM `ts_checkin`";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '') {
$sqlTot .= $where;
$sqlRec .= $where;
}
//$sqlRec .= " ORDER BY ". $columns[$params['order'][0]['column']]." ".$params['order'][0]['dir']." LIMIT ".$params['start']." ,".$params['length']." ";
$queryTot = mysqli_query($VisitorManagement, $sqlTot) or die("database error:". mysqli_error($VisitorManagement));
$totalRecords = mysqli_num_rows($queryTot);
$queryRecords = mysqli_query($VisitorManagement, $sqlRec) or die("error to fetch check-in data");
//iterate on results row and create new index array of data
while( $row = mysqli_fetch_row($queryRecords) ) {
$data[] = $row;
}
$json_data = array(
"draw" => intval( $params['draw'] ),
"recordsTotal" => intval( $totalRecords ),
"recordsFiltered" => intval($totalRecords),
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
?>
In response.php, I need to able to replace ts_checkin, which is shown on this line:
$sql = "SELECT id, suid, staffMember, studentName, studentEmail, date_format(checkinDateTime, '%b %d, %Y, %h:%i %p') as checkinDateTime FROM `ts_checkin`";`
with a variable called $checkinTable that would concatenate similar to how checkin.php does with the staff table. So essentially I would like to have $checkinTable = $dept . "_checkin" with $dept equaling the value of the session variable.
When I go to do this, I get this error from DataTables: DataTables warning: table id=checkin - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
Is it possible to get this working? I would like to keep DataTables as its the best way to achieve on-the-fly table filtering, searching, and sorting (plus it's a highly requested feature by our departments). But I need to be able to set the table based on the session variable.
I apologize for the length of this question. If there needs to be clarification, let me know.
I'm not certain to understand the question...
Are you saying this is not working ?
Did you try it written like this?
(notice the space after FROM. It is necessary!)
$checkinTable = $dept . "_checkin";
$sql = "SELECT id, suid, staffMember, studentName, studentEmail, date_format(checkinDateTime, '%b %d, %Y, %h:%i %p') as checkinDateTime FROM " . $checkinTable;
For sure, $dept has also to be defined.
And the resulting $checkinTable has to be an existing table name.
Ok...
This looks to be missing in your response.php:
session_start();
$dept = $_SESSION[department];
$checkinTable = $dept . "_checkin";

Dynamically generated "submit" buttons in PHP

First time posting here (so please be gentle, as I am a relative PHP newbie).
I am building an intranet for our company and one of the things I need to do is to create a form that lists all outstanding sales orders (pulled from our accounting database) and provides a "submit" button beside each one to create the relevant work order.
Here is the code:
<div class="report_column">
<div class="report_header">
<div class="report_column_title" style="width:150px;margin-left:5px">ship date</div>
<div class="report_column_title" style="width:200px">customer</div>
<div class="report_column_title" style="width:140px;text-align:right">item</div>
<div class="report_column_title" style="width:120px;text-align:right">quantity</div>
</div>
<?php
// Open connection
include 'includes/dbconnect.php';
// Perform query
$result = mysqli_query($con,"SELECT * FROM tSalOrdr ORDER BY dtShipDate ASC");
// Retrieve results
while($row = mysqli_fetch_array($result)) {
$order = $row['lId'];
if ($row['bCleared'] == 0) {
$shipdate = substr($row['dtShipDate'], 0,10);
$customer = $row['sName'];
$po = $row['sComment'];
echo '<div class="report_item" style="width:750px";>';
echo '<form class="form" action="index.php?page=form&item=create_work_order" method="POST">';
echo '<div class="report_item_date" style="width:120px">'.$shipdate.'</div>';
echo '<div class="report_item_name" style="width:530px">'.$customer;
echo '<input type="hidden" name="po" value="'.$po.'" />';
echo '<input type="submit" class="submit" style="height: 25px;width:100px;margin:0px;padding:0px;margin:0px" value="work order"/>';
echo '</div>';
$result2 = mysqli_query($con,"SELECT * FROM tSOLine WHERE lSOId=$order ORDER BY sDesc ASC");
while($row = mysqli_fetch_array($result2)) {
if ($row['dRemaining'] <> 0) {
echo '<div class="report_item_details">';
echo '<div class="report_item_item">'.$row['sDesc'].'</div>';
echo '<div class="report_item_quantity">'.$row['dRemaining'].'</div>';
echo '</div>';
}
}
echo '</form>';
echo '</div>';
}
}
// Close connection
mysqli_close($con);
?>
</div>
What happens when I do this is that the first "submit" button will, for some reason, send me back to "index.php". The other buttons will load the correct page, however, they do not POST the required value.
Is there something I am doing wrong or is this something that needs different methodology than what I am currently using? My research on this seems to indicate that perhaps I should use javascript or an array to deal with this, but, having never dealt with either, I am not sure how to proceed. Any pointers would be appreciated.
Thanks.
#maniteja: The index.php is as follows:
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<title></title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<link href="css/forms.css" rel="stylesheet" type="text/css" />
<link rel="icon" type="image/ico" href="favicon.ico" />
<script type="text/javascript" src="scripts/jquery-2.1.0.min.js" ></script>
<script type="text/javascript" src="scripts/tabcontent.js" ></script>
</head>
<body>
<!-- BEGIN MAIN CONTENT -->
<div id="wrapper">
<!-- BEGIN HEADER -->
<div id="header">
<img src="images/logo.jpg">
</div>
<!-- END HEADER -->
<!-- BEGIN MAIN MENU -->
<div id="leftcolumn">
<?php include 'includes/menu.php'; ?>
</div>
<!-- END MAIN MENU -->
<!-- BEGIN CONTENT FRAME -->
<div id="rightcolumn">
<div id="content_area">
<?php
if (isset($_GET['page']))
{$page = $_GET['page'];
include('pages/' . $page . '.php');}
else {include('pages/home.php');}
?>
</div>
</div>
<!-- END MAIN CONTENT -->
</body>
</html>
I've made seventeen other forms with it, so I don't think that it is the problem. I'm hoping that this is just a typo or a logic error on my part.
u can use
<button type='submit' class='' name='' onclick=''>Submit</button>
Try to do onclick. See my example below.
input type="button" name="submit" onclick='location.href="index.php?id=$id"'
AS far as I understand, you are making your forms go to index.php:
echo '<form class="form" action="index.php?page=form&item=create_work_order" method="POST">';
Can you explain what is your expected behavior when a button is pushed?

Turning data retrieved from mysql database into chart

For some reason my chart will not load up . The user enters a date , php send query to mysql that recieves data and displays a table, underneath that table i want a chart to be displayed using the google API's. Can someone please help here is my code.
<!doctype html>
<html>
<head>
<!-- links to scripit for jquery drop down calendar -->
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src= "//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<!-- links to CSS style sheets -->
<link href="styles/main.css" rel="stylesheet" type="text/css">
<link href="styles/date.css" rel="stylesheet" type="text/css">
<link href="styles/date2.css" rel="stylesheet" type="text/css">
<meta charset="utf-8">
<title>Cartridge Details</title>
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.-->
<script>var __adobewebfontsappname__="dreamweaver"</script>
<script src="http://use.edgefonts.net/short-stack:n4:default;abel:n4:default;annie-use- your-telescope:n4:default.js" type="text/javascript"></script>
</head>
<!-- php connection to database to query table for Cartridge Details -->
<?php
$username = "root";
$password = "*******";
$hostname = "localhost";
$my_db = "print_consump";
//connection to the database
$dbhandle = mysqli_connect($hostname, $username, $password, $my_db)
or die("Unable to connect to MySQL");
echo "cond";
?>
<body>
<div class="divH">
<header id="heading1">Cartridge Details</heade>
</div>
<div class="LinkedPages">
<form method="post" action="cartridgedetails.php" name="frm1">
<div>
Date:<input type="text" name="YEAR" value="Enter Year (i.e '2013')">
<input type="submit" value="submit">
</div>
</form>
<span></span>
<?php
//formula for toner usage total pages/35000 = #toner used for month
if(isset($_POST["YEAR"])) {
$year = $_POST['YEAR'];
$result = mysqli_query($dbhandle,"SELECT `Servers`, `Total Pages` / 35000 FROM summaryofserver WHERE
RIGHT(Servers,4) = '$year'");
$data = array(array('Server, Month, Year', 'Number of Toner Cartridges Used'));
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "</tr>";
$data[] = array($row[0], $row[1]);
}
}
?>
<script>
function drawChart () {
var data = google.visualization.arrayToDataTable(<?php echo json_encode($data, JSON_NUMERIC_CHECK); ?>);
// draw a ColumnChart
// you can change this to whatever chart type you need
var chart = new google.visualization.ColumnChart(document.querySelector('#myChart'));
chart.draw(data, {
// chart options, eg:
height: 400,
width: 600
});
}
google.load('visualization', '1', {packages: ['corechart'], callback: drawChart});
</script>
<div id="myChart"></div>
</div>
</body>
</html>

The PHP code stops after the > in the if statement

For some reason my html stops recognizing the code for php after the first and second >, at the point marked with the comment code stops here.
The meaning for this that I need to get a picture from the database and then show it on the website as a header. I am very new to PHP and HTML. I am using phpmyadmin and sublimetext. the database is called stickerdome with the table images. in images there are 3 columns: id, name, link.
This is my code:
<head>
<?php
//Database Connect
$connect = mysql_connect("localhost","root","");
//Database Select
$db = mysql_select_db("stickerdome",$connect);
?>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title> StickerDome </title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="banner">
<?php
//Query
$query1 = mysql_query("SELECT * FROM images WHERE id = 1");
$num = mysql_num_rows($query1);
if ($num > 0) // code stops here right after the >
{
while ($output1 = mysql_fetch_assoc($query1))
{
$src = $output1['link'];
echo "<img src='".$src."' alt='Image1'>"; //code stops here right after the > for the second time
}
}
else
{
echo "No picture found.";
}
?>
</div>
This is the file in total:
<!DOCTYPE html>
<html>
<head>
<?php
//Database Connect
$connect = mysql_connect("localhost","root","");
//Database Select
$db = mysql_select_db("stickerdome",$connect);
?>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title> StickerDome </title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="banner">
<?php
//Query
$query1 = mysql_query("SELECT * FROM images WHERE id = 1");
$num = mysql_num_rows($query1);
if ($num IS NOT NULL)
{
while ($output1 = mysql_fetch_assoc($query1))
{
$src = $output1['link'];
echo "<img src='".$src."' alt='Image1'>";
}
}
else
{
echo "No picture found.";
}
?>
</div>
<div id="navigation">
<ul>
<li>
<a class="first" href="index.html">StickerDome</a>
</li>
<li>
<a class="second" href="samplepack.html">Sample Pack</a>
</li>
<li>
<a class="second" href="contact.html">Contact</a>
</li>
</ul>
</div>
<div id="pagename"><img src="Stickedomepagename.png"></div>
<div id="text">
<h1>Welcome to Stickerdome</h1>
<p class="text">Stickerdome is a website that gives you the best stickers you could ever imagine. It gives you <br>
- the best quality for every sticker <br>
- the best endurance that is usable outside <br>
- the biggest assortment <br>
<br>
For several years stickers started to became more popular. Everyone starting loving stickers. You can place them almost everywhere imaginable. But there is still one thing that nobody had and that is their own stickers. Yes, your own stickers! You can design your own stickers, send them to us, and we make sure that your stickers will be on your doormat within 5 days! Every design is possible, from round to square to with a border or without. You say it we make it!
</p>
</div>
</body>
<footer>
<p class="footer"> Stickerdome 2014 | Netherlands</p>
</footer>
</html>
you could try a different method or debug your sql.
Since i see your dutch im providing you with a link to a tutorial which greatly helped me the first time i worked with sql. maybe if you follow it you can fix your problem.
http://www.phphulp.nl/php/tutorial/overig/pdo-verbinden-met-verschillende-databases/534/inleiding/1364/

Categories