why <input = "file"> on modal can't pass image to php - php

I'm rookie at php and html, i have this modal that has in it which i need for inserting an image..
if (isset($_POST['add_roomtype_action'])) {
require 'script/addRoomType.php';
}
<div class="modal fade" id="add_roomtype_modal" tabindex="-1" role="dialog"
aria-labelledby="add_roomtype_modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-
hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Add Room Type</h4>
</div>
<form action="room_management.php" method="post"
autocomplete="off">
<div class="modal-body">
<input type="hidden" id="upd_roomtype_id" name =
"add_roomtype_idnm">
<label style="font-size: 10pt">Room Type : </label>
<input type="text" id="add_roomtype" name = "add_roomtypenm"
style="font-size: 10pt" ><br></br>
<label style="font-size: 10pt">Rate : </label>
<input type="text" id="addupd_rate" name = "add_ratenm"
style="font-size: 10pt" ><br></br>
<label style="font-size: 10pt">Image : </label>
<input type="file" id ="add_roomtypeImgid"
name="add_roomtypeImgnm" accept="image/x-png,image/jpeg">
</div>
<div class="modal-footer">
<button type="button" class="btn" data-
dismiss="modal">Close</button>
<button type="submit" class="btn" id = "add_roomtype_action"
name = "add_roomtype_action">Add</button>
</div>
</form>
</div>
</div>
</div>
and this is the php file which the modal will call
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "afgroms";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['add_roomtype_action'])){
$roomtypeid = $_POST['add_roomtype_idnm'];
$roomtype = $_POST['add_roomtypenm'];
$rate = $_POST['add_ratenm'];
$file = $_FILES['add_roomtypeImgnm'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg','jpeg','png');
if(in_array($fileActualExt, $allowed)){
if($fileError === 0)
{
if ($fileSize > 500000) {
mysql_query("UPDATE `tbl_roomtype` SET `RoomType` =
'$roomtype', `Rate` = '$rate', `Image` = '$img' WHERE RoomTypeID =
".$roomtypeid);
echo "<script>";
echo "alert(\"Successfully Added!\");";
echo "</script>";
}else{
echo "<script>";
echo "alert(\"File size too big!\");";
echo "</script>";
}
}else
{
echo "<script>";
echo "alert(\"There was an error\");";
echo "</script>";
}
}else
{
echo "<script>";
echo "alert(\"You cannot upload this type of file\");";
echo "</script>";
}
}
?>
but this error keep on occurring : Notice: Undefined index: add_roomtypeImgnm...
help me out here guys, i don't know whats the problem. I already tried to change the name and id of my and same error keeps on occurring.

The reason why you cannot post files is not your modal dialog but the fact that you are not using enctype="multipart/form-data" in your form.
Try it like this and it should work.

Related

Set column as empty if no file is selected when submit

I am very new to PHP and was trying to do the file uploading. When I try to submit a form without having any files selected, the database will still insert a value to the attachments column.
My table picture:
Is there any way that I can set the attachments column as empty if there is not file selected for submission. Below is my code:
view_group.php
<form class="forms-sample" enctype='multipart/form-data' method="post">
<div class="modal-body">
<div class="form-group">
<textarea id="status_content" name="status_content" rows="30"></textarea>
</div>
<div class="form-group">
<label for="section_label">Add Attachments</label><br>
<input type="text" class="form-control" id="file" disabled placeholder="Select a file"><br>
<button type="button" class="file-upload-browse btn btn-primary" name="button" onclick="document.getElementById('fileName').click()">Select a file</button>
<input type="file" name="attachmentfile" id="fileName" style="display:none">
</div>
</div>
<div class="modal-footer">
<button class="btn btn-outline-secondary btn-fw">Cancel</button>
<input type="submit" class="btn btn-primary" name="postStatus" value="Post" />
</div>
</form>
GroupsController.php
function postStatus($std_id, $group_id){
$status = new ManageGroupsModel();
$status->std_id = $std_id;
$status->group_id = $group_id;
$status->status_content = $_POST['status_content'];
$status->attachments = time() . $_FILES['attachmentfile']['name'];
$status->target_dir = "../../attachments/groupfiles/";
//target file to save in directory
$status->target_file = $status->target_dir . basename($_FILES["attachmentfile"]["name"]);
// select file type
$status->imageFileType = strtolower(pathinfo($status->target_file,PATHINFO_EXTENSION));
// valid file extensions
$status->extensions_arr = array("jpg","jpeg","png","gif","pdf", "doc", "pdf");
if($status->postStatus() > 0) {
$message = "Status posted!";
echo "<script type='text/javascript'>alert('$message');
window.location = '../ManageGroupsView/view_group.php?group_id=".$group_id."'</script>";
}
}
GroupsModel.php
function postStatus() {
$sql = "insert into status(std_id, group_id, status_content, attachments) values(:std_id, :group_id, :status_content, :attachments)";
$args = [':std_id'=> $this->std_id, ':group_id'=> $this->group_id, ':status_content'=> $this->status_content, 'attachments'=> $this->attachments];
move_uploaded_file($_FILES['attachmentfile']['tmp_name'],$this->target_dir.$this->attachments); $stmt = DB::run($sql, $args);
$count = $stmt->rowCount(); return $count; }
I'm sorry if the question sounded dumb. It would be really great if someone can help. Thank you!
UPDATE!
Thanks to the people in my comment section, I finally get to do it. Here are the code needed to add :
function postStatus($std_id, $group_id){
$status = new ManageGroupsModel();
$status->std_id = $std_id;
$status->group_id = $group_id;
$status->status_content = $_POST['status_content'];
if($_FILES['attachmentfile']['name']) {
$status->attachments = time() . $_FILES['attachmentfile']['name'];
$status->target_dir = "../../attachments/groupfiles/";
//target file to save in directory
$status->target_file = $status->target_dir . basename($_FILES["attachmentfile"]["name"]);
// select file type
$status->imageFileType = strtolower(pathinfo($status->target_file,PATHINFO_EXTENSION));
// valid file extensions
$status->extensions_arr = array("jpg","jpeg","png","gif","pdf", "doc", "pdf");
} else {
$status->attachments = '';
}
if($status->postStatus() > 0) {
$message = "Status posted!";
echo "<script type='text/javascript'>alert('$message');
window.location = '../ManageGroupsView/view_group.php?group_id=".$group_id."'</script>";
}
}

Hiding the form if the field in database is null in php

Hi i have a registration form in my website.if the particular field in the db is null then the form should not be displayed to the user.Here if the payment_category_upload field is empty then the form should not displayed to the user otherwise the form should be displayed.
<?php include 'includes/db.php';
$sql = "SELECT * FROM users WHERE username = '$_SESSION[user]' AND user_password = '$_SESSION[password]' AND payment_category_upload!='' ";
$oppointArr =array();
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result) > 0)
{
if(isset($_POST['submit_user'])|| isset($_POST['save_users']))
{
$formsubmitstatus = isset($_POST['submit_user'])?1:0;
if($_FILES["affidavits_upload"]["tmp_name"]!="")
{
$pname = rand(1000,10000)."-".str_replace("-"," ",$_FILES["affidavits_upload"]["name"]);
$affidavits_upload = $_FILES["affidavits_upload"]["tmp_name"];
$uploads_dir = '../admin/images/uploads';
move_uploaded_file($affidavits_upload, $uploads_dir.'/'.$pname);
}
else
{
$pname = $_POST['hid_affidavits_upload'];
}
$id= $_POST['users_id'];
$ins_sql = "UPDATE users set affidavits_upload='$pname',status='3',affidavitsupload_submit_status='$formsubmitstatus' WHERE users_id = $id";
$run_sql = mysqli_query($conn,$ins_sql);
$msg = 'Your Application successfully submitted. ';
$msgclass = 'bg-success';
}
else
{
$msg = 'Record Not Updated';
$msgclass = 'bg-danger';
}
}
else
{
echo "Please make the payment to enable Affidavits";
}
?>
FORM :
<form class="form-horizontal" action="affidavits.php" method="post" role="form" enctype="multipart/form-data" id="employeeeditform">
<?php if(isset($msg)) {?>
<div class="<?php echo $msgclass; ?>" id="mydiv" style="padding:5px;"><?php echo $msg; ?></div>
<?php } ?>
<input type='hidden' value='<?=$id;?>' name='users_id'>
<div class="form-group">
<label for="affidavits_upload" class="col-sm-4 control-label">Affidavits Upload</label>
<div class="col-sm-8">
<input type="hidden" value="<?php echo $oppointArr['affidavits_upload'];?>" name="hid_payment_category_upload">
<input type="file" name="affidavits_upload" id="affidavits_upload">
<?php if(!empty($oppointArr['affidavits_upload'])){?>
<div>
<?php echo $oppointArr['affidavits_upload'];?>
</div>
<?php }?>
<span class="text" style="color:red;">Please upload PDF Format Only</span>
</div>
</div>
<div class="col-sm-offset-2">
<?php if($oppointArr['affidavitsupload_submit_status'] == 0){ ?>
<button type="submit" class="btn btn-default" name="save_users" id="save_users">Save</button>
<button type="submit" class="btn btn-default" name="submit_user" id="subject">Submit Application</button>
<?php } ?>
</div>
</form>
//Add this Css class
.hiddenBlock {
display:none
}
<div class="<?php echo isset(test_field)?"":"hiddenBlock"; ?>">
<form>...<form>
</div>
You can do it like this for your field.

Date not being stored in database from .xlsx sheet in PHP

I have a page to save an excel sheet records to the database. The records are being stored same way as they are provided in excel sheet other than "date of birth" column.
The "Date of Birth" column saves only for the second record being uploaded from excel sheet. I had been searching a lot on this but not found the exact reason for it.
Here is my complete code ,
<?php include 'blocks/headerInc.php' ;
include 'Classes/PHPExcel/IOFactory.php';
?>
<?php
$scsmsg = "" ;
$errmsg = "" ;
if(isset($_POST['submit']))
{
extract($_POST);
//$moduleId = mysql_real_escape_string(htmlspecialchars(trim($module_id)));die;
if(empty($_FILES['bulk_file']['name']))
{
$errmsg .= 'Please Choose File.<br>';
}
if(!empty($_FILES['bulk_file']['name']))
{
$extensions = array('.xlsx');
$valid_extensions = '.xlsx';
$extension = strrchr($_FILES['bulk_file']['name'], '.');
if (!in_array($extension, $extensions))
{
$errmsg .="Wrong files format , alowed Extension only".$valid_extensions.""."<br>";
}
}
if($errmsg == "")
{
$created = date("Y-m-d h:i:s");
$register_date = date("Y-m-d");
$created_by = $_SESSION['session_admin_id'] ;
$bulk_file = $_FILES['bulk_file']['name'];
if(!empty($bulk_file))
{
$tmp_name=$_FILES['bulk_file']['tmp_name'];
$bulk_file=$_FILES['bulk_file']['name'];
$file_name = $bulk_file;
//$file=$file_name.".csv";
$inputFileName = "uploads/user/$file_name";
$file_sucess=move_uploaded_file($tmp_name,$inputFileName);
//$inputFileName = 'format.xlsx';
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
} catch(Exception $e)
{
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage());
}
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet); // Here get total count of row in that Excel sheet
for($i=2;$i<=$arrayCount;$i++)
{
$salutation = trim($allDataInSheet[$i]["A"]);
$sbiempid = trim($allDataInSheet[$i]["B"]);
$branch = trim($allDataInSheet[$i]["C"]);
$middlename = trim($allDataInSheet[$i]["D"]);
$firstname = trim($allDataInSheet[$i]["E"]);
$lastname = trim($allDataInSheet[$i]["F"]);
$dateofbirth = trim($allDataInSheet[$i]["G"]);
$dateInput = explode('-',$dateofbirth);
$dob = $dateInput[2].'-'.$dateInput[1].'-'.$dateInput[0];
// $dob ="19".date("Y-m-d", strtotime($dateofbirth));
//var_dump($dob);
//print_r($dob);
$mobileno = trim($allDataInSheet[$i]["H"]);
$email = trim($allDataInSheet[$i]["I"]);
$city = trim($allDataInSheet[$i]["J"]);
$state = trim($allDataInSheet[$i]["K"]);
$designation = trim($allDataInSheet[$i]["L"]);
$corporate_user_sql=mysql_fetch_array(mysql_query("select * from tbl_corporate where id='$created_by'"));
$pre_define_day=$corporate_user_sql['pre_defined_day'];
$dataQuestion = array("type"=>"3","salutation"=>$salutation, "employee_id"=>$sbiempid, "branch"=>$branch, "middle_name"=>$middlename, "first_name"=>$firstname, "last_name"=>$lastname, "dob"=> $dob, "mobile"=>$mobileno, "email"=>$email, "city"=>$city,"state"=>$state,"designation"=>$designation,"created_on"=>$created, "created_by"=>$created_by,"status"=>"0","register_date"=>$register_date,"request_updated_day"=>$pre_define_day,"registration_type"=>"1");
$db->query_insert("tbl_user", $dataQuestion);
$question_id = mysql_insert_id();
$raw_password=uniqid().$question_id;
$md5_pass=md5(uniqid().$question_id);
$dataOption1 = array("registration_id"=>$sbiempid."_".$question_id,"password"=>$md5_pass,"raw_password"=>$raw_password);
$db->query_update("tbl_user", $dataOption1,"id=$question_id");
}
}
$scsmsg = "<b>Record inserted Successfully</b>";
}
}
?>
<div class="container pagecontainer">
<!-- Static navbar -->
<div class="row row-offcanvas row-offcanvas-right">
<!--/.col-xs-12.col-sm-9-->
<div class="col-sm-3 col-md-3 sidebar" id="sidebar">
<div id="left_panel" class="clearfix left">
<?php include 'blocks/leftnavInc.php' ; ?>
</div>
</div>
<div class="col-xs-12 col-sm-9 page-right">
<div class="panel panel-primary">
<div class="panel-heading">Upload User</div>
<div class="panel-body">
<div class="column col-sm-offset-0">
<?php
if($scsmsg!="")
{
echo "<div class='success'>".ucwords($scsmsg)."</div>";
}
if($errmsg!="")
{
echo "<div class='error'>".ucwords($errmsg)."</div>";
}
echo "<div id='error'></div>";
?>
<form class="form-horizontal" method="post" action="" enctype="multipart/form-data">
<div class="form-group">
<div class="col-md-12">
<div class="col-md-3">
<label for="username" class="control-label">Select FIle:</label>
</div>
<div class="col-md-9">
<input type="file" name="bulk_file" class="form-control" required="" >
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="col-md-3">
<label for="username" class="control-label">
Download Format</label>
</div>
<div class="col-md-9 text-right">
<button type="submit" name="submit" value="submit" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Save</button>
<button type="reset" onClick="javascript:window.location.href='quizList.php';" class="btn btn-danger"><i class="glyphicon glyphicon-ban-circle"></i> Cancel</button>
<button type="reset" onclick="javascript:history.go(-1)" class="btn btn-danger"><i class="glyphicon glyphicon-ban-circle"></i> Go Back</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!--/.sidebar-offcanvas-->
</div>
</div>
<?php include 'blocks/footerInc.php'; ?>
May I know where am I doing wrong in this as rest of the data fields are being posted semantically. This stores date of birth only for the second record in the excel sheet and for rest rows date of birth are being saved as 0000-00-00.
Any suggestion and help will be highly appreciated.
I'd suggest that you don't request formatted values when you build the array from the spreadsheet content, use
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,false,true);
instead of
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
Then manually convert the raw timestamp date values from cells to the format you need for the database
$dateofbirth = PHPExcel_Shared_Date::ExcelToPHPObject($allDataInSheet[$i]["G"])
->format('Y-m-d');

Selected checkboxes are not checked. why?

checkbox.php
<body>
<form>
<label>
<input type="checkbox" value="1" name="name">fruits</label>
<label>
<input type="checkbox" value="2" name="name">vegitables</label>
</form>
<!--modal-->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default" id="submit" onclick="submit();">save</button>
<h4 id="result"></h4>
</div>
</div>
</div>
</div>
</body>
Above is my main two checkboxes. A modal appears when I click on a checkbox. On which displays dynamic checkboxes(sub checkboxes) from database. when I click on sub checkboxes on modal and then click submit. Alert pops with no values. what I need to do is to get checked checkboxes values into alert. can anyone help me?
Here are my checkbox.js
$(document).ready(function(){
$("input[type=checkbox][name=name]").change(function(){
if(this.checked) {
var value = $(this).val();
$.ajax({
url:"modal.php",
type:"POST",
data:{value:value},
success:function(modalBody){
$("#myModal .modal-body").html(modalBody);
$("#myModal").modal('show');
}
});
}
});
});
function submit() {
var values = [];
$('input[type=checkbox][name=sub]').each(function(){
if($(this).is(":checked"))
{
values.push($(this).val());
alert(values.join());
}
});
}
and modal.php
<html>
<body>
<?php
if($_POST['value']){
$test = $_POST['value'];
include("config.php");
$sql = "SELECT name FROM tb where Id=".$value." ";
$res = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($res)){
?>
<input id='category' type='checkbox' name=sub'[]' value = <?php echo $row['name']; ?> /><?php
echo $row['name'];
echo "<br>";
}
}
else echo "not post";
?>
</body>
</html>
config.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "test";
// Create connection
$conn = mysqli_connect($servername, $username, $password,$db);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully <br/>";
?>
Fix your php page
<?php
if($_POST['value']){
$test = $_POST['value'];
include("config.php");
$sql = "SELECT name FROM tb where Id=".$value." ";
$res = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($res)){
echo "<input class='category' type='checkbox' name='sub[]' value ='".$row['name'];."'/>";
echo $row['name'];
echo "<br>";
}
}
else echo "not post";
?>
your js
var values = [];
$('.category:checked').each(function(){
values.push($(this).val());
});
alert(values.join());

PHP Form update without logout

As i am newbie to PHP kindly pardon me if i looks silly ,
I created a form in php , while i do the update part of the form the update reflects in db whereas in the form it still shows the same old value . i tried refresh and force refresh but nothing changes .
Whereas if i logout and login again , the form shows the updated value .
I tried using die(); after mysql_close($link); but it logs out the session and needs to re-login .
Kindly help me on viewing the changes while i am still inside the login .
My code is as follows :
<?php
if(isset($_POST['update'])) {
$name_a = $_POST['name'];
$email_a = $_POST['email'];
$pass_a = $_POST['password'];
$sql = "UPDATE admin SET a_name = '$name_a', a_email = '$email_a', password = '$pass_a' where aid='$update_id' ";
$retval = mysql_query($sql,$link);
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
echo "Updated data successfully\n";
mysql_close($link);
}else {
?>
<!-- Widget: user widget style 1 -->
<div class="box box-widget widget-user-2">
<!-- Add the bg color to the header using any of the bg-* classes -->
<div class="widget-user-header bg-yellow">
<div class="widget-user-image">
<?php echo '<img src="' . $img . '" class="img-circle" alt="User Image">'; ?>
</div>
<!-- /.widget-user-image -->
<h3 class="widget-user-username"><?php echo "$name"; ?></h3>
<h5 class="widget-user-desc"><?php echo "$role"; ?></h5>
</div>
<div class="box-footer no-padding">
<form role="form" method = "post" action = "<?php $_PHP_SELF ?>">
<div class="box-body">
<div class="form-group">
<label for="exampleInputName1">Name</label>
<input type="text" class="form-control" id="exampleInputName1" name="name" value="<?php echo "$name"; ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" name="email" value="<?php echo "$email"; ?>">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="password" value="<?php echo "$password"; ?>">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" name="update" id="update" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
<!-- /.widget-user -->
<?php
}
?>
SOLUTION
1) use the updated value like $name_a instead of $name because $name_a contain updated value and $name contain old value
2) reload page after update and get new value from database on page load and store that value in $name , $email etc variable (if new data update successfully in database then only you get new value )
3) if You store your data in session or cookie then update session and cookie value also when you update in database
Try this:
<?php
$name = '';
$email = '';
$password = '';
$update_id = '';
//$img = '';
//$role = '';
//$link = null;
if(
isset($_POST['update']) &&
isset($_POST['id']) &&
isset($_POST['name']) &&
isset($_POST['email']) &&
isset($_POST['password'])
) {
$update_id = mysql_real_escape_string($_POST['id']);
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$password = mysql_real_escape_string($_POST['password']);
$sql = 'UPDATE admin SET a_name = \'' . $name . '\', a_email = \'' . $email . '\', password = \'' . $password . '\' WHERE aid = \'' . $update_id . '\'';
$result = #mysql_query($sql, $link);
if(!$result)
die('Could not update data: ' . mysql_error($link));
echo 'Updated data successfully', "\n";
}
elseif(isset($_GET['id'][0])) {
$update_id = mysql_real_escape_string($_GET['id']);
$sql = 'SELECT a_name,a_email,a_password FROM admin WHERE aid = \'' . $update_id . '\'';
$result = #mysql_query($sql, $link);
if($result) {
$result = mysql_fetch_row($result);
$name = $result[0];
$email = $result[1];
$password = $result[2];
}
else {
echo 'Could not find the id.' . "\n";
$update_id = '';
}
}
unset($result);
if(isset($update_id[0])) {
mysql_close($link);
?>
<!-- Widget: user widget style 1 -->
<div class="box box-widget widget-user-2">
<!-- Add the bg color to the header using any of the bg-* classes -->
<div class="widget-user-header bg-yellow">
<div class="widget-user-image">
<img src="<?php echo htmlspecialchars($img); ?>" class="img-circle" alt="User Image">
</div>
<!-- /.widget-user-image -->
<h3 class="widget-user-username"><?php echo htmlspecialchars($name); ?></h3>
<h5 class="widget-user-desc"><?php echo htmlspecialchars($role); ?></h5>
</div>
<div class="box-footer no-padding">
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($update_id); ?>">
<div class="box-body">
<div class="form-group">
<label for="exampleInputName1">Name</label>
<input type="text" class="form-control" id="exampleInputName1" name="name" value="<?php echo htmlspecialchars($name); ?>">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" name="email" value="<?php echo htmlspecialchars($email); ?>">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" name="password" value="<?php echo htmlspecialchars($password); ?>">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button type="submit" name="update" id="update" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
<!-- /.widget-user -->
<?php }
else {
$sql = 'SELECT aid,a_name FROM admin';
$result = #mysql_query($sql, $link);
if($result) {
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '' . $row['a_name'] . '<br />' . "\n";
}
}
mysql_close($link);
}
?>
As #DivyeshSavaliya mentioned in the comment the issue is ,
I didn't Used Select query after update . Once done that the issue solved
The new working code is
<?php
if(isset($_POST['update'])) {
$name_a = $_POST['name'];
$email_a = $_POST['email'];
$pass_a = $_POST['password'];
$sql = "UPDATE admin SET a_name = '$name_a', a_email = '$email_a', password = '$pass_a' where aid='$update_id' ";
$retval = mysql_query($sql,$link);
if(! $retval ) {
die('Could not update data: ' . mysql_error());
}
}
$result = mysql_query("SELECT * FROM admin where aid='$update_id' ",$link);
while($row = mysql_fetch_array($result)){
$name = $row['a_name'];
$email = $row['a_email'];
$password = $row['password'];
}
mysql_close($link);
?>
Thanks to #DivyeshSavaliya

Categories