I have a mistake in my database .. It is written that there is undefined index from line 41 until 50 in the code .. In my website I tried to insert data from a form to the PhpMyAdmin database and everything is working fine except this...
The error is :
Notice: Undefined index: Services in C:\xampp\htdocs\ers\Database.php on line 41 - 50
Database.php :
<html>
<body>
<?php
$con = mysql_connect("localhost","root","123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
<table border="1">
<tr >
<td>Finding</td>
<td>ServiceType</td>
<td>Title</td>
<td>RootCause</td>
<td>RiskRating</td>
<td>Impact</td>
<td>Efforts</td>
<td>Likelihood</td>
<td>Finding</td>
<td>Implication</td>
<td>Recommendation</td>
<td>Report</td>
</tr>
<?php
mysql_select_db ( "ers_1", $con);
$sql="INSERT INTO findings (ServiceType_ID, Title, RootCause_ID, RiskRating_ID, Impact_ID, Efforts_ID, Likelihood_ID, Finding,Implication, Recommendation, Report_ID) VALUES (
'$_POST[Services]',
'$_POST[title]',
'$_POST[RootCause]',
'$_POST[RiskRating]',
'$_POST[impact]',
'$_POST[Efforts]',
'$_POST[likelihood]',
'$_POST[Finding]',
'$_POST[Implication]',
'$_POST[Recommendation]',
'1'
)";
$result = mysql_query("SELECT * FROM findings");
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $row['Finding_ID'] . "</td>";
echo "<td>" . $row['ServiceType_ID'] . "</td>";
echo "<td>" . $row['Title'] . "</td>";
echo "<td>" . $row['RootCause_ID'] . "</td>";
echo "<td>" . $row['RiskRating_ID'] . "</td>";
echo "<td>" . $row['Impact_ID'] . "</td>";
echo "<td>" . $row['Efforts_ID'] . "</td>";
echo "<td>" . $row['Likelihood_ID'] . "</td>";
echo "<td>" . $row['Finding'] . "</td>";
echo "<td>" . $row['Implication'] . "</td>";
echo "<td>" . $row['Recommendation'] . "</td>";
echo "<td>" . $row['Report_ID'] . "</td>";
//echo "<td><a href='edit.php'>[EDIT]</a> <a href='delete_risk.php?risk_no=" . $row['risk_no'] . "'>[DELETE]</a></td>";
echo "</tr>";
}
mysql_close($con);
?>
<input type="button" value="Back" onclick="window.location.href='option_Frame.php'" />
</body>
</html
>
It sounds like $_POST['Services'] was not posted rather than this being a database issue.
Check your HTML; there is probably no input element with name="Services".
Related
Currently stuck trying to configure a php page to update a MySQL database row "orderStatus" by checking one or more checkboxes. It should update the orderStatus of the selected row(s) to "validated" once the form is submitted. It's updating only the first row of the table likely due to $orderID = $_POST['id']; in the validate.php snippet. What I tried to do is retrieve all the orderIDs of the rows that have been checked and assign it to the variable/array $orderID, so that the orderStatus is changed only for those rows.
Here is the HTML:
<html>
<header>
<title>Validate an Order</title>
</header>
<body>
<h1>Validate an Order</h1>
<h4>Showing all unvalidated orders.</h4>
<br/>
<?php
$con=mysqli_connect("***","***","***","***");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM orders WHERE orderStatus = 'processing' ORDER BY orderDate DESC");
echo "<table border='1'>
<tr>
<th>Validate?</th>
<th>OrderID</th>
<th>OrderDate</th>
<th>OrderShipDate</th>
<th>OrderType</th>
<th>OrderMedia</th>
<th>OrderContent</th>
<th>OrderStatus</th>
<th>OrderQuantity</th>
<th>OrderCost</th>
<th>OrderDeposit</th>
<th>OrderDesc</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<form action='validate.php' method='post'><input type='hidden' name='id' value='".$row['orderID']."'><input type='checkbox' name='validate[]' value='validated'>" . "</td>";
echo "<td>" . $row['orderID'] . "</td>";
echo "<td>" . $row['orderDate'] . "</td>";
echo "<td>" . $row['orderShipDate'] . "</td>";
echo "<td>" . $row['orderType'] . "</td>";
echo "<td>" . $row['orderMedia'] . "</td>";
echo "<td>" . $row['orderContent'] . "</td>";
echo "<td>" . $row['orderStatus'] . "</td>";
echo "<td>" . $row['orderQuantity'] . "</td>";
echo "<td>" . $row['orderCost'] . "</td>";
echo "<td>" . $row['orderDeposit'] . "</td>";
echo "<td>" . $row['orderDesc'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<input type='submit' name='submit' value='Submit'></form>";
mysqli_close($con);
?>
</body>
</html>
And here is the PHP for the form:
<?php
$con=mysqli_connect("***","***","***","***");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$orderID = $_POST['id'];
if(isset($_POST['validate'])){
foreach($_POST['validate'] as $validate){
mysqli_query($con,"UPDATE orders SET orderStatus = '$validate' WHERE orderID = $orderID");
}
}
mysqli_close($con);
?>
Here's what the page looks like.
Validate an Order
Any help is appreciated!
Problem is Form is inside while loop.When you're using with you need to either put the tags completely outside the , or have the entire inside one . Any other structure breaks the syntax of the and will be ignored by the browser, or rendered incorrectly.
Please try this
<html>
<header>
<title>Validate an Order</title>
</header>
<body>
<h1>Validate an Order</h1>
<h4>Showing all unvalidated orders.</h4>
<br/>
<?php
$con=mysqli_connect("***","***","***","***");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM orders WHERE orderStatus = 'processing' ORDER BY orderDate DESC");
echo "<form action='validate.php' method='post'>
<table border='1'>
<tr>
<th>Validate?</th>
<th>OrderID</th>
<th>OrderDate</th>
<th>OrderShipDate</th>
<th>OrderType</th>
<th>OrderMedia</th>
<th>OrderContent</th>
<th>OrderStatus</th>
<th>OrderQuantity</th>
<th>OrderCost</th>
<th>OrderDeposit</th>
<th>OrderDesc</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . "<input type='hidden' name='id' value='".$row['orderID']."'><input type='checkbox' name='validate[]' value='validated'>" . "</td>";
echo "<td>" . $row['orderID'] . "</td>";
echo "<td>" . $row['orderDate'] . "</td>";
echo "<td>" . $row['orderShipDate'] . "</td>";
echo "<td>" . $row['orderType'] . "</td>";
echo "<td>" . $row['orderMedia'] . "</td>";
echo "<td>" . $row['orderContent'] . "</td>";
echo "<td>" . $row['orderStatus'] . "</td>";
echo "<td>" . $row['orderQuantity'] . "</td>";
echo "<td>" . $row['orderCost'] . "</td>";
echo "<td>" . $row['orderDeposit'] . "</td>";
echo "<td>" . $row['orderDesc'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "<input type='submit' name='submit' value='Submit'>"
. "</form>";
mysqli_close($con);
?>
</body>
</html>
Thanks all! I wound up changing the input checkbox tag in the HTML to: <input type="checkbox" name="vid[]" id="validate" value='.$row['orderID'].' This grabs the orderIDs of those rows selected into the vid[] array.
Then in validate.php, the query sets the status to "validate" using $vid from foreach():
// if the vid array exists
if(isset($_POST['vid'])) {
// Loop through vid array "containing orderIDs" and set orderStatus to "validated" only for those orderIDs
foreach($_POST['vid'] as $vid) {
mysqli_query($con,"UPDATE orders SET orderStatus = 'validated' WHERE orderID = '$vid'");
}
}
I am trying to produce a spreadsheet like page - right now ive got the information from the database being displayed and an additional page allowing the user to add information.
I cannot understand how i would call the database to display a set row. I am not running an AI id so that is out the question. I tried to implement one after but it resulted in my code not working and giving me a blank white page.
Here is the code i am using to display the database:
<?php
$link = mysql_connect('', '', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//connect to the database
mysql_select_db('');
//query the database
$query = mysql_query("SELECT * FROM ");
echo "<table border='1'>
<tr>
<td class='td'>Date</td>
<td class='td'>Region</td>
<td class='td'>Cameraman</td>
<td class='td'>Livestream?</td>
<td class='td'>Event Title</td>
<td class='td'>Lecturer</td>
<td class='td'>Time</td>
<td class='td'>Speaker</td>
<td class='td'>ICE Contact</td>
<td class='td'>Venue Address</td>
<td class='td'>Venue Contact</td>
<td class='td'>Additional Comments</td>
<td class='td'>On App?</td>
<td class='td'>Edit</td>
<td class='td'>Delete</td>
</tr>";
WHILE($rows = mysql_fetch_array($query)):
$rows = array_filter($rows);
if (!empty($rows)) {
echo "<tr>";
echo "<td>" . $rows['date'] . "</td>";
echo "<td>" . $rows['region'] . "</td>";
echo "<td>" . $rows['cameraman'] . "</td>";
echo "<td>" . $rows['livestream'] . "</td>";
echo "<td>" . $rows['eventitle'] . "</td>";
echo "<td>" . $rows['lecturer'] . "</td>";
echo "<td>" . $rows['time'] . "</td>";
echo "<td>" . $rows['speaker'] . "</td>";
echo "<td>" . $rows['icecontact'] . "</td>";
echo "<td>" . $rows['venueaddress'] . "</td>";
echo "<td>" . $rows['venuecontact'] . "</td>";
echo "<td>" . $rows['additionalcomments'] . "</td>";
echo "<td>" . $rows['onapp'] . "</td>";
echo "<td><img src=""></td>";
echo "<td><img src=""></td>";
echo "</tr>";
}
endwhile;
echo "</table>";
?>
Any help would be appreciated.
Thanks
There was a quotes mismatch in the third last and second last line of the if block where you used double quotes within the double quotes which causes for syntax error. Here outer double quotes is replace with single quotes. Update the if block like this:
if (!empty($rows)) {
echo "<tr>";
echo "<td>" . $rows['date'] . "</td>";
echo "<td>" . $rows['region'] . "</td>";
echo "<td>" . $rows['cameraman'] . "</td>";
echo "<td>" . $rows['livestream'] . "</td>";
echo "<td>" . $rows['eventitle'] . "</td>";
echo "<td>" . $rows['lecturer'] . "</td>";
echo "<td>" . $rows['time'] . "</td>";
echo "<td>" . $rows['speaker'] . "</td>";
echo "<td>" . $rows['icecontact'] . "</td>";
echo "<td>" . $rows['venueaddress'] . "</td>";
echo "<td>" . $rows['venuecontact'] . "</td>";
echo "<td>" . $rows['additionalcomments'] . "</td>";
echo "<td>" . $rows['onapp'] . "</td>";
echo '<td><img src=""></td>';
echo '<td><img src=""></td>';
echo "</tr>";
}
I seem to be having an issue with my HTML formatting. I am calling the database to display all information within the table on a webpage. I have got the information coming down into the table. Unfortunately the table is adding an additional row to the bottom of the table making 4 rows when in fact there is only 3 rows displaying in the database.
Any idea as to why?
<?php
//connect to the server
$link = mysql_connect('*****', '*****', '****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('******');
$query = mysql_query("SELECT * FROM tablename");
echo "<table border='1'>
<tr>
<td>Date</td>
<td>Region</td>
<td>Cameraman</td>
<td>Livestream?</td>
<td>Event Title</td>
<td>Lecturer</td>
<td>Time</td>
<td>Speaker</td>
<td>ICE Contact</td>
<td>Venue Address</td>
<td>Venue Contact</td>
<td>Additional Comments</td>
<td>On App?</td>
</tr>";
WHILE($rows = mysql_fetch_array($query)):
echo "<tr>";
echo "<td>" . $rows['date'] . "</td>";
echo "<td>" . $rows['region'] . "</td>";
echo "<td>" . $rows['cameraman'] . "</td>";
echo "<td>" . $rows['livestream'] . "</td>";
echo "<td>" . $rows['eventitle'] . "</td>";
echo "<td>" . $rows['lecturer'] . "</td>";
echo "<td>" . $rows['time'] . "</td>";
echo "<td>" . $rows['speaker'] . "</td>";
echo "<td>" . $rows['icecontact'] . "</td>";
echo "<td>" . $rows['venueaddress'] . "</td>";
echo "<td>" . $rows['venuecontact'] . "</td>";
echo "<td>" . $rows['additioncomments'] . "</td>";
echo "<td>" . $rows['onapp'] . "</td>";
echo "</tr>";
endwhile;
echo "</table>";
?>
I have added the link to the page below.
http://cpdonline.tv/spreadsheet/spreadsheet.php
Update your while loop with the following:
WHILE($rows = mysql_fetch_array($query)):
$rows = array_filter($rows);
if (!empty($rows)) {
echo "<tr>";
echo "<td>" . $rows['date'] . "</td>";
echo "<td>" . $rows['region'] . "</td>";
echo "<td>" . $rows['cameraman'] . "</td>";
echo "<td>" . $rows['livestream'] . "</td>";
echo "<td>" . $rows['eventitle'] . "</td>";
echo "<td>" . $rows['lecturer'] . "</td>";
echo "<td>" . $rows['time'] . "</td>";
echo "<td>" . $rows['speaker'] . "</td>";
echo "<td>" . $rows['icecontact'] . "</td>";
echo "<td>" . $rows['venueaddress'] . "</td>";
echo "<td>" . $rows['venuecontact'] . "</td>";
echo "<td>" . $rows['additioncomments'] . "</td>";
echo "<td>" . $rows['onapp'] . "</td>";
echo "</tr>";
}
endwhile;
echo "</table>";
array_filter() function's default behavior will remove all values from array which are equal to null, 0, '' or false.
It seems that you have empty data in your database, as many lines are empty
Check your database for empty records or run the query
DELETE FROM table_name WHERE column='';
i need list something like this.
First table is display By using the this code.
<?php
if (isset($_REQUEST['asign'])) {
include 'includes/connection.php';
$sql12= $cid->query("SELECT name FROM user WHERE designation='Technical' AND status='1'");
$query = "SELECT * FROM allinone WHERE flag=3 ORDER BY id ASC";
$rs = $cid -> query($query);
$n = $rs -> num_rows;
echo "<br /><span style='color:red;'><center>$n records found</center></span>";
echo "<div id='record'>";
echo "<table border='1' width='80%' align='center' cellpadding='0' cellspacing='0' id='unsolTable'>";
echo "<tr>";
echo "<th>ID</th>";
echo "<th>Ticket Number</th>";
echo "<th>KOID</th>";
echo "<th>PROBLEM</th>";
echo "<th>COMMENT</th>";
echo "<th>DATE</th>";
echo "<th>TIME</th>";
echo "<th>STATUS</th>";
echo "<th>SOLVED BY</th>";
echo "<th>Assign</th>";
echo "<th>Assigned to</th>";
echo "</tr>";
while ($row = $rs -> fetch_assoc() ) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['token'] . "</td>";
echo "<td>" . $row['koid'] . "</td>";
echo "<td>" . $row['problem'] . "</td>";
echo "<td>" . $row['comment'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['time'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['solvedBy'] . "</td>";
echo "<td><a href='assign.php?qType=technical&name=anshul&id=" . $row['id'] . "'>anshul</a>
<br />
<a href='assign.php?qType=technical&name=kiran&id=" . $row['id'] . "'>kiran</a>
<br />
<a href='assign.php?qType=technical&name=akhilesh&id=" . $row['id'] . "'>akhilesh</a></td>";
echo "<td>" . $row['assTo'] . "-" . $row['assTime'] . "-" . $row['assDate'] . "</td>";
echo "</tr>";
}
echo"</table>";
echo "</div>";
}
?>
On the another side is list on the assign i don't want to write it manually just get from the database how can i do this??
$sql= $cid->query("SELECT name FROM user WHERE designation='Technical' AND status='1'");
while ($row=$sql->fetch_assoc()) {
$name= $row['name'];
}
this is the another code i want to add in first code.
Nothing prevents you from executing another SQL query inside you while loop; just replace the echo...anshul...echo...kiran... part with another while loop containing the code you already provided.
You just have to make sure that you use different variables, otherwise your $row variable is overwritten by the second query. Hence, you can do something like this:
// ...
echo "<td>" . $row['solvedBy'] . "</td>";
$resultSetAssignedUsers = $cid->query("SELECT name FROM user WHERE designation = 'Technical' AND status = '1'");
while ($rowAssignedUsers = $resultSetAssignedUsers->fetch_assoc()) {
echo "<td><a href='assign.php?qType=technical&name=" . $rowAssignedUsers['name'] . "&id=" . $row['id'] . "'>" . $rowAssignedUsers['name'] . "</a>";
}
echo "<td>" . $row['assTo'] . "-" . $row['assTime'] . "-" . $row['assDate'] . "</td>";
// ...
This question already has an answer here:
How to extract only columns which has non zero values in mysql and php?
(1 answer)
Closed 7 years ago.
Above image is the entry of data in mysql database.
Above image was the output what i am getting is,
But i need to display only non zero fields as the output that means from "sample revived" column to "library qc" column only.
php script is
<?php
$userinput1 = $_POST['soid'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "status";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_errno) {
printf("Connect failed: %s\n", $conn->connect_error);
exit();
}
$result = mysqli_query($conn, "SELECT * FROM $dbname.statusinfo WHERE soid = '$userinput1' ") or die(mysqli_error
($conn));
echo "<p><font size= 4>SO_NUMBER:$userinput1";
echo "<table border='1'>
<tr>
<style>
th{
color: blue;
}
td{
color: black;
}
</style>
<th>Sample Recived</th>
<th>Mol-Bio Extraction</th>
<th>Extraction QC</th>
<th>Library Prep</th>
<th>Library QC</th>
<th>Sequencing</th>
<th>Data Check</th>
<th>RE Sequencing</th>
<th>QC Check</th>
<th>Analysis Started</th>
<th>Analysis Completed</th>
<th>Report</th>
<th>Outbound</th>
</tr>";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<br />";
echo "Department:".$row['dept'] ;
echo "<td>" . $row['samplerecived'] . "</td>";
echo "<td>" . $row['molbioextraction'] . "</td>";
echo "<td>" . $row['molbioextractionqc'] . "</td>";
echo "<td>" . $row['libraryprep'] . "</td>";
echo "<td>" . $row['libraryqc'] . "</td>";
echo "<td>" . $row['sequencing'] . "</td>";
echo "<td>" . $row['datacheck'] . "</td>";
echo "<td>" . $row['resequencing'] . "</td>";
echo "<td>" . $row['qccheck'] . "</td>";
echo "<td>" . $row['analysisstarted'] . "</td>";
echo "<td>" . $row['analysiscompleted'] . "</td>";
echo "<td>" . $row['report'] . "</td>";
echo "<td>" . $row['outbound'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
inside your while loop use for each field like this (use like this for all fields):
while($row = mysqli_fetch_assoc($result))
{
if($row['samplerecived']=="0000-00-00") $row['samplerecived']="";
echo "<tr>";
echo "<br />";
echo "Department:".$row['dept'] ;
echo "<td>" . $row['samplerecived'] . "</td>";
echo "<td>" . $row['molbioextraction'] . "</td>";
echo "<td>" . $row['molbioextractionqc'] . "</td>";
echo "<td>" . $row['libraryprep'] . "</td>";
echo "<td>" . $row['libraryqc'] . "</td>";
echo "<td>" . $row['sequencing'] . "</td>";
echo "<td>" . $row['datacheck'] . "</td>";
echo "<td>" . $row['resequencing'] . "</td>";
echo "<td>" . $row['qccheck'] . "</td>";
echo "<td>" . $row['analysisstarted'] . "</td>";
echo "<td>" . $row['analysiscompleted'] . "</td>";
echo "<td>" . $row['report'] . "</td>";
echo "<td>" . $row['outbound'] . "</td>";
echo "</tr>";
}
Use typecasting operator int() for the respective fields.
$var = (int) $var ? $var : '';
Explanation:
An empty date 0000-00-00 00:00:00 always return 0 which is blank/empty.
In above code, it will return 0 hence, it will not display blank/empty date.
Only dates with some non-zero values will be displayed.