I would like to retrieve images from phpmyadmin database. Currently, the link of the picture is saved in the database. But when I retrieve it, nothing was shown.
//form2.php (uploading of image)
<div>
<label>Attachment:</label><input type='file' name='img'><br>
</div>
//insert2.php
<?php
$con= mysqli_connect('127.0.0.1','root','');
if(!$con)
{
echo 'Not Connected To Server';
}
if(!mysqli_select_db($con,'satsform1'))
{
echo 'Database Not Selected';
}
$name = $_GET['name'];
$staffno = $_GET['staffno'];
$date = $_GET['date'];
$time = $_GET['time'];
$email = $_GET['email'];
$mobno = $_GET['mobno'];
$roles = $_GET['roles'];
$location = $_GET['location'];
$flightno = $_GET['flightno'];
$flightdate = $_GET['flightdate'];
$seatno = $_GET['seatno'];
$class = $_GET['class'];
$description = $_GET['description'];
$image = $_GET['img'];
$remarks = $_GET['remarks'];
$sql = "INSERT INTO handover (name,staffno,date,time,email,mobno,roles,location,flightno,flightdate,seatno,class,description,image,remarks,status)
VALUES ('$name','$staffno','$date','$time','$email','$mobno','$roles','$location','$flightno','$flightdate','$seatno','$class','$description','$image','$remarks','Pending')";
if(!mysqli_query($con,$sql))
{
echo 'Not Submitted';
}
else
{
echo 'Submitted';
}
header("refresh:2; url=selection.php")
?>
<?php
//fetch3.php
$connect = mysqli_connect('127.0.0.1','root','', 'satsform1');
$output = '';
if(isset($_POST["query"]))
{
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM handover
WHERE name LIKE '%".$search."%'
OR staffno LIKE '%".$search."%'
OR date LIKE '%".$search."%'
OR email LIKE '%".$search."%'
OR mobno LIKE '%".$search."%'
OR roles LIKE '%".$search."%'
OR location LIKE '%".$search."%'
OR flightno LIKE '%".$search."%'
OR flightdate LIKE '%".$search."%'
OR seatno LIKE '%".$search."%'
OR class LIKE '%".$search."%'
";
}
else
{
$query = "
SELECT * FROM handover ORDER BY ID
";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>ID</th>
<th>Staff Name</th>
<th>Staff Number</th>
<th>Date</th>
<th>Time</th>
<th>Email</th>
<th>Mobile Number</th>
<th>Roles</th>
<th>Location</th>
<th>Flight Number</th>
<th>Flight Date</th>
<th>Seat Number</th>
<th>Class of Travel</th>
<th>Image</th>
<th> Status </th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["ID"].'</td>
<td>'.$row["name"].'</td>
<td>'.$row["staffno"].'</td>
<td>'.$row["date"].'</td>
<td>'.$row["time"].'</td>
<td>'.$row["email"].'</td>
<td>'.$row["mobno"].'</td>
<td>'.$row["roles"].'</td>
<td>'.$row["location"].'</td>
<td>'.$row["flightno"].'</td>
<td>'.$row["flightdate"].'</td>
<td>'.$row["seatno"].'</td>
<td>'.$row["class"].'</td>
<td><img src="'.$row["img"].'"></td>
<td>'.$row["status"].'</td>
<td> <form action="edit3.php" method="GET">
<input type="hidden" name="update_id" value="'.$row["ID"].'">
<button type="submit">update </button>
</form>
</td>
</tr>
';
}
echo $output;
}
else
{
echo 'Data Not Found';
}
?>
I expect the picture of a particular row will be shown and display the image. So, when I doing the live search engine, the picture will appear under the image column according to their row.
Please change this:
<td><img src="'.$row["img"].'"</td>
To this:
<td><img src="'.$row["img"].'"></td>
Hope this help.
Related
I'm trying to update the status to 'Approved' from pending by clicking the update button. However when i click on the button it does not respond and change the status. But if I hardcode the ID, the status is able to update. How do I get the ID capture from the database and update the status once click on the button?
//edit1.php:
<?php
$con= mysqli_connect('127.0.0.1','root','');
if(!$con)
{
echo 'Not Connected To Server';
}
if(!mysqli_select_db($con,'satsform1'))
{
echo 'Database Not Selected';
}
$ID = 'ID';
$sql = "update handover set status= 'Approved' where ID = '$ID'";
if(!mysqli_query($con,$sql))
{
echo 'Not Submitted';
}
else
{
echo "<meta http-equiv='refresh' content='0;url=index3.php'>";
}
?>
<?php
//fetch3.php
$connect = mysqli_connect('127.0.0.1','root','', 'satsform1');
$output = '';
if(isset($_POST["query"]))
{
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM handover
WHERE name LIKE '%".$search."%'
OR staffno LIKE '%".$search."%'
OR date LIKE '%".$search."%'
OR email LIKE '%".$search."%'
OR mobno LIKE '%".$search."%'
OR roles LIKE '%".$search."%'
OR location LIKE '%".$search."%'
OR flightno LIKE '%".$search."%'
OR flightdate LIKE '%".$search."%'
OR seatno LIKE '%".$search."%'
OR class LIKE '%".$search."%'
";
}
else
{
$query = "
SELECT * FROM handover ORDER BY ID
";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>ID</th>
<th>Staff Name</th>
<th>Staff Number</th>
<th> Status </th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["ID"].'</td>
<td>'.$row["name"].'</td>
<td>'.$row["staffno"].'</td>
<td>'.$row["status"].'</td>
// this is the update button where use the edit1.php to update the status by ID
<td> <form action="edit1.php" method="GET">
<button type="submit">update </button>
</form>
</td>
</tr>
';
}
echo $output;
}
else
{
echo 'Data Not Found';
}
?>
I expect the output to be able to update the status to 'Approved' into the database after clicking the update button.
Try this:
//edit1.php:
<?php
$con= mysqli_connect('127.0.0.1','root','');
if(!$con) {
echo 'Not Connected To Server';
}
if(!mysqli_select_db($con,'satsform1')) {
echo 'Database Not Selected';
}
if ( isset( $_GET['update_id'] ) && is_numeric( $_GET['update_id'] ) ) {
$ID = $_GET['update_id'];
$sql = "update handover set status= 'Approved' where ID = '$ID'";
if(!mysqli_query($con,$sql)) {
echo 'Not Submitted';
}
else {
echo "<meta http-equiv='refresh' content='0;url=index3.php'>";
}
}
?>
<?php
//fetch3.php
$connect = mysqli_connect('127.0.0.1','root','', 'satsform1');
$output = '';
if(isset($_POST["query"])) {
$search = mysqli_real_escape_string($connect, $_POST["query"]);
$query = "
SELECT * FROM handover
WHERE name LIKE '%".$search."%'
OR staffno LIKE '%".$search."%'
OR date LIKE '%".$search."%'
OR email LIKE '%".$search."%'
OR mobno LIKE '%".$search."%'
OR roles LIKE '%".$search."%'
OR location LIKE '%".$search."%'
OR flightno LIKE '%".$search."%'
OR flightdate LIKE '%".$search."%'
OR seatno LIKE '%".$search."%'
OR class LIKE '%".$search."%'
";
}
else {
$query = "
SELECT * FROM handover ORDER BY ID
";
}
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0) {
$output .= '
<div class="table-responsive">
<table class="table table bordered">
<tr>
<th>ID</th>
<th>Staff Name</th>
<th>Staff Number</th>
<th> Status </th>
</tr>
';
while($row = mysqli_fetch_array($result)) {
$output .= '
<tr>
<td>'.$row["ID"].'</td>
<td>'.$row["name"].'</td>
<td>'.$row["staffno"].'</td>
<td>'.$row["status"].'</td>
// this is the update button where use the edit1.php to update the status by ID
<td>
<form action="edit1.php" method="GET">
<input type="hidden" name="update_id" value="'.$row["ID"].'">
<button type="submit">update </button>
</form>
</td>
</tr>
';
}
echo $output;
}
else {
echo 'Data Not Found';
}
?>
Adding the input field as type=hidden and set the ID in the value of this field. Before update query, I have checked that the id is set or not if it's set only then run the update query otherwise do nothing. You may add else as well as per requirement.
i have a website project, where customers will need to search and the results will display, so i have done all that, but the problem is when a search results comes up,if there's more than 1 row,it dublicate the results on the same row,here are the code.
<h1 style="font-family:calibri;color:#13CC0D;text-align:center;">BODABODA SEARCH RESULTS</h1>
<table cellpadding="1" cellspacing="1" id="resultTable">
<thead>
<tr>
<th style="border-left: 1px solid #C1DAD7"> Region</th>
<th> District </th>
<th> Ward </th>
<th> Street</th>
<th> Driver Name </th>
<th>Identification Type</th>
<th>Identification Number</th>
<th>Motorcycle Type</th>
<th>Motorcycle Reg No</th>
<th>Phone Number</th>
</tr>
</thead>
<?php
$conn = mysqli_connect('localhost', 'efalococ_calcia', '*ad4#zNQ=nfN') or die('can not connect to the server'.mysqli_error);
mysqli_select_db($conn, 'efalococ_safirii');
if(isset($_POST['search'])){
$query = $_POST['region'];
$query1 = $_POST['district'];
$query2 = $_POST['ward'];
$query3 = $_POST['street'];
$results = mysqli_query($conn,"SELECT * FROM bodaboda WHERE (`region` LIKE '%".$query."%') && (`district` LIKE '%".$query1."%') && (`ward` LIKE '%".$query2."%') && (`street` LIKE '%".$query3."%')") or die(mysql_error());
if(mysqli_num_rows($results) >0){
while($row = mysqli_fetch_array($results)){
echo "<td>".$row['Region']."</td>" ;
echo "<td>".$row['District']."</td>";
echo "<td>".$row['Ward']."</td>";
echo "<td>".$row['Street']."</td>";
echo "<td>".$row['DriverName']."</td>";
echo "<td>".$row['IdentificationType']."</td>";
echo "<td>".$row['IdentificationNumber']."</td>";
echo "<td>".$row['MotorcycleType']."</td>";
echo "<td>".$row['MotorcycleRegNo']."</td>";
echo "<td>".$row['PhoneNumber']."</td>";
}
}else{
echo '<span style="color:red;font-family:cursive;font-size:14px;">No results found, Please Modify your search </span> Click here'.mysqli_error($conn);
}
}
?>
</table>
And the results shows like this!
Can you please help on that? any idea?
You just need to use the <tr> for every row.
The tag defines a row in an HTML table.
Learn more about HTML tr tag
while($row = mysqli_fetch_array($results)) {
echo "<tr>";
echo "<td>".$row['Region']."</td>" ;
echo "<td>".$row['District']."</td>";
echo "<td>".$row['Ward']."</td>";
echo "<td>".$row['Street']."</td>";
echo "<td>".$row['DriverName']."</td>";
echo "<td>".$row['IdentificationType']."</td>";
echo "<td>".$row['IdentificationNumber']."</td>";
echo "<td>".$row['MotorcycleType']."</td>";
echo "<td>".$row['MotorcycleRegNo']."</td>";
echo "<td>".$row['PhoneNumber']."</td>";
echo "</tr>";
}
This is my code I just need to add pagination to my code, I try some other example but it failed to work.
In my HTML code I add pagination raw (<<1,2,3,4>>)
its working in Wordpress using a database connection
The URL is like ?eventid=#ID
I checked many codes and example in SO but I failed
function ee_attendee_list($atts){
global $wpdb, $post;
$EVT_ID = $atts['eventid'];
$post = get_post( $EVT_ID );
echo '
';
$sql = "SELECT ATT_fname, ATT_lname, ATT_email, ATT_address, ATT_phone, STA_ID ";
$sql .= "FROM {$wpdb->prefix}esp_attendee_meta ";
$sql .= "INNER JOIN {$wpdb->prefix}esp_registration ";
$sql .= "ON {$wpdb->prefix}esp_attendee_meta.ATT_ID = {$wpdb->prefix}esp_registration.ATT_ID ";
$sql .= "WHERE {$wpdb->prefix}esp_registration.EVT_ID = %d";
$attendees = $wpdb->get_results( $wpdb->prepare( $sql, $post->ID ));
echo '<table class="blueTable">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
<th>State</th>
<th>Country</th>
</tr>
</thead>
<tfoot><tr>
<td colspan="6">';
echo '
<div class="links">« <a class="active" href="#">1</a> 2 3 4 »</div>
</td>
</tr>
</tfoot>
<tbody>';
foreach($attendees as $attendee){
$fname = $attendee->ATT_fname;
$lname = $attendee->ATT_lname;
$email = $attendee->ATT_email;
if (empty($attendee->ATT_phone)){ $phone = "No Phone"; } else { $phone = $attendee->ATT_phone; }
if (empty($attendee->ATT_address)){ $address = "No Address"; } else { $address = $attendee->ATT_address; }
$STA_ID = $attendee->STA_ID;
echo "
<tr>
<td>$fname $lname</td>
<td>$email</td>
<td>$phone</td>
<td>$address</td>
<td>$statename</td>
<td>$country</td>
</tr>
";
}
echo "</tbody>
</tr>
</table> ";
}
I need help with the table. They are not organized/neat and very confusing ->
The table has to look neat, understandable and not confusing like this -> (this is how the table should look like)
This is what I have achieved so far (See: OrderID 2) -> http://i.imgur.com/fj06EGB.png
Below is the code
<table>
<tr>
<th>Customer Name</th>
<th>Customer Contact</th>
<th>Customer Email</th>
<th>Order ID</th>
<th>Order Date</th>
<th>Menu Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total Amount</th>
<th>Action</th>
</tr>
<?php
$result = $mysqli->query("SELECT * FROM `order`");
while($obj = mysqli_fetch_assoc($result)) {
$orderDate = $obj['OrderDate'];
$orderId = $obj['OrderID'];
$totalAmount = $obj['OrderTotal'];
$paymentStatus = $obj['PaymentStatus'];
$customerId = $obj['CustomerID'];
$res = $mysqli->query("SELECT CustomerName, CustomerContactNo, CustomerEmail FROM customer WHERE CustomerID=$customerId");
if($row = mysqli_fetch_assoc($res)) {
$customerName = $row['CustomerName'];
$customerContactNo = $row['CustomerContactNo'];
$email = $row['CustomerEmail'];
}
$result1 = $mysqli->query("SELECT * FROM ordermenu WHERE OrderID = $orderId");
while($obj1 = mysqli_fetch_assoc($result1)) {
$menuId = $obj1['MenuID'];
$menuQty = $obj1['menuQty'];
$result2 = $mysqli->query("SELECT * FROM menu WHERE MenuID = $menuId");
$obj2 = mysqli_fetch_assoc($result2);
$name = $obj2['MenuName'];
$price = $obj2['MenuPrice'];
?>
<tr>
<td><?php echo $customerName;?></td>
<td><?php echo $customerContactNo;?></td>
<td><?php echo $email;?></td>
<td><?php echo $orderId;?></td>
<td><?php echo $orderDate;?></td>
<td><?php echo $name;?></td>
<td>$<?php echo $price;?></td>
<td><?php echo $menuQty;?></td>
<td>$<?php echo $totalAmount;?></td>
<td>Update</td>
</tr>
<?php } ?>
<?php } ?>
</table>
Anyone help please.
First get Customers From db
Foreach customer get Orders by customerID joined with ordermenu (on ordermenu.OrderID = order.OrderID) and joined with menu (on ordermenu.MenuID = menu.MenuID)
<?php
$customerQuery = $mysqli->query("SELECT CustomerID, CustomerName, CustomerContactNo, CustomerEmail FROM customer;");
while($customer = mysqli_fetch_assoc($customerQuery)) {
$customerId = $customer['CustomerID'];
$orderQuery = $mysqli->query("SELECT * FROM `order` o LEFT JOIN ordermenu om ON o.OrderID = om.OrderID LEFT JOIN menu m ON m.MenuID = om.MenuID WHERE o.CustomerID = $customerId");
while($order = mysqli_fetch_assoc($orderQuery)) {
// do something with your customer and order record
// show in table for example
}
}
I had a previous question on here a few minutes ago about a syntax error that was sorted. I need help getting this script working or at least for someone to point me in the right direction.
This is a search script to search by multiple fields. The search() array works fine and is a series of tickboxes with the following code:
<td width="22"><input type="checkbox" name="search[olevel = 'Yes']" id="search[olevel = 'Yes']" value="1"/>
The postcode box is a text box with the following code:
<input name="postcode[]" type="text" id="postcode[]" size="12" maxlength="12" /></td>
When I tick the olevel box it returns all the records that have Yes in the olevel field. That works as I expect.
If I put in anything in the postcode box it returns no results.
Here is the php code for the search engine.
<?php
include ('c1.php');
if ($_COOKIE["auth"] == "1") {
$display_block = "<p>You are an authorized user.</p>";
} else {
header("Location: userlogin.html");
exit;
}
doDB();
$display_block = "<h1>Results</h1>";
if (isset($_POST['search']) && !empty($_POST['search'])) {
foreach ($_POST['search'] as $key => $value) {
if ($value == 1)
$search[] = "$key";
$searchstring = implode(' AND ', $search);
$post_map = array(
'postcode' => 'candididate_contact_details.postcode'
);
}
if (isset($_POST['postcode']) && !empty($_POST['postcode'])) {
foreach ($_POST['postcode'] as $key => $value) {
if (array_key_exists($key, $post_map))
$search[] = $post_map[$key] . '=' . mysql_real_escape_string($value);
echo $searchstring;
echo $search;
$query = "SELECT candidate_id.master_id, candidate_contact_details.first_name, candidate_contact_details.last_name, candidate_contact_details.home_phone, candidate_contact_details.work_phone, candidate_contact_details.mobile_phone, candidate_contact_details.email FROM candidate_id, candidate_contact_details, qualifications, security_experience, previous_career WHERE qualifications.active = 'finished' and candidate_id.master_id = candidate_contact_details.master_id and candidate_id.master_id = qualifications.master_id and candidate_id.master_id = security_experience.master_id and candidate_id.master_id = previous_career.master_id and $searchstring";
$query_res = mysqli_query($mysqli, $query)
or die(mysqli_error($mysqli));
// $search = mysqli_query($mysqli, $query)or die(mysqli_error($mysqli));
{
$display_block .= "
<table width=\"98%\" cellspacing=\"2\" border=\"1\">
<tr>
<th>Registration Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Home Number</th>
<th>Work Number</th>
<th>Mobile Number</th>
<th>E-Mail</th>
</tr>";
while ($result = mysqli_fetch_array($query_res)) {
$regnum = $result['master_id'];
$first_name = $result['first_name'];
$last_name = $result['last_name'];
$home_phone = $result['home_phone'];
$work_phone = $result['work_phone'];
$mobile_phone = $result['mobile_phone'];
$email = $result['email'];
$display_block .= "
<tr>
<td align=\"center\">$regnum <br></td>
<td align=\"center\">$first_name <br></td>
<td align=\"center\">$last_name <br></td>
<td align=\"center\">$home_phone <br></td>
<td align=\"center\">$work_phone <br></td>
<td align=\"center\">$mobile_phone <br></td>
<td align=\"center\">$email <br></td>
</tr>";
}
$display_block .= "</table>";
}
}
}
}
?>
<html>
<head>
<title> Display results</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>
I know I am doing something wrong but cannot quite figure it out. Thanks in advance.
if I understand correctly, you have several postcodes per form.
then id="postcode[]" is wrong as there will be several id named the same in dom.
just delete that from your code.