save image in xampp and show it in web php - php

The HTML upload form:
<form action="InformationData.php" method="post" enctype="multipart/form-data">
<label >Barangay Certification</label>
<input name="BarangayCertification" type="file" id="exampleInputFile1">
<button type="Submit" name="Submit" value="Upload">Submit</button>
</form>
The InformationData.php:
<?php
$conn = mysqli_connect("localhost", "root", "", "registration");
if($_POST['BarangayCertification']){
$BarangayCertification = $_POST['BarangayCertification'];
} else {
$BarangayCertification = "";
}
$sql = "INSERT INTO stakeholdersform (BarangayCertification) VALUES ($BarangayCertification);
?>
Code to show the image:
<?php
$conn = mysqli_connect("localhost", "root", "", "registration");
$informations = "SELECT * FROM stakeholderinformations";
$result = $conn->query($informations);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$BarangayCertification = $row['BarangayCertification'];
echo $BarangayCertification;
}
}
?>
I tried to echo it but nothing happens, but I can see the image in the database.

From PHP documentation
echo — Output one or more strings
So, no, you can not echo image.
What you could do is
echo '<img src="data:image/jpeg;base64,' . $BarangayCertification . '">'
Although there's an upper limit about the size of $BarangayCertification and I do not recommend storing image in your database.

If connection to databases is set correctly.this below code work.But at first you must create a directory upload in the root
form
<form action="InformationData.php" method="post" enctype="multipart/form-data">
<label >Barangay Certification</label>
<input name="BarangayCertification" type="file" id="exampleInputFile1">
<button type="Submit" name="Submit" value="Upload">Submit</button>
</form>
The InformationData.php:
<?php
$conn = mysqli_connect("localhost", "root", "", "registration");
if (isset($_POST("Submit"))){
if($_POST['BarangayCertification']){
// $BarangayCertification = $_POST['BarangayCertification'];
if (file_exists("upload/" . $_FILES["BarangayCertification"]["name"])) {
echo $_FILES["BarangayCertification"]["name"] . " <b>already exists.</b> ";
} else {
///creat upload in root
move_uploaded_file($_FILES["BarangayCertification"]["tmp_name"], "upload/" . $_FILES["BarangayCertification"]["name"]);
$BarangayCertification = "//".$_SERVER['HTTP_HOST'].'//'. "upload/" . $_FILES["file"]["name"];
}
} else {
$BarangayCertification = "";
}
}
$sql = "INSERT INTO stakeholdersform (BarangayCertification) VALUES ($BarangayCertification)";
?>
Code to show the image:
<?php
$conn = mysqli_connect("localhost", "root", "", "registration");
$informations = "SELECT * FROM stakeholderinformations";
$result = $conn->query($informations);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$BarangayCertification = $row['BarangayCertification'];
echo "<img src=".$BarangayCertification.">";
}
}
?>

Related

How to show comments on specific posts

I have an application that where users can post announcements and comment on posts. My problem is that whenever a comment is posted, It shows up on every announcement post. How can I post comments so that they show up on that specific post?
I have 2 database tables: "announcement: id, name, announcementTitle, announcement, image" and "comment: id, post_id, name, comment" with foreign key attached to comment.
Here is my home.php where the announcements and comments are echoed
<div class="container">
<div class="mx-auto">
<?php
if (isset($_SESSION['username'])) {
echo'
<h1 style="text-decoration:underline">Post an announcement</h1>
<form method="post" action="announcement.php" enctype="multipart/form-data">
<input type="text" name="announcementTitle" placeholder="Enter Subject"><br>
<textarea name="announcementBox" rows="5" cols="40" placeholder="Enter Announcement"></textarea><br>
<input type="file" name="image" accept="image/jpeg">
<button name="announcement">Submit</button>
</form>';
}
$query = "SELECT * FROM announcement ORDER BY id DESC";
$result = mysqli_query($con,$query);
while ($row = mysqli_fetch_array($result)) {
echo '<div class="row" style="color:black;background-color:white;border-radius:5px;padding:10px;margin-top:10px;margin-bottom:70px">';
echo '<div class="column" style="width:100%;border:5px">';
if (isset($_SESSION['username'])) {
echo '<form method="post" action="announcement.php">';
echo "Posted by " .$row["name"]. " click X to delete:";
echo '<input type="hidden" name="postID" value="'.$row['id'].'">';
echo '<button name="delete" style="float:right">X</button>';
echo '</form>';
}
echo $row['announcementTitle'].'<br>';
echo $row['announcement'].'<br>';
echo '<img width="20%" src="data:image;base64,'.$row['image'].'"alt="Image" style="padding-top:10px">';
echo'
<form method="post" action="comment.php">
<textarea name="commentbox" rows="2" cols="50" placeholder="Leave a Comment"></textarea><br>
<button name="comment">Submit</button>
</form>';
echo "Comments:<p><p>";
echo " <p>";
$find_comment = "SELECT * FROM comment ORDER BY id DESC";
$res = mysqli_query($con,$find_comment);
while ($row = mysqli_fetch_array($res)) {
echo '<input type="hidden" name="postID" value="'.$row['post_id'].'">';
$comment_name = $row['name'];
$comment = $row['comment'];
echo "$comment_name: $comment<p>";
}
if(isset($_GET['error'])) {
echo "<p>100 Character Limit";
}
echo '</div></div>';
}
?>
</div>
</div>
Here is comment.php where comments are put in the database
<?php
session_start();
$con = mysqli_connect('localhost', 'root', 'Arv5n321');
mysqli_select_db($con, 'userregistration');
$namee = '';
$comment = '';
$comment_length = strlen($comment);
if($comment_length > 100) {
header("location: home.php?error=1");
}else {
$que = "SELECT * FROM announcement";
$res = mysqli_query($con,$que);
while ($row = mysqli_fetch_array($res)) {
$post_id = $row['id'];
}
$namee = $_SESSION['username'];
$comment = $_POST['commentbox'];
$query = "INSERT INTO comment(post_id,name,comment) VALUES('$post_id','$namee','$comment')";
$result = mysqli_query($con, $query);
if ($result) {
header("location:home.php?success=submitted");
} else {
header("location:home.php?error=couldnotsubmit");
}
}
?>
Here is announcement.php where announcements are put in the database
<?php
session_start();
//$con = mysqli_connect('freedb.tech', 'freedbtech_arvindra', 'Arv5n321', 'freedbtech_remote') or die(mysqli_error($con));
$con = mysqli_connect('localhost', 'root', 'Arv5n321', 'userregistration') or die(mysqli_error($con));
if (isset($_POST['announcement'])) {
$image = $_FILES['image']['tmp_name'];
$name = $_FILES['image']['name'];
$image = base64_encode(file_get_contents(addslashes($image)));
date_default_timezone_set("America/New_York");
$title = $_POST['announcementTitle']." (<b>".date("m/d/Y")." ".date("h:i:sa")."</b>)";
$paragraph = $_POST['announcementBox'];
if (empty($paragraph)||empty($title)) {
header('location:home.php?error=fillintheblanks');
}else{
$nam = $_SESSION['username'];
$query = "insert into announcement(name,announcementTitle,announcement,image) values('$nam','$title','$paragraph','$image')";
$result = mysqli_query($con, $query);
if ($result) {
header("location:home.php?success=submitted");
} else {
header("location:home.php?error=couldnotsubmit");
}
}
}else if (isset($_POST['delete'])){
$query = "delete from announcement where id='".$_POST['postID']."';";
$result = mysqli_query($con,$query);
if ($result) {
header('location:home.php?success=deleted');
} else {
header('location:home.php?error=couldnotdelete');
}
}
else {
header('location:home.php');
}
I am a little new to PHP so any help is good.

Display BLOB data from SQLITE database using PHP

Hope You all have a Great Day, I new with SQLITE DB and so I'm little confused about handling BLOB data.I tried lot of things ,but nothing get in to favor of me.
Here is My Code
INSERTING DATA
insert.php
<form method="POST" enctype="multipart/form-data">
model no:<input type="text" name="model_no"\><span style="color: red"><?php echo $messages["model_no"]; ?></span>
image:<input type="file" name="image" id="image"\><span style="color: red">
<input type="submit" value="save" id="save" name="save"/>
<input type="reset" value="Clear"/>
</form>
include.php
<?php
$flag = 0;
class MyDB extends SQLite3
{
function __construct()
{
$this->open('../database.db');
}
}
//checking save button is clicked
if(isset($_POST["save"])){
$model_no = $_POST['model_no'];
$image = $_FILES['image']['name'];
if($model_no != '' && $image != ''){
$flag = 1;
}
if($flag == '1'){
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
}
else{
$dbb = new MyDB();
$sql = 'SELECT COUNT(*) as count FROM fisfis WHERE model_no = "'.$model_no.'"';
//echo $sql;
$rows = $dbb->query($sql);
$row = $rows->fetchArray();
$numRows = $row['count'];
//echo $numRows;
if($numRows != 0){
$flag = 0;
echo "error:this model no is already taken";
}else{
$sqlp = "INSERT INTO fisfis(model_no, image) values('$model_no','$image')";
if($dbb->exec($sqlp)){
echo "data inserted successfully\n";
}
else{
echo"error:\n";
echo "data not inserted \n";
echo"contact admin for details\n";
}
}
}
}
else{
echo"error:\n";
echo "data not inserted : data fields cannot be empty\n";
}
}
?>
this is very successfully inserting data in to my table (table name:fisfis)
DISPLAYING DATA
display.php
<form method="POST" enctype="multipart/form-data">
<p>Enter Barcode : <input type="text" name="search_model" id="search_model" /></p>
<!--<p><img src='image.php?id=<?php //echo $row['model_no'];?>'/></p>-->
<p><input type="submit" value="search" name="search" id="search"/></p>
</form>
display_include.php
<?php
$flag2 = 0;
$flag3 = 0;
class MyDB extends SQLite3
{
function __construct()
{
$this->open('../database.db');
}
}
$db = new MyDB();
if(isset($_POST["search"])){
$model_no = '';
$model_no = $_POST['search_model'];
if($model_no != ''){
$flag2 = 1;
}
if($flag2 == '1'){
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
}
else{
$dbb = new MyDB();
$sql = 'SELECT COUNT(*) as count FROM fisfis WHERE model_no = "'.$model_no.'"';
$rows = $dbb->query($sql);
$row = $rows->fetchArray();
$numRows = $row['count'];
echo $numRows;
if($numRows == 0){
echo 'sorry this model no is not exists';
echo '<br/>';
echo 'create new';
$flag2 = 1;
}else{
echo "this is exisists";
$flag3 = 1;
}
if($flag3 == 1){
$sqla = 'SELECT * FROM fisfis WHERE model_no = "'.$model_no.'"';
$result = $dbb->query($sqla);
while($row = $result->fetchArray(SQLITE3_ASSOC) ) {
echo "MODEL NO = ". $row['model_no'] ."\n";
$img = '\'<img src="'. $row['image'] .'" width="100" height="100"/>\'';
echo $img;
}
}
}
}
}
?>
the display part displaying all data other than blob ,what i have tried
1.try to echo the image inside the php script
$img = '\'<img src="'. $row['image'] .'" width="100" height="100"/>\'';
try to display image inside html tag
but this is not working,please help me to fix this,thanks in advance
My explaining is not good, so here is a show-and-tell. I made a repro so I wouldn't forget any necessary bits.
The database table is defined:
CREATE TABLE `imgrepro` (
`id` INTEGER NOT NULL,
`photo` BLOB,
PRIMARY KEY(`id`)
);
It is seeded with one row, id = 1, photo is NULL.
The POST block will insert the image into the BLOB column in the db. The rest of the script will fetch the image and the html will display it.
<?php
$db = new SQLite3("***********\stacktest.db");
if ($_SERVER['REQUEST_METHOD'] == "POST") {
// insert photo
$photo = file_get_contents($_FILES['fname']['tmp_name']);
$query = $db->prepare("UPDATE imgrepro set photo = :photo where id = 1");
$query->bindValue(':photo',$photo,SQLITE3_BLOB);
$result = $query->execute();
}
// get photo if there is one
$rows = $db->query("SELECT * from imgrepro")->fetchArray(SQLITE3_ASSOC);
$showphoto="";
if (count($rows) > 0) {
$showphoto=base64_encode($rows['photo']);
}
$db->close();
?>
<!DOCTYPE html>
<head>
<title>Say Cheese!</title>
</head>
<!-- show the photo -->
<img alt="no photo yet" src="data:image/jpeg;base64,<?= $showphoto ?>" >
<form action="imgrepro.php" method="post" enctype="multipart/form-data">
<input type="file" name="fname" accept=".jpg">
<input type="submit">
</form>

PHP PDO output in angular

I am trying to get output in Angular via PHP PDO but unable to understand the error.
When I write the same code using PHP procedural way (mysqli) then I can easily fetch the output. But I am struggling in fetching data with PHP PDO.
Here is my code:
Index.php:
<div ng-app="myapp" ng-controller="fieldcontroller" ng-init="displayData()">
<tr ng-repeat="field in fields">
<td>{{ field.fieldlabel }}</td>
</tr>
My JS File:
var app = angular.module("myapp",[]);
app.controller("fieldcontroller", function($scope, $http){
//Display Function
$scope.displayData = function(){
$http.get("model/select.php?type=getForm")
.then(function(response) {
$scope.fields = response.data;
console.log($scope.fields);
});
}
});
PHP File:
?php
//include('Database.php');
//select.php
//$connect = mysqli_connect("localhost", "kcmsuser", "KC+wSH&X#z9P", "kcms");
$server = 'localhost';
$user = 'kcmsuser';
$pass = 'KC+wSH&X#z9P';
$dbname = 'kcms';
$conn = new mysqli($server, $user, $pass, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo " Connected successfully ";
}
$sql = "SELECT * FROM form";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$output = array();
while($row = $result->fetch_array()) {
$output[] = $row;
}
} else {
echo "0 Results ";
}
echo json_encode($output);
Console.log shows:
[{"0":"110","id":"110","1":"First Name","fieldlabel":"First Name","2":"firstname","fieldname":"firstname","3":"text","fieldtype":"text","4":"","isprimary":"","5":"yes","required":"yes","6":"1","position":"1"},{"0":"23","id":"23","1":"Carrier","fieldlabel":"Carrier","2":"carrier","fieldname":"carrier","3":"text","fieldtype":"text","4":"no","isprimary":"no","5":"yes","required":"yes","6":"5","position":"5"},{"0":"26","id":"26","1":"Email","fieldlabel":"Email","2":"email","fieldname":"email","3":"email","fieldtype":"email","4":"","isprimary":"","5":"yes","required":"yes","6":"9","position":"9"},{"0":"27","id":"27","1":"Password","fieldlabel":"Password","2":"password","fieldname":"password","3":"password","fieldtype":"password","4":"","isprimary":"","5":"no","required":"no","6":"4","position":"4"},{"0":"102","id":"102","1":"Date of Birth","fieldlabel":"Date of Birth","2":"dob","fieldname":"dob","3":"date","fieldtype":"date","4":"","isprimary":"","5":"no","required":"no","6":"6","position":"6"},{"0":"101","id":"101","1":"Last Name","fieldlabel":"Last Name","2":"lastname","fieldname":"lastname","3":"text","fieldtype":"text","4":"","isprimary":"","5":"yes","required":"yes","6":"2","position":"2"}]
And [ngRepeat:dupes] warning.
I tried track by $index with ng-repeat but nothing happens.
I am new to Angular.
you can use pdo code for get data from mysql
<?php
$servername="localhost";
$username="";
$password="";
$dbname="";
$dsn="mysql:host=$servername;dbname=$dbname";
try{
$connect=new PDO ($dsn,$username,$password);
$connect->exec("SET NAMES 'utf8';");
}catch(PDOException $error){
echo "Error in connect".$error->getMessage();
exit();
}
$sql = "SELECT * from `table`";
$result = $connect->query($sql);
$num_row=$connect->query("SELECT count(id) from `table`")->fetchColumn();
if ($num_row > 0) {
$output = array();
while($row=$result->fetch(PDO::FETCH_ASSOC)) {
$output[] = $row;
}
} else {
echo "0 Results ";
}
?>
After spending few hours and hit and try message, I was able to sole the problem.
Problem was in the below PHP code:
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
echo " Connected successfully ";
}
Thanks....
sorry i was busy, i write code for you very fast if you have any proplem you can say me
<?PHP
if(#$_REQUEST['delete']){
/**************delete**************/
$delete=$_REQUEST['delete'];
if($connect->query("delete from table where id='$delete'")){
echo 'delete successful';
}}else if(#$_REQUEST['insert']=='record'){
/**************insert**************/
if(isset($_POST['submit'])){
$title=$_POST['title'];
if($connect->query("INSERT INTO `table`(`title`) VALUES ('$title')")){
echo 'success'; }else{ echo 'error'; }
}}else if(#$_REQUEST['edit']=='record'){
/**************insert**************/
if(isset($_POST['submit'])){
$title=$_POST['title'];
$mid=$_POST['mid'];
if($connect->query("UPDATE `table` SET `title`='$title'")){
echo 'success'; }else{ echo 'error'; }
}} ?>
<h1><?PHP if(#$_REQUEST['edit']=='new'){?>insert<?PHP }else if(#$_REQUEST['edit']=='new'){?>edit<?PHP }else{?>manage<?PHP }?><h1>
<br>insert
<?PHP
if(#$_REQUEST['edit']=='new'){
$id=$_REQUEST['id'];
$checks=$connect->query("select * from table where id='$id' order by id desc");
$check=$checks->fetch(PDO::FETCH_ASSOC);
?>
<form>
<input type="text" name="title" value="<?=$check['title']?>">
<input type="hidden" name="edit" value="record">
<input type="hidden" name="mid" value="<?=$check['id']?>">
<input type="submit" value="edit" name="submit"/>
</form>
<?PHP }else if(#$_REQUEST['insert']=='new'){?>
<form>
<input type="text" name="title">
<input type="hidden" name="insert" value="record">
<input type="submit" value="create" name="submit"/>
</form>
<?PHP
}else{
$radif=0;
$qacs=$connect->query("select * from table order by id desc");
while ($qc=$qacs->fetch(PDO::FETCH_ASSOC)){$radif++;
?>
<tr>
<td scope="row"><?=$radif?></td>
<td><?=$qc['title']?></td>
<td>delete</td>
<td>edit</td>
<?PHP }}?>

can't upload multiple files in a form

I'm sorry if this is a repost. But I have seen many questions without finding the right answer
i'm trying to upload multiple files + some information , but if i submit my form with 2 images it goes ok and the script runs perfect when i upload more then 2 or 3 files i get undefined indexs of all the form elements .
up.php
/////// Random name generator ////////
function random_name($length) {
$key = '';
$keys = array_merge(range(0, 9), range('a', 'z'));
for ($i = 0; $i < $length; $i++) {
$key .= $keys[array_rand($keys)];
}
return $key;
}
//sql//
require("sql.php");
//////////
//!!! some vars !!!//
//
$total = count($_FILES['pimages']['name']);
//
$foldername = random_name(15);
$target_dir = "../images/projects/".$foldername."/";
$target_file = $target_dir . basename($_FILES["icon"]["name"]);
$uploadyes = 1;
$imageType = pathinfo($target_file,PATHINFO_EXTENSION);
$saveicon = $target_dir . "icon." .$imageType;
/////submited form vars /////
$linkedid = $_POST['lid'];
$date = date("y.m.d H:i:s");
$name = $_POST['projectname'];
$loc = $_POST['location'];
$type = $_POST['type'];
$des = $_POST['des'];
$precara = $_POST['cara'];
$client = $_POST['client'];
$col = $_POST['cost'];
$bua = $_POST['builtup'];
////////////////cara slice /////////////
$caraxarray = explode("," , $precara);
$cara = base64_encode(serialize($caraxarray));
echo $imageType ;
///////////////////////// Start of the upload check ////////////////////
if(isset($_POST['submit']) && !empty($name)) {
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
}
// Check if $uploadyes is set to 0 by an error
if (!isset($_POST['submit'])) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
mkdir($target_dir);
if (move_uploaded_file($_FILES["icon"]["tmp_name"], $saveicon)) {
//////////////////////////..........................//////////////////
// Loop through each file
$imgext = array();
for($i=0; $i<=$total; $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['pimages']['tmp_name'][$i];
$x = $i + 1 ;
if ($tmpFilePath != ""){
//Setup our new file path
$pimgex = $_FILES['pimages']['name'][$i];
$pimageType = pathinfo($pimgex,PATHINFO_EXTENSION);
$newFilePath = $target_dir ."img".$x.".".$pimageType;
array_push($imgext , "$newFilePath");
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
echo "yeaaaaaah";
}
}
}
$str = serialize($imgext);
$sql1 = "INSERT INTO projects (date, name, type, location, icon, imgext, folder, linkedid)
VALUES ('$date', '$name','$type', '$loc', '$saveicon' , '$str', '$foldername', '$linkedid')";
$sql2 = "INSERT INTO projectdetails (proname, prolocation, prodes, procara, client, col, builtarea, linkedid)
VALUES ('$name', '$loc','$des', '$cara', '$client' , '$col', '$bua', '$linkedid')";
mysqli_query($conn ,$sql1);
mysqli_query($conn ,$sql2);
mysqli_close($conn);
/////////////////...........................////////////////////////
header("location:cp.php");
} else {
echo "Sorry, there was an error uploading your file.";
}
}
projectsuploader.php
$lkid = random_name(8);
$tlink = random_name(6);
require("sql.php");
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql1 = "SELECT id, date, name, type, location FROM projects";
$sql2 = "SELECT id, titleen FROM projectsnav";
$result = mysqli_query($conn, $sql1);
$types = mysqli_query($conn, $sql2);
//mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<h2>Projects Page</h2>
<h5>projects</h5>
<table>
<tr>
<td>#</td>
<td>Date & Time</td>
<td>Project name</td>
<td>Project type</td>
<td>Project location</td>
<!--<td>View</td>
<td>Edit</td>-->
<td>Remove</td>
</tr>
<?php
if (mysqli_num_rows($result) > 0) {
// output data of each row .$row["id"]
while($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>".$row["id"]."</td>";
echo "<td>".$row["date"]."</td>";
echo "<td>".$row["name"]."</td>";
echo "<td>".$row["type"]."</td>";
echo "<td>".$row["location"]."</td>";
echo "<td><a href='../del.php?id=".$row['id']."'>Remove</a></td> </tr>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
</table>
<h4 id="addproject">Add Project</h3>
<h4 id="addtype">Add Type </h4>
<div id="frontlayer">
<div id="addpro">
<h2 style="text-align:center;"> add project </h2>
<form method="POST" action="up.php" enctype="multipart/form-data" >
<input type="hidden" name="MAX_FILE_SIZE" value="50000000">
id:<input type="text" name="lid" value="<?php echo $lkid ; ?>" readonly> <br>
project name:<input type="text" name="projectname"><br>
Type:<select name="type">
<?php
if (mysqli_num_rows($types) > 0){
while($navrow = mysqli_fetch_assoc($types)) {
echo "<option value='".$navrow['titleen']."'>".$navrow['titleen']." </option>";
}
}else{
echo "<option>PLEASE ADD TYPES TO DATABASE FIRST!!!!ERROR 0 TYPES IN DATABASE</option>";
}
mysqli_close($conn);
?>
</select>
<br>
location:<input type="text" name="location"><br>
icon:<input type="file" name="icon" id="icon"><br>
images:<input type="file" name="pimages[]" id="pimages" multiple><br>
<input type="hidden" name="sendfiles" value="Send Files" />
<!--
------//////////////------
------//////////////------
------//////////////------
-->
description:<input type="text" name="des"><br>
caracteristic:<input type="text" name="cara" data-role="tagsinput"><br>
client:<input type="text" name="client"><br>
Collaborator:<input type="text" name="cost"><br>
Gross Area:<input type="text" name="builtup"><br>
<input type="submit" value="Upload" name="submit">
</form>
</div>
Sorry if it is bad writed i\m begginer , Thanks in advance for anyhelp
The problem were that there was a big file (4mb image) and php was not able to post this size of an image so you have to resize your image before upload ..
and big thanks for Felippe Duarte.

php, sql, html updating a unique record with corresponding button

I am new to PHP and SQL and trying to figure out how I can make the HTML Approve (submit) button interact specifically with its corresponding record. Currently when the Approve button is clicked, each of the fields are updated, but the top (first) record available is always the one updated. I would like the user to be able to skip the first record and update a different record. Any and all suggestions/help are greatly appreciated.
$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('there was a problem connecting to the database' . mysql_error());
$sql = "SELECT Part, Lot, Qty, AnodTemp, Amp, SealTemp, PerformedBy, DateTimePerformed, FinalAnodThickness, QtyPass, FinalSealCheck, CheckedBy, DateTimeChecked, id FROM logs";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$unapproved = $row['CheckedBy'];
if($unapproved == null)
{
echo "<br><br><br> Part: " . $row['Part']. " / Lot: " . $row['Lot']. " / Qty: " . $row['Qty']. " / AnodTemp: " . $row['AnodTemp']. " / Amp: " . $row['Amp']. " / SealTemp: " . $row['SealTemp']. " / PerformedBy: " . $row['PerformedBy']. " / ID: " . $row['id']; ?>
<form action="adminapproval.php" method="post">
Final Anod Thickness:<br>
<input type="text" name="FinalAnodThickness">
<br><br>
Qty Pass:<br>
<input type="text" name="QtyPass">
<br><br>
Final Seal Check:<br>
<input type="text" name="FinalSealCheck">
<br><br>
<input type="submit" id="submit" value="Approve" name="submit">
<br><br>
</form>
_____________________________________________________________________<br>
<?php
if (isset($_POST['submit']))
{
$FinalAnodThickness= $_POST['FinalAnodThickness'];
$QtyPass= $_POST['QtyPass'];
$FinalSealCheck= $_POST['FinalSealCheck'];
$CheckedBy= $_SESSION['CheckedBy'];
$id = $row['id'];
$sql = "UPDATE logs SET FinalAnodThickness = '$FinalAnodThickness', QtyPass = '$QtyPass', FinalSealCheck = '$FinalSealCheck', CheckedBy = '$CheckedBy', DateTimeChecked = now() WHERE id = $id ";
$conn->query($sql);
break;
$conn->close();
echo "Record Updated.";
header("Location: adminapproval.php");
}
}
}
}
echo "<br><br> No further items need to be approved at this time.";
?>
TWO FILES
adminapproval.php
<?php
session_start();
$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('there was a problem connecting to the database' . mysql_error());
$sql = "SELECT Part, Lot, Qty, AnodTemp, Amp, SealTemp, PerformedBy, DateTimePerformed, FinalAnodThickness, QtyPass, FinalSealCheck, CheckedBy, DateTimeChecked, id FROM logs";
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$unapproved = $row['CheckedBy'];
if($unapproved == null){
echo "<br><br><br> Part: " . $row['Part']. " / Lot: " . $row['Lot']. " / Qty: " . $row['Qty']. " / AnodTemp: " . $row['AnodTemp']. " / Amp: " . $row['Amp']. " / SealTemp: " . $row['SealTemp']. " / PerformedBy: " . $row['PerformedBy']. " / ID: " . $row['id']; ?>
<form action="adminapproval-exec.php?id=<?php echo $row['id']; ?>" method="post">
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" />
<input type="hidden" name="checkedby" value="<?php echo $SESSION['CheckedBy']; ?>" />
Final Anod Thickness:<br>
<input type="text" name="FinalAnodThickness">
<br><br>
Qty Pass:<br>
<input type="text" name="QtyPass">
<br><br>
Final Seal Check:<br>
<input type="text" name="FinalSealCheck">
<br><br>
<input type="submit" id="submit" value="Approve" name="submit">
<br><br>
</form>
<?php
}
}
} else {
echo "<br><br> No further items need to be approved at this time.";
}
?>
adminapproval-exec.php
<?php
session_start();
if (isset($_POST['submit'])){
$FinalAnodThickness= $_POST['FinalAnodThickness'];
$QtyPass= $_POST['QtyPass'];
$FinalSealCheck= $_POST['FinalSealCheck'];
$CheckedBy= $_POST['CheckedBy'];
$id = $_GET['id'];
// OR
// $id = $_POST['id'];
$sql = "UPDATE logs SET FinalAnodThickness = '$FinalAnodThickness', QtyPass = '$QtyPass', FinalSealCheck = '$FinalSealCheck', CheckedBy = '$CheckedBy', DateTimeChecked = now() WHERE id = $id ";
$conn->query($sql);
$conn->close();
// echo "Record Updated.";
header("Location: adminapproval.php");
}
?>
<?php
$server = "localhost";
$username = "username";
$password = "password";
$dbname = "db";
$con = mysqli_connect($server, $username, $password, $dbname);
if (!$con) {
die("Faild: " . mysqli_connect_error());
}
$sql = "UPDATE xxx SET lastname='Jan' WHERE id=2"; // This is importat
if (mysqli_query($con, $sql)) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . mysqli_error($con);
}
mysqli_close($con);
?>
$CheckedBy= $_SESSION['CheckedBy'];
$id = $row['id'];
Should the row id be coming out of the session as well? If not, then it will always be pointing to the first item in the row.

Categories