Code doesn't update - php

I have an edit form that will search for the ID and edit it in the same page. Then tosses it to another page where it will show that it's successful.
<body bgcolor = "#FFFFFF" text = "#000000">
<form name = "ReadID" method="post">
<table width = "350" border = "0" align="center" cellpadding = "3" >
<tr>
<td colspan = "2" bgcolor = "#EF8D25" height = "23">
<center><b>Search</b></center>
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "40%" bgcolor = "#eeeeee">
<center>Asset ID</center>
</td>
<td width = "60%">
<input id="text" type = "text" name = "ASSET_ID">
</td>
</tr>
<td colspan = "2" bgcolor = "#EF8D25">
<center>
<input type = "submit" name = "Submit" value = "Search" onclick="showElem()">
</center>
</td>
</tr>
</table>
</form>
<form name="displayform" method="post" action="edititem.php">
<table width="350" border="0" align="center" cellpadding="3" id="111">
<tr>
<td colspan="2" bgcolor="#EF8D25">
<div align="center"><b>Edit Form</b></div>
</td>
</tr>
<?php
$host = "localhost";
$uname = "root";
$pass = "";
$tablename = "tb_asset";
$con = mysql_connect($host, $uname, $pass)
or die ("Database connection failed!<br>");
mysql_select_db("db_itinventory",$con);
$ASSET_ID = $_POST['ASSET_ID'];
$sql="select * from tb_asset where ASSET_ID='$ASSET_ID'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
?>
<tr bgcolor="#eeeeee">
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align="right" >Barcode</div>
</td>
<td width = "150">
<input id="text" type="text" name = "Barcode" value ="<?php echo $row['Barcode']; ?>"/>
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Item Name</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Item_Name" value="<?php echo $row['Item_Name']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Serial</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Serial" value="<?php echo $row['Serial']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Brand</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Brand" value="<?php echo $row['Brand']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Model</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Model" value="<?php echo $row['Model']; ?>" />
</td>
</tr>
<tr bgcolor = "#eeeeee">
<td width = "100" bgcolor = "#eeeeee">
<div align = "right" >Status</div>
</td>
<td width = "150">
<input id="text" type = "text" name="Status" value="<?php echo $row['Status']; ?>" />
</td>
</tr>
<td colspan="2" bgcolor="#EF8D25" >
<div align="center">
<input type="submit" name="Submit" value="Update" />
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
This is the second page.
<?php
$user_name = "root";
$password = "";
$database = "db_itinventory";
$server = "localhost";
mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database);
$ASSET_ID = trim(mysql_real_escape_string($_POST["ASSET_ID"]));
$Barcode = trim(mysql_real_escape_string($_POST["Barcode"]));
$Item_Name = trim(mysql_real_escape_string($_POST["Item_Name"]));
$Serial = trim(mysql_real_escape_string($_POST["Serial"]));
$Brand = trim(mysql_real_escape_string($_POST["Brand"]));
$Model = trim(mysql_real_escape_string($_POST["Model"]));
$Status = trim(mysql_real_escape_string($_POST["Status"]));
$sql = ("Update tb_asset set Barcode = '".$Barcode."' , Item_Name = '".$Item_Name."' , Serial = '".$Serial."' , Brand = '".$Brand."' , Model = '".$Model."' , Status = '".$Status."' where ASSET_ID = '".$ASSET_ID."'");
$result=mysql_query($sql);
if ($result){
echo "<center><table border = \"0\" align = \*center\* cellspacing = \"1\" cellpadding = \"5\" width = \"350\">";
echo "<tr>";
echo "<td colspan = \"2\" bgcolor = \"#EF8D25\">";
echo "<center><b>Record successfully edited!</b></center>";
echo "</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"20\">";
echo "<div align = \"right\">Barcode</div>";
echo "</td>";
echo "<td width = \"550\">".$Barcode."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Item_Name</div>";
echo "</td>";
echo "<td width = \"200\">".$Item_Name."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Serial</div>";
echo "</td>";
echo "<td width = \"200\">".$Serial."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Brand</div>";
echo "</td>";
echo "<td width = \"200\">".$Brand."</td>";
echo "</tr>";
//echo "<tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Model</div>";
echo "</td>";
echo "<td width = \"200\">".$Model."</td>";
echo "</tr>";
echo "<tr bgcolor = \"#eeeeee\">";
echo "<td width = \"200\">";
echo "<div align = \"right\">Status</div>";
echo "</td>";
echo "<td width = \"200\">".$Status."</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan = \"2\" bgcolor = \"#EF8D25\"> </td>";
echo "</tr>";
echo "</table>";
}
else {
echo "ERROR!";
}
?>
There's no error showing. But the code is not working. Help?

One of few possible errors..
$sql = ("Update tb_asset set Barcode = '".$Barcode."' , Item_Name = '".$Item_Name."' , Serial = '".$Serial."' , Brand = '".$Brand."' , Model = '".$Model."' , Status = '".$Status."' where ASSET_ID = '".$ASSET_ID."'");
*shouldn't have any parentheses.
Regarding undefined ASSET_ID:
You might want to put the value of ASSET_ID in a hidden form field
<input type="hidden" name = "ASSET_ID" value ="<?php echo $row['ASSET_ID']; ?>"/>

Related

PHP / SQL: Successful update a data row but got PHP Fatal Error

I have a really weird issue in my code. To be short, I created a system that has a dashboard called dashboard_engineer.php. This dashboard will display only the first 30 data rows of the SQL database. This dashboard also contains 3 filtered inputs which are:
team
date from
date to
Users can use this filter to find their exact data rows. The user just fills in the input and presses the button Search, and this will redirect the user to dashboard_engineer2.php.
In this dashboard, all the filtered data rows will be displayed. Each data row contains a View and a Remove button. The remove button is used to remove the details of the data row by updating it.
My problem is, at the filtered data, when I click the remove button, the data is update at SQL database, but it will display this error:
PHP Fatal error: Uncaught PDOException: SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near '10'. in C:\inetpub\wwwroot\tgotworker_testing\pages\dashboard\engineer\dashboard_engineer2.php:157
When I click remove button from a data row that not being filtered (dashboard_engineer.php), the data removed and no error display after that.
Any suggestions on how to resolve this will be appreciated. Below is my code:
dashboard_engineer.php
<form method = 'post' action = 'dashboard_engineer2.php' target="_blank">
<td width="40%">
<select class="form-control" name="team" id="team" required>
<option value="">Please select...</option>
<?php foreach ($data as $row2): ?>
<option value="<?php echo $row2["team_id"]; ?>"><?php echo $row2["fullname"]; ?></option>
<?php endforeach ?>
</select>
</td>
<td width="1%"></td>
<td width="20%"><input type="text" name="from" id="from" class="form-control" placeholder="From" required></td>
<td width="1%"></td>
<td width="20%"><input type="text" name="to" id="to" class="form-control" placeholder="To" required></td>
<td width="1%"></td>
<td width="10%"><button type="submit" class="btn-primary" >Search</button><td>
</form>
</tr>
</table><br>
<div class="row" style='height: 300px; overflow-y: scroll;'>
<div class="col-lg-12 grid-margin stretch-card">
<?php
$query = $conn->query("SELECT TOP 30 * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid WHERE ot_users.team_id <> 1 AND ot_report.status = 'yes' ORDER BY ot_report.report_id DESC");
$query -> execute();
$results = $query -> fetchAll(PDO::FETCH_OBJ);
if(empty($results)){
echo "<table class = 'table-bordered' width ='100%'>";
echo "<thead>";
echo "<tr>";
echo "<th width = '5%'>id</th>
<th width = '17%'>Date</th>
<th width = '27%'>Officer/ Asst. Engineer</th>
<th width = '32%'>Task Name</th>
<th width = '12%'>Status</th>
<th width = '7%'>Action</th>
</tr>
</thead>
<tbody >
<tr>
<td colspan='8'>No report at this moment</td>
</tr>
</tbody>
</table>";
}else{
echo "<table class = 'table-bordered' width ='100%'>";
echo "<thead>";
echo "<tr>";
echo "<th width = '5%'>id</th>
<th width = '17%'>Date</th>
<th width = '27%'>Officer/ Asst. Engineer</th>
<th width = '32%'>Task Name</th>
<th width = '12%'>Status</th>
<th colspan = '2' width = '7%'>Action</th>
</tr>
</thead>
<tbody >";
$query = $conn->query("SELECT TOP 30 * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid WHERE ot_users.team_id <> 1 AND ot_report.status = 'yes' ORDER BY ot_report.report_id DESC");
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$status=$row['report_status'];
if($status=="Pending")
{
$color="color:blue";
}
else
{
$color="color:green";
}
$report_id = $row['report_id'];
$datereport = $row['report_date'];
$datereport2 = strtotime($datereport);
$report_date = date('d M Y', $datereport2);
$fullname = $row['fullname'];
$task_name = $row['task_name'];
echo "<tr>";
echo "<td>". $report_id. "</td>";
echo "<td>". $report_date . "</td>";
echo "<td>". $fullname . "</td>";
echo "<td>". $task_name . "</td>";
echo "<td align='center' style='$color'><strong>". $status . "</strong></td>";
echo "<td align='center'>";
echo "<form method = 'post' action = 'view_task/view_task.php' target='_blank'>";
echo "<input type = 'hidden' name = 'report_id' value = '".$report_id."'>";
echo "<button type = 'submit' class='btn-primary'>View</button>";
echo "</form>";
echo "</td>";
echo "<td align='center'>";
echo "<form method = 'post' action = 'remove.php' onClick=\"return confirm('Do you want to remove this report?')\">";
echo "<input type = 'hidden' name = 'report_id' value = '".$report_id."'>";
echo "<button type = 'submit' class='btn-danger'>Remove</button>";
echo "</form>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table><br>";
}
?>
dashboard_engineer2.php
<?php
if(isset($_REQUEST["from"], $_REQUEST["to"], $_REQUEST["team"])){
$from = $_REQUEST['from'];
$to = $_REQUEST['to'];
$team = $_REQUEST['team'];
$result = '';
$query = "SELECT * FROM ot_report LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid WHERE ot_report.status = 'yes' AND ot_users.team_id = '".$team."' AND report_date BETWEEN '".$from."' AND '".$to."' ORDER BY ot_report.report_id DESC";
$sql = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$sql -> execute(); //line 157
if($sql->rowCount() > 0){
echo'
<div><u>PDF View</u></div><br>
<div class="row">
<div class="col-lg-12 grid-margin stretch-card">
<div class="row" style="height: 300px; overflow-y: scroll;">
<div class="col-lg-12 grid-margin stretch-card">
<table class = "table-bordered" width = "100%">
<thead>
<tr>
<th width = "10%"><input type="checkbox" id="checkAl"> All</th>
<th width = "3%">id</th>
<th width = "15%">Date</th>
<th width = "25%">Supervisor</th>
<th width = "30%">Task Name</th>
<th width = "10%">Status</th>
<th colspan = "2" width = "7%">Action</th>
</tr>
</thead>
<tbody>';
$i=0;
while($row = $sql->fetch(PDO::FETCH_ASSOC)){
$datereport = $row['report_date'];
$datereport2 = strtotime($datereport);
$report_date = date('d M Y', $datereport2);
$status=$row['report_status'];
if($status=="Pending"){
$color="color:blue";
}
else {
$color="color:green";
}
$report_id = $row["report_id"];
echo'<tr>';
echo '<td><input type="checkbox" id="checkItem" name="check[]" value='.$row['report_id'].'></td>';
echo '<td>'.$report_id.'</td>';
echo '<td>'.$report_date.'</td>';
echo '<td>'.$row["fullname"].'</td>';
echo '<td>'.$row["task_name"].'</td>';
echo '<td align="center" style='.$color.'><strong>'.$status.'</strong></td>';
echo '<td align="center">';
echo '<form action = "view_task/view_task.php" method = "post" target="_blank">';
echo '<input type = "hidden" name = "report_id" value = "'.$report_id.'">';
echo '<button type = "submit" class="btn-primary">View</button>';
echo '</form>';
echo '</td>';
// echo '<a class="btn-view btn-primary btn-sm" href="view_task/view_task.php?report_id='. $report_id .'" data-toggle="tooltip" >View</a></td>';
echo '<td align="center">';
echo "<form action = 'remove2.php' method = 'post' onClick=\"return confirm('Do you want to remove this reports?')\">";
echo '<input type = "hidden" name = "from" value = "'.$from.'">';
echo '<input type = "hidden" name = "to" value = "'.$to.'">';
echo '<input type = "hidden" name = "team" value = "'.$team.'">';
echo '<input type = "hidden" name = "report_id" value = "'.$report_id.'">';
echo '<button type = "submit" class="btn-danger">Remove</button>';
echo '</form>';
echo '</td>';
echo '</tr>';
$i++;
}
echo '<tr>';
echo '<td><p align="center"><button type="submit" class="btn-danger btn-sm" name="save">DELETE</button></p></td>';
echo '</tr>';
}
else
{
echo '
<table class = "table-bordered" width = "100%">
<thead>
<tr>
<th width = "5%">id</th>
<th width = "12%">Date</th>
<th width = "29%">Supervisor</th>
<th width = "23%">Task Name</th>
<th width = "10%">Status</th>
<th width = "7%">Action</th>
</tr>
<tr>
<td colspan="6">No report found</td>
</tr>';
}
echo '</body></table></div></div>';
}
?>
remove2.php
<?php
include('../../../config/configPDO.php');
$report_id = $_POST['report_id'];
$from = $_POST['from'];
$to = $_POST['to'];
$team = $_POST['team'];
$sql = "UPDATE ot_report SET status = 'no' WHERE report_id=:report_id";
$query = $conn->prepare($sql);
$query->execute(array(':report_id' => $report_id));
header("Location: dashboard_engineer2.php?from='".$_POST["from"]."'&to='".$_POST["to"]."' &team='".$_POST["team"]."'");
?>
Use a parametrized query instead of concatenating variables.
$query = "
SELECT *
FROM ot_report
LEFT JOIN ot_users ON ot_report.badgeid = ot_users.badgeid
WHERE ot_report.status = 'yes'
AND ot_users.team_id = :team
AND report_date BETWEEN :from AND :to
ORDER BY ot_report.report_id DESC";
$sql = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$sql->bindParam(':team', $team, PDO::PARAM_INT);
$sql->bindParam(':from', $from, PDO::PARAM_INT);
$sql->bindParam(':to', $to, PDO::PARAM_INT);
$sql -> execute();
I found the answer, problem at remove2.php. Below is the code:
<?php
include('../../../config/configPDO.php');
$report_id = $_POST['report_id'];
$from = $_POST['from'];
$to = $_POST['to'];
$team = $_POST['team'];
$sql = "UPDATE ot_report SET status = 'no' WHERE report_id=:report_id";
$query = $conn->prepare($sql);
$query->execute(array(':report_id' => $report_id));
header("Location: dashboard_engineer2.php?from=".$from."&to=".$to."&team=".$team."");
?>

Getting contents of dropdown from table and storing it in an array

I just want to get the contents of the dropdown and store it in array.
I am able to display the dropdown but it doesn't get the contents of what I selected.
echo '<br><br><br><br><br>
<div class="Table">
<table border="2pt solid black" align="left" cellpadding="2px" bordercolor=black>
<tr>
<td width = "7%">
<div align = "left"><b>BRAND NAME</div></b>
</td>
<td width = "7%">
<div align = "left"><b>INGREDIENT</div></b>
</td>
<td width = "3%">
<div align = "left"><b>QUANTITY</div></b>
</td>
<td width = "7%">
<div align = "left"><b>MEASUREMENT</div></b>
</td>
</tr>';
for ($x = 0; $x < sizeof($rowarray); $x++) {
$query = "select R.name AS RAWNAME, I.name AS INGREDIENTNAME, R.quantity AS RAWQUANTITY from rawmaterial R JOIN ingredient I ON R.ingredient_id = I.ingredient_id where R.rawmaterial_id='{$rowarray[$x]}'";
$res = mysqli_query($dbc, $query);
while ($fetch = mysqli_fetch_array($res, MYSQL_ASSOC)) {
echo "<tr>
<td width=\"7%\">
<div align=\"left\">{$fetch['RAWNAME']}</div>
</td>
<td width=\"3%\">
<div align=\"left\">{$fetch['INGREDIENTNAME']}</div>
</td>
<td width=\"3%\">
<div align=\"left\"><input type='name' name='quantity[]' placeholder={$fetch['RAWQUANTITY']}></input></div>
</td>
<td width=\"7%\">
<div align=\"left\">";
echo "<select name = 'measure'>";
$mesr = mysqli_query($dbc, 'select measure from measure_ref');
while ($row = mysqli_fetch_array($mesr, MYSQLI_ASSOC)) {
$mes = $row['measure'];
echo '<option value ='.$mes.'>'.$mes.'</option>';
}
echo "</select>";
echo "</div>";
echo "</td>";
echo "</tr>";
}
}
echo '</table></div>';
$messarray = array();
$mes = $_POST['measure'];
$row = array();
foreach ($mes as $row) {
array_push($messarray, $row);
}
Check below points.
Make sure your dropdown is within form
As you are creating multiple dropdown you should give name with '[]'(measure[]),like you have given to 'quantity[]'.

Display and retrieve image from database in PHP

I want to display image from database but currently it displays only name of image. need help. here is my code
submit.php
<?php
$radio = $_POST['RadioGroup1'];
$img_banner = $_FILES['bannerImage']['name'];
$target_file = "uploads/";
if(!empty($img_banner))
{
$errors = array();
$file_name = $_FILES['bannerImage']['name'];
$file_size = $_FILES['bannerImage']['size'];
$file_tmp = $_FILES['bannerImage']['tmp_name'];
$file_type = $_FILES['bannerImage']['type'];
$file_ext = strtolower(end(explode('.',$_FILES['bannerImage']['name'])));
$k = move_uploaded_file($file_tmp,"uploads/".$file_name);
}
$date = $_POST['date'];
$qry_banner = "INSERT INTO `banner_tbl`(`banner_img`, `date`) VALUES ('$img_banner','$date')";
$res_banner = mysql_query($qry_banner);
$banner_tbl_id = mysql_insert_id();
$sec_id = $_POST['sectionID'];
$sec_active_image = $_POST['activeimage'];
$sec_title = $_POST['section_title'];
$total_sec = count($sec_id);
for($i=0;$i<$total_sec;$i++)
{
$qry_section1 = "INSERT INTO `section_lt_tbl`(`banner_id`, `sectionID`, `activeimage`, `sectiontitle`) VALUES
('$banner_tbl_id','$sec_id[$i]','$sec_active_image[$i]','$sec_title[$i]')";
$res_section1 = mysql_query($qry_section1);
$sec_tbl_id1 = mysql_insert_id();
$section_generated_id[] = $sec_tbl_id1;
}
$array_section_ids = array();
for($i=1;$i<=$radio;$i++)
{
$j = $i-1 ;
$array_section_ids[$i] = $section_generated_id[$j];
}
for($h=1;$h<=count($array_section_ids);$h++)
{
$news_ids_sec[$h] = $_POST['sec_'.$h.'_new'];
$news_title_sec[$h] = $_POST['sec_'.$h.'_title_news'];
$sec_1_desc[$h] = $_POST['sec_'.$h.'_desc'];
$sec_1_newslink[$h] = $_POST['sec_'.$h.'_newslink'];
$sec_1_news_url[$h] = $_POST['sec_'.$h.'_news_url'];
$sec_1_news_img[$h] = $_FILES['sec_'.$h.'_news_img']['name'];
$temp_file[$h] = $_FILES['sec_'.$h.'_news_img']['tmp_name'];
$section = $array_section_ids[$h];
for($c=0;$c<count($news_ids_sec[$h]);$c++)
{
$id = $news_ids_sec[$h][$c];
// $sec_id = $array_section_ids[$h][$c];
$title= $news_title_sec[$h][$c];
$desc = $sec_1_desc[$h][$c];
$link = $sec_1_newslink[$h][$c];
$url = $sec_1_news_url[$h][$c];
$img = $sec_1_news_img[$h][$c][0];
$tmp_name = $temp_file[$h][$c][0];
$qry_news_insert = "INSERT INTO `news_lt_tbl`(`newsid`, `news_sec_id`, `newstitle`, `Description`, `titleoflink`, `urlofnews`, `news_img`) VALUES ('$id','$section','$title','$desc','$link','$url','$img')";
$res_news = mysql_query($qry_news_insert);
$file_name = $img;
$file_tmp = $tmp_name;
$file_ext = strtolower(end(explode('.',$file_name)));
$k = move_uploaded_file($file_tmp,"uploads/".$file_name);
}
}
?>
<?php
$qry_test = "SELECT * FROM `section_lt_tbl` WHERE sec_id = 162";
$res_tses = mysql_query($qry_test);
$arr = mysql_fetch_assoc($res_tses);
?>
<?php
$query = "SELECT `newsid`, `newstitle`, `Description`, `titleoflink`, `urlofnews`, `news_img` FROM `news_lt_tbl` ";
$result_news = mysql_query($query);
$file_name = $img;
$file_tmp = $tmp_name;
$file_ext = strtolower(end(explode('.',$file_name)));
$k = move_uploaded_file($file_tmp,"uploads/".$file_name);
?>
And
<table align="center" width="600">
<tr>
<tr>
<td bgcolor="#ffffff" valign="bottom" align="left"><img border="0" src="http://www.nrsadvisors.com/email-images/mainlogo.jpg" alt="NRS Advisors"/></td>
</tr>
<tr>
<td style="border-top-width:2px; border-top-style:solid; border-top-color: #3E7DBD;" bgcolor="#dbdbdb"><img border="0" src="http://www.nrsadvisors.com/email-images/banner-hero-image.png" alt="bannerimg" width="550" /><a name="featuredstartup" style="height:0;margin:0;padding:0"></a></td>
</tr>
<td bgcolor="#dbdbdb" align="center"><table border="0" cellpadding="0" cellspacing="0" width="550" align="center">
<tr>
<td width="25%"><a href="#featuredstartup"><img src="uploads/<?php echo $arr['activeimage'] ?>_blue.jpg" width="125px" height="134px" />
</a></td>
<td width="25%"><img src="uploads/<?php echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></td>
<td width="25%"><img src="uploads/<?php echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></td>
<td width="25%"><img src="uploads/<?php echo $arr['activeimage'] ?>_grey.jpg" width="125px" height="134px" /></td>
</tr>
</table>
</td>
</tr>
<?php
while ($row = mysql_fetch_array($result_news)) {
?>
<table align="center" width="600">
<tr>
<span style="font-size:14px;line-height:17px;font-weight:normal;color:#333333">
<td align="left">
<span style="font-weight:bold">
<?php echo $row['newsid'] ?>
</span>
</td>
</span>
</tr>
<tr>
<td>
<span align='left' style='color:#3E7DBD;font-weight:bold'>
<span style='font-size:14px;line-height:17px;font-weight:normal;color:#333333'><span style='font-weight:bold'>
<?php echo $row['newstitle'] ?>
-</span><br><br>
</td>
</tr>
<tr>
<td><?php echo $row['Description'] ?></td><br><br>
</tr>
<tr>
<td>
<a href="<?php echo $row['urlofnews'] ?>" style='font-size:14px;line-height:17px;color:#3FC47B; text-decoration:none;'><?php echo $row['titleoflink'] ?></a></td><br><br>
</tr>
<tr>
<td><?php echo $row['news_img'] ?></td>
</tr>
</table>
<?php
}
?>
You need to use img tag to display Image. like this:
<img src="your_upload_path/<?php echo $row['news_img'] ?>" />
Specify the upload image path in img src like this
<img src="Upload Path/<?php echo $row['news_img'] ?" />

trouble in using $_SESSION in PHP

I am facing trouble in using $_SESSION when I open viewrcd.php file it opens directly instead of opening admin_login.php page. (b'coz to view this page "viewrcd.php" admin logged in is must...)
admin_login.php
<?php
session_start();
require 'testdbcheking.php';
if(isset($_POST['login']))
{
$a_name = $_POST['admin_name1'];
$a_pword = $_POST['admin_password1'];
$_SESSION['admin_name1'] = 'admin_name1';
if(!empty($_POST['admin_name1']) && !empty($_POST['admin_password1']))
{
$query10="SELECT * FROM admin_login WHERE admin_name = '$a_name' AND admin_password = '$a_pword'";
if($query10_run = mysql_query($query10))
{
$query10_num_rows = mysql_num_rows($query10_run);
if($query10_num_rows == 0)
{
echo 'you are not an admin';
}
if($query10_num_rows == 1)
{
echo "<script>window.open('viewrcd.php?logged= Admin logged in Success','_self')</script>";
}
}
}
else
{
echo 'provide both......';
}
}
?>
<html>
<title>Admin Login Page</title>
<body>
<form action = 'admin_login.php' method = 'POST' >
<table align = 'center' border = '3' bgcolor = 'gray'>
<tr ><td colspan = 8 align ='center'>Admin Login FORM</td></tr>
<tr>
<td>Admin Username:</td>
<td><input type = 'text' name ='admin_name1'></td>
</tr>
<tr>
<td>Admin Password:</td>
<td><input type = 'password' name ='admin_password1'></td>
</tr>
<tr> <td colspan = '4' align ='center'>
<input type = 'submit' name='login' value = 'Login'>
</td>
</tr>
</table>
</form>
</body>
</html>
viewrcd.php
<?php
session_start();
require 'testdbcheking.php';
if($_SESSION['admin_name1'])
{
//echo 'qqq';
header('location :admin_login.php');
//header('location : viewrcd.php');
}
?>
<a href= 'admin_logout.php'>ADMIN_logout </a>
<html>
<head><center><h1>Viewing all the rocords</center></h1><head/>
<body>
<table align = center border = 1>
<tr align = 'center'>
<th>SR.NO.</th>
<th>Username</th>
<th>Firstname</th>
<th>Surname</th>
<th>Delete</th>
<th>Edit</th>
<th>Details</th>
</tr>
<?php
$query4 = 'SELECT * FROM users';
$query4_run = mysql_query($query4);
while (#$data_row = mysql_fetch_array($query4_run))
{
$u_id = $data_row [0];
$u_name = $data_row[1];
$f_name = $data_row [3];
$s_name = $data_row [4];
?>
<tr align = 'center'>
<td> <?php echo #$u_id;?></td>
<td> <?php echo #$u_name;?></td>
<td> <?php echo #$f_name;?></td>
<td> <?php echo #$s_name;?></td>
<td><a href = 'delete.php?del=<?php echo $u_id ;?>'>Delete</a></td>
<td><a href = 'edit.php?edit=<?php echo $u_id ;?>'>Edit</a></td>
<td><a href = 'viewrcd.php?details=<?php echo $u_id ;?>'>Details</a></td>
<?php } ?>
</tr>
</table>
<?php
$record_details = #$_GET['details'];
$query8 = "SELECT * FROM users WHERE id = '$record_details'";
$query_run8 = mysql_query($query8);
while($query_run8_row = mysql_fetch_array($query_run8))
{
$d_name = $query_run8_row[1];
$d_firstname = $query_run8_row[3];
$d_surname = $query_run8_row[4];
?>
<table align = center border = 1>
</tr>
<tr ><td colspan = 10 align = center> your details are here </td></tr>
<tr align = center>
<td><?php echo $d_name ; ?></td>
<td><?php echo $d_firstname ; ?></td>
<td><?php echo $d_surname ; ?></td>
</tr>
<?php } ?>
</table>
<font bgcolor = 'green' align = 'center' size = '6'>
<?php echo #$_GET['deleted'];?>
</font>
<font color = 'green' align = 'center' size = '6'>
<?php echo #$_GET['updated'];?>
<?php echo #$_GET['logged'];?>
</font><br><br><br><br><br>
<form action = "viewrcd.php" method = "get">
Search record: <input type = "text" name = "search" >
<input type = "submit" name = "submit" value ="Find Record">
</form>
<?php
if (isset($_GET['search']))
{
$search_record = $_GET['search'];
$query9 = "SELECT * FROM users WHERE id = '$search_record' OR firstname ='$search_record' ";
$query9_run = mysql_query($query9);
while($query9_run_row = mysql_fetch_assoc($query9_run))
{
//$find_id = $query9_run_row['id'];
$find_username = $query9_run_row['username'];
$find_firstname = $query9_run_row['firstname'];
$find_surname = $query9_run_row['surname'];
?>
<br><br><br>
<table border = '2' bgcolor ='green' align ='center'>
<tr>
<th>Username</th>
<th>Firstname</th>
<th>Surname</th>
<tr>
<td><?php echo $find_username ; ?></td>
<td><?php echo $find_firstname ; ?></td>
<td><?php echo $find_surname ; ?></td>
</tr>
</table>
<?php } } ?>
</body>
</html>
admin_logout.php
<?php
require 'testdbcheking.php';
session_start();
session_destroy();
header('Location: admin_login.php');
?>
replace
if($_SESSION['admin_name1'])
with
if(!$_SESSION['admin_name1'])
in viewrcd.php
replace
if($_SESSION['admin_name1'])
with
if(empty($_SESSION['admin_name1']))
i have updated my answer ..try now
admin_login.php
<?php
session_start();
require 'testdbcheking.php';
global $a_name;
if(isset($_POST['login']))
{
$a_name = $_POST['admin_name1'];
$a_pword = $_POST['admin_password1'];
if(!empty($_POST['admin_name1']) && !empty($_POST['admin_password1']))
{
$query10="SELECT * FROM admin_login WHERE admin_name = '$a_name' AND admin_password = '$a_pword'";
if($query10_run = mysql_query($query10))
{
$query10_num_rows = mysql_num_rows($query10_run);
if($query10_num_rows == 0)
{
echo 'you are not AN admin';
}
if($query10_num_rows == 1)
{
$admin_id = mysql_result($query10_run,0,'admin_name');
$_SESSION['admin_id'] = $admin_id;
echo "<script>window.open('viewrcd.php?logged= Admin logged in Success','_self')</script>";
}
}
}
else
{
echo 'provide both......';
}
}
?>
<br><br><br>
<?php //echo $a_name ; ?>
<html>
<title>Admin Login Page</title>
<body>
<form action = 'admin_login.php' method = 'POST' >
<table align = 'center' border = '3' bgcolor = 'gray'>
<tr ><td colspan = 8 align ='center'>Admin Login FORM</td></tr>
<tr>
<td>Admin Username:</td>
<td><input type = 'text' name ='admin_name1'></td>
</tr>
<tr>
<td>Admin Password:</td>
<td><input type = 'password' name ='admin_password1'></td>
</tr>
<tr> <td colspan = '4' align ='center'>
<input type = 'submit' name='login' value = 'Login'>
</td>
</tr>
</table>
</form>
</body>
</html>
viewrcd.php
<?php
session_start();
require 'testdbcheking.php';
if(!isset($_SESSION['admin_id']))
{
?>
First Login here..
<?php
}
else
{
?>
<a href= 'admin_logout.php'>ADMIN_logout </a>
<html>
<head><center><h1>Viewing all the rocords</center></h1><head/>
<body>
<table align = center border = 1>
<tr align = 'center'>
<th>SR.NO.</th>
<th>Username</th>
<th>Firstname</th>
<th>Surname</th>
<th>Delete</th>
<th>Edit</th>
<th>Details</th>
</tr>
<?php
$query4 = 'SELECT * FROM users';
$query4_run = mysql_query($query4);
while (#$data_row = mysql_fetch_array($query4_run))
{
$u_id = $data_row [0];
$u_name = $data_row[1];
$f_name = $data_row [3];
$s_name = $data_row [4];
?>
<tr align = 'center'>
<td> <?php echo #$u_id;?></td>
<td> <?php echo #$u_name;?></td>
<td> <?php echo #$f_name;?></td>
<td> <?php echo #$s_name;?></td>
<td><a href = 'delete.php?del=<?php echo $u_id ;?>'>Delete</a></td>
<td><a href = 'edit.php?edit=<?php echo $u_id ;?>'>Edit</a></td>
<td><a href = 'viewrcd.php?details=<?php echo $u_id ;?>'>Details</a></td>
<?php } ?>
</tr>
</table>
<?php
$record_details = #$_GET['details'];
$query8 = "SELECT * FROM users WHERE id = '$record_details'";
$query_run8 = mysql_query($query8);
while($query_run8_row = mysql_fetch_array($query_run8))
{
$d_name = $query_run8_row[1];
$d_firstname = $query_run8_row[3];
$d_surname = $query_run8_row[4];
?>
<table align = center border = 1>
</tr>
<tr ><td colspan = 10 align = center> your details are here </td></tr>
<tr align = center>
<td><?php echo $d_name ; ?></td>
<td><?php echo $d_firstname ; ?></td>
<td><?php echo $d_surname ; ?></td>
</tr>
<?php } ?>
</table>
<font bgcolor = 'green' align = 'center' size = '6'>
<?php echo #$_GET['deleted'];?>
</font>
<font color = 'green' align = 'center' size = '6'>
<?php echo #$_GET['updated'];?>
<?php echo #$_GET['logged'];?>
</font><br><br><br><br><br>
<form action = "viewrcd.php" method = "get">
Search record: <input type = "text" name = "search" >
<input type = "submit" name = "submit" value ="Find Record">
</form>
<?php
if (isset($_GET['search']))
{
$search_record = $_GET['search'];
$query9 = "SELECT * FROM users WHERE id = '$search_record' OR firstname ='$search_record' ";
$query9_run = mysql_query($query9);
while($query9_run_row = mysql_fetch_assoc($query9_run))
{
//$find_id = $query9_run_row['id'];
$find_username = $query9_run_row['username'];
$find_firstname = $query9_run_row['firstname'];
$find_surname = $query9_run_row['surname'];
?>
<br><br><br>
<table border = '2' bgcolor ='green' align ='center'>
<tr>
<th>Username</th>
<th>Firstname</th>
<th>Surname</th>
<tr>
<td><?php echo $find_username ; ?></td>
<td><?php echo $find_firstname ; ?></td>
<td><?php echo $find_surname ; ?></td>
</tr>
</table>
<?php } } ?>
</body>
</html>
<?php }?>
admin-logout.php
<?php
session_start();
// session_destroy();
unset($_SESSION['admin_id']);
header('Location: loginform.php');
?>

how to give color to table tr?

Hello i have a table with some fields like
here i want make colors for table entire rows..means if ASR value is 75 to 100 should get one color and 50 to 75 should get another color and below 50 should get another color.
and here is my php code
<table width="75%" border="1">
<tr>
<td align="center">channel no</td>
<td align="center">IP</td>
<td align="center">Total calls</td>
<td align="center">Connected calls</td>
<td align="center">Disconnected calls</td>
<td align="center">Duration</td>
<td align="center">ASR</td>
<td align="center">ACD</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr>
<td>".$row['channel']." </td>
<td>".$row['ip']." </td>
<td>".$row['totalcalls']." </td>";
if ($row['totalcalls']>1){
$sql1 = "SELECT count(duration) as count FROM gateways where duration=0 and ip='".$_POST['ip']."' and channel='".$row['channel']. "' and (connect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' or disconnect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' ) Group by channel";
$result1 = mysql_query($sql1, $link);
$norow=mysql_fetch_assoc($result1);
$attenedcalls=($row['totalcalls']-$norow['count']);
echo "<td>".$attenedcalls." </td>";
$disconnectedcalls=($row['totalcalls']-$attenedcalls);
echo "<td>".$disconnectedcalls." </td>";
echo " <td>".$row['tduration']." </td>";
echo "<td>".(($attenedcalls/$row['totalcalls'])*100)."</td>";
}else{
echo "<td>".$row['totalcalls']."</td>";
echo "<td>100</td>";
}
$minutes = gmdate("H:i:s", ($row['tduration']/$attenedcalls));
echo " <td>".$minutes." </td>
</tr>";
}
?>
</table>
thanks in advance
You can try like this
<table width="75%" border="1">
<tr>
<td align="center">channel no</td>
<td align="center">IP</td>
<td align="center">Total calls</td>
<td align="center">Connected calls</td>
<td align="center">Disconnected calls</td>
<td align="center">Duration</td>
<td align="center">ASR</td>
<td align="center">ACD</td>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
$color = '';
if ($row['totalcalls']>1){
$sql1 = "SELECT count(duration) as count FROM gateways where duration=0 and ip='".$_POST['ip']."' and channel='".$row['channel']. "' and (connect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' or disconnect_datetime BETWEEN ' ".$_POST['toval']." ' and '".$_POST['fromval']."' ) Group by channel";
$result1 = mysql_query($sql1, $link);
$norow=mysql_fetch_assoc($result1);
$attenedcalls=($row['totalcalls']-$norow['count']);
$asr = (($attenedcalls/$row['totalcalls'])*100);
if($asr >= 75 && $asr <=100 ){
$color = 'red';
}else if($asr >= 50 && $asr < 75){
$color = 'cyan';
}else if($asr < 50){
$color = 'blue';
}
}
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr style='background-color : ".$color."'>
<td>".$row['channel']." </td>
<td>".$row['ip']." </td>
<td>".$row['totalcalls']." </td>";
if ($row['totalcalls']>1){
echo "<td>".$attenedcalls." </td>";
$disconnectedcalls=($row['totalcalls']-$attenedcalls);
echo "<td>".$disconnectedcalls." </td>";
echo " <td>".$row['tduration']." </td>";
echo "<td>".$asr."</td>";
}else{
echo "<td>".$row['totalcalls']."</td>";
echo "<td>100</td>";
}
$minutes = gmdate("H:i:s", ($row['tduration']/$attenedcalls));
echo " <td>".$minutes." </td>
</tr>";
}
?>
</table>
[...]
while ($row = mysql_fetch_assoc($result)) {
$asrVal=(($attenedcalls/$row['totalcalls'])*100);
if($asrVal>=50 && $asrVal <=75) $class="from50to75";
if($asrVal>=75 && $asrVal <=100) $class="from75to100";
if($asrVal<50) $class="below50";
//$minutes = gmdate("H:i:s", $row['tduration']);
echo "<tr class='$class'>
[...]
then add:
<style>
tr.from50to75 td{background-color:red;}
tr.from75to100 td{background-color:green;}
tr.below50 td{background-color:blue;}
</style>
Modify your while loop so that you compute the ASR value before emitting the <tr> tag. Use that value to select a class according to the classification you have set up, and emit a tag of the form <tr class=foo> where foo is the class name you have selected. Then it’s just a matter of writing CSS rules for the classes, using class selectors like tr.foo.
(Provided that you have not set color on the td cells. If you have, you need to use selectors like tr.foo td to override such settings.)

Categories