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'] ?" />
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
it says syntax error t_else, what could be the problem?
it really is making me crazy for finding what did i do wrong in this code
what could be myy mistake here?
<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
$page1 = $_GET['page'];
if ($page1 == "" || $page1 == 1) {
$page1 = 0;
}
else {
$page1 = ($page1 * 5) - 5;
}
$query = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
a href="news_view.php?id=<?php echo $row['news_id']; ?>">
<img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title']; ?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author']; ?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed']; ?></td>
</tr>
</thead>
</table>
<?php
}
$query1 = "select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
$result1 = mysql_query($query1);
$row1 = mysql_num_rows($result1);
$pagecount = $row1 / 5;
$pagecount = ceil($pagecount);
for ($count = 1; $count <= $pagecount; $count++) {
?>
<?php echo $count ?>
<?php
}
}
else{
$page1 = $_GET['page'];
if ($page1 == "" || $page1 == 1) {
$page1 = 0;
}
else {
$page1 = ($page1 * 5) - 5;
}
$query = "select * from tbl_news where news_status='Active' limit $page1,5";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id']; ?>">
<img src="<?php echo $row['news_image_location'] . $row['news_image']; ?>" height="300"
width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title']; ?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author']; ?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed']; ?></td>
</tr>
</thead>
</table>
<?php
}
?>
<?php
$query1 = "select * from tbl_news where news_status='Active'";
$result1 = mysql_query($query1);
$row1 = mysql_num_rows($result1);
$pagecount = $row1 / 5;
$pagecount = ceil($pagecount);
for ($count = 1; $count <= $pagecount; $count++) {
?>
<?php echo $count ?>
<?php # code...
}
}
?>
here is the full code, of what errror gives me, please help me guys it takes me a a lot of time having this kind of problem i already tried everything i could but maybe you guys could me solve my problem hahahaha it really drained my mind here , im already mindblown on what is the my currently facing problem
You are missing < at the a tag inside the first while loop (exactly on line 21 when I copy/paste your code). That might be the reason it doesn't recognize the else statement, because it can't get to it properly.
try this code. may be it resolve your problem.
I have corrected some syntax mistake in your code.
<?php
include("../mysql_connect.php");
if (isset($_POST['search_form'])) {
$page1=$_GET['page'];
if ($page1=="" || $page1==1) {
$page1=0;
}
else{
$page1=($page1*5)-5;
}
$query="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]' ";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id'];?>">
<img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title'];?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author'];?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed'];?></td>
</tr>
</thead>
</table>
<?php
}
$query1="select * from tbl_news where news_title like '$_POST[search]' || news_author like '$_POST[search]'";
$result1=mysql_query($query1);
$row1=mysql_num_rows($result1);
$pagecount=$row1/5;
$pagecount=ceil($pagecount);
for ($count=1; $count <= $pagecount ; $count++) {
?>
<?php echo $count?>
<?php
}
}else{
$page1=$_GET['page'];
if ($page1=="" || $page1==1) {
$page1=0;
}
else{
$page1=($page1*5)-5;
}
$query="select * from tbl_news where news_status='Active' limit $page1,5";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
?>
<table class="table table-hover" border="2">
<col width="50%"></col>
<col width="40%"></col>
<col width="20%"></col>
<tr>
<td rowspan="3">
<a href="news_view.php?id=<?php echo $row['news_id'];?>">
<img src="<?php echo $row['news_image_location'].$row['news_image'];?>" height="300" width="500">
</a>
</td>
<td>Title: <?php echo $row['news_title'];?></td>
</tr>
<tr>
<td>Author: <?php echo $row['news_author'];?></td>
</tr>
<tr>
<td>Date: <?php echo $row['news_date_filed'];?></td>
</tr>
</thead>
</table>
<?php
}
$query1="select * from tbl_news where news_status='Active'";
$result1=mysql_query($query1);
$row1=mysql_num_rows($result1);
$pagecount=$row1/5;
$pagecount=ceil($pagecount);
for ($count=1; $count <= $pagecount ; $count++) {
?>
<?php echo $count?>
<?php # code...
}
}
?>
Please, i need assistance on how to generate a register for a transaction which is entered into the database daily as a register, group by each car. See my code below:
Selection Criteria:
<tr>
<td>Start Date:<input type="date" name="d1" class="form-control" id="datepicker" /></td>
<td>End Date:<input type="date" name="d2" class="form-control" id="datepicker" /></td>
<?php $s = mysqli_query($connection,"SELECT * FROM tab_location");?>
<td>Location:
<select name="loc" class="form-control">
<option>Select Location...</option>
<?php while($lo = mysqli_fetch_array($s)) { ?>
<option value="<?php echo $lo['location_name'];?>"><?php echo $lo['location_name'];?></option>
<?php } ?>
</select>
</td>
<td>Action:<input type="submit" name="sbt" class="form-control btn btn-success" value="Generate Report" /></td>
</tr>
Table to Display the result:
<table width="70%" border="0" style="margin-top:15px;" align="left" class="table table-bordered">
<thead>
<tr>
<th>S/N</th>
<th nowrap="nowrap">FLT NO</th>
<?php $list = array();
$month = date('m');
$year = date('Y');
$dy = cal_days_in_month(CAL_GREGORIAN,date('n'),date('Y'));
for($d=1; $d<=$dy; $d++) {
$time = mktime(12, 0, 0, $month, $d, $year);
if (date('m', $time) == $month)
$list[]=date('Y-m-d', $time);
}
foreach ($list as $li){
echo "<th>".$li."</th>";
}?>
</tr>
</thead>
<tbody>
<?php if(isset($_POST['sbt'])){
$loc = $_POST['loc'];
$d1 = $_POST['d1'];
$d2 = $_POST['d2'];
$c = 0;
$st = mysqli_query($connection, "SELECT DISTINCT(fltno),created_at,id,status FROM tab_ddaily WHERE loc='$loc' AND CAST(created_at as date) BETWEEN '$d1' AND '$d2' ORDER BY fltno");
while($r = mysqli_fetch_array($st)){
$c++;?>
<tr>
<td><?php echo $c;?></td>
<td nowrap="nowrap"><?php echo $r['fltno'];?></td>
<td nowrap="nowrap"><?php echo $r['status']=='Available'?'<img src="includes/images/pass.jpe" width="20" height="10" />':'<img src="includes/images/wrong.jpe" width="20" height="10" />';?></td>
</tr>
<?php }
} else {
$loc = "";
$d1 = "";
$d2 = "";
}?>
</tbody>
</table>
The Above produces:
I want it to produce:Distinct FLT No on a row with the status of each day spreading from the 1st day to the last day of the month. Kindly help on how to achieve this.
See structure and Data below:
[![enter image description here][2]][2]
I have modified the output array returned from database and then reiterate it to show FLT and status date-wise.
<tbody>
<?php if(isset($_POST['sbt'])){
$loc = $_POST['loc'];
$d1 = $_POST['d1'];
$d2 = $_POST['d2'];
$c = 1;
$st = mysqli_query($connection, "SELECT DISTINCT(fltno),created_at,id,status FROM tab_ddaily WHERE loc='$loc' AND CAST(created_at as date) BETWEEN '$d1' AND '$d2' ORDER BY fltno");
$temp = array();
while($r = mysqli_fetch_array($st)){
$temp[ $r['fltno'] ][ $r['created_at'] ] = array('id' => $r['id'], 'status' => $r['status']);
}
foreach($temp as $key => $values){
$dates = array_keys($values); ?>
<tr>
<td><?php echo $c;?></td>
<td nowrap="nowrap"><?php echo $key;?></td>
<?php foreach ($list as $li){
if(in_array($li, $dates)){ ?>
<td nowrap="nowrap"><?php echo ($values[$li]['status'] == 'Available') ? '<img src="includes/images/pass.jpe" width="20" height="10" />':'<img src="includes/images/wrong.jpe" width="20" height="10" />';?></td>
<?php } else{ ?>
<td nowrap="nowrap">n/a</td>
<?php }
} ?>
</tr>
<?php $c++;
}
} else {
$loc = "";
$d1 = "";
$d2 = "";
}?>
</tbody>
Outer loop is printing table row, SR_NO, FLT_NO and inner loop is printing status date wise.
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');
?>
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']; ?>"/>
in this edit file i have to choose the same picture file or another picture file to be able update the rows. but i want to be able to change whichever i want without touching the other rows. any ideas over here?
<?php
include('../config.php');
include ('../ac.thumbs.php');
if ($_GET['sil']) {
$sil = htmlspecialchars(stripslashes($_GET['sil']));
mysql_query("DELETE FROM CloseOut WHERE itemNO = $sil limit 1");
echo "<h1>$sil item nolu kayit silinmistir</h1><br>";
}
$edit = htmlspecialchars(stripslashes($_GET['edit']));
$data = mysql_query("SELECT * FROM CloseOut WHERE itemNO=$edit") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{ echo "
<center>
[ Delete ]<br>
<a href=../../large.php?f=upload/".$info['resim'], $thumblarge .">
<img src=../../small.php?f=upload/".$info['resim'], $thumbsmall .">
</a>";
$editresim = $info[resim];
$editisim = $info[isim];
$editalan1 = $info[alan1];
$editalan2 = $info[alan2];
$editalan3 = $info[alan3];
$editalan4 = $info[alan4];
}
//Resimlerin yuklenecegin yer
$target = "../../upload/";
//////////////////////////////////////////////////////////////////////
///////////////////////////////Resim1/////////////////////////////////
//////////////////////////////////////////////////////////////////////
$target1 = $target . basename( $_FILES['resim1']['name']) ;
//Formdan gelen bilgileri almasi icin
$resim=($_FILES['resim1']['name']);
$isim=$_POST['isim1'];
$alan1=$_POST['alan11'];
$alan2=$_POST['alan21'];
$alan3=$_POST['alan31'];
$alan4=$_POST['alan41'];
/////////////Formdaki bos alanlara bos bilgi kayit etmemesi icin////////////////////////
$updates = array();
if (!empty($resim))
$updates[] = 'resim="'.mysql_real_escape_string($resim).'"';
if (!empty($isim))
$updates[] = 'isim="'.mysql_real_escape_string($isim).'"';
if (!empty($alan1))
$updates[] = 'alan1="'.mysql_real_escape_string($alan1).'"';
if (!empty($alan2))
$updates[] = 'alan2="'.mysql_real_escape_string($alan2).'"';
if (!empty($alan3))
$updates[] = 'alan3="'.mysql_real_escape_string($alan3).'"';
if (!empty($alan4))
$updates[] = 'alan4="'.mysql_real_escape_string($alan4).'"';
$updates = implode(', ', $updates);
/////////////////////////////////////////////////////////////////////////////////////////
//update etmesi icin
if(move_uploaded_file($_FILES['resim1']['tmp_name'], $target1))
{
mysql_query("UPDATE CloseOut SET $updates WHERE itemNO='$edit' ");
echo "Tebrikler, ". basename( $_FILES['resim1']['name']). " isimli dosya yuklendi ve database'e basariyla islendi!<br>";
}
?>
<br>
<center>
<table width="900" border="5" style="background-color:white; "bordercolor="#000000">
<tr>
<td width="120" height="50" bgcolor= "545454"><b>RESIM</b></td>
<td width="120" height="50" bgcolor= "545454"><b>NAME</b></td>
<td width="120" height="50" bgcolor= "545454"><b>CATAGORY</b></td>
<td width="120" height="50" bgcolor= "545454"><b>QUANTITY</b></td>
<td width="120" height="50" bgcolor= "545454"><b>LOCATION</b></td>
<td width="120" height="50" bgcolor= "545454"><b>PRICE</b></td>
</tr>
<tr>
<form enctype="multipart/form-data" method="post" action="">
<td><input type="file" name="resim1" value="<?php echo $editresim;?>"> </td>
<td><input type="text" name="isim1" value="<?php echo $editisim;?>"> </td>
<td><input type="text" name="alan11" value="<?php echo $editalan1;?>"> </td>
<td><input type="text" name="alan21" value="<?php echo $editalan2;?>"> </td>
<td><input type="text" name="alan31" value="<?php echo $editalan3;?>"></td>
<td><input type="text" name="alan41" value="<?php echo $editalan4;?>"></td>
</tr>
<td colspan="5"><center><input type="submit"></center></td>
</form>
</table>
</center>