sending $_SERVER['request_uri'] via post - php

i got a usual form sending values to php file.
<form action=\"/admin/save\" method=\"post\" ENCTYPE=\"multipart/form-data\">
<div class=\"element\">
<label for=\"name\">Page ID <span class=\"red\">(required)</span></label>
<input id=\"id\" name=\"id\" value=".$edit['id']." class=\"text\" />
</div>
<div class=\"element\">
<label for=\"name\">Page title <span class=\"red\">(required)</span></label>
<input id=\"title\" name=\"title\" value=".$edit['title']." class=\"text\" />
</div>
<div class=\"element\">
<label for=\"category\">Category <span class=\"red\">(required)</span></label>
<input id=\"category\" name=\"category\" value=".$edit['category']." class=\"text\" />
</div>
<div class=\"element\">
<label for=\"attach\">Attachments</label>
<input type=\"file\" id=\"img\" name=\"img\" />
</div>
<div class=\"element\">
<label for=\"short-content\">Short content <span class=\"red\">(required)</span></label>
<textarea name=\"short_content\" id=\"short_content\" class=\"textarea\" rows=\"10\">".$edit['short_content']."</textarea>
</div>
<div class=\"element\">
<label for=\"content\">Long content <span class=\"red\">(required)</span></label>
<textarea name=\"long_content\" id=\"long_content\" class=\"textarea\" rows=\"10\">".$edit['content']."</textarea>
</div>
<div class=\"element\">
<label for=\"date\">Date <span class=\"red\">(required)</span></label>
<input id=\"date\" name=\"date\" class=\"text\" value=".$edit['date']." />
</div>
<div class=\"element\">
<label for=\"language\">Language <span class=\"red\">(required)</span></label>
<input id=\"language\" name=\"language\" value=".$edit['lang']." class=\"text\" />
</div>
<div class=\"entry\">
<button type=\"submit\" id=\"button-save\" class=\"add button-save\">Save page</button>
</div>
</form>
Sends to..
<?php include('/views/admin/header.php'); ?>
<div class="wrap">
<div id="header">
<div id="top">
<div class="left">
<p>Welcome, <strong><?php echo $_SESSION['user'];?></strong> [ logout ]</p>
</div>
<div class="right">
<div class="align-right">
<p>Avetisyan | Admin Panel</p>
</div>
</div>
</div>
<div id="nav">
<?php include '/views/admin/upper-menu.php'; ?>
</div>
</div>
<div id="content">
<div id="sidebar">
<div class="box">
<div class="h_title">› Pages</div>
<?php include '/views/admin/left-menu.php'; ?>
</div>
</div>
<div id="main">
<div class="full_w">
<?php
$id = $_POST['id'];
$category = $_POST['category'];
$title = $_POST['title'];
$short_content = $_POST['short_content'];
$long_content = $_POST['long_content'];
$date = $_POST['date'];
$lang = $_POST['language'];
if(empty($id)){
echo "<h3 style=\"color:red;\">Please fill ID</h3>";
}
if(empty($category)){
echo "<h3 style=\"color:red;\">Please fill Category</h3>";
}
if(empty($title)){
echo "<h3 style=\"color:red;\">Please fill Title</h3>";
}
if(empty($date)){
echo "<h3 style=\"color:red;\">Please fill Date</h3>";
}
if(empty($lang)){
echo "<h3 style=\"color:red;\">Please fill Lang</h3>";
}
if(isset($_FILES['img']['name'])){
$extension = end(explode(".",$_FILES['img']['name']));
//echo "file format: ".$extension."<br>";
$name = $_FILES['img']['name'];
$size = $_FILES['img']['size'];
if(file_exists("views/admin/uploads/".$name)){
echo $_FILES['img']['name']." exists";
}
if($extension != "jpg" && $extension != "png" && $extension != "gif"){
echo "File with format: ".$extension." is not aviable to upload";
}
if($size > 1000000) {
echo $size." is greater than 1 mb !";
}
else {
move_uploaded_file($_FILES['img']['tmp_name'],"views/admin/uploads/".$name);
}
}
?>
</div>
<div class="clear"></div>
</div>
<div id="footer">
<div class="left">
<p>Webex Technologies LLC | Admin Panel: Avetisyan</p>
</div>
<div class="right">
</div>
</div>
</div>
<?php include('/views/admin/footer.php');?>
In second file, i want to do an link back, so if user wrote something wrong, he click on that link, go back to edit page (edit page link look like this - /admin/edit?id=5&lang=arm). How i can send $_SERVER['request_uri'] via post method but not via inputs, i dont want to have there another input with it.. Or can u give me any solution here?

Use $_SERVER['HTTP_REFERER'] in the file you process the submission.

Easiest way is to have a hidden input:
<input type="hidden" name="previous_page" value="<?=$_SERVER['REQUEST_URI']?>" />
You then have access to the previous page URI via $_POST['previous_page'].

Related

Undefined indexes apeeared after submitting the form

I have a two step form. create.php and create2.php. Both pages are forms. After first form is filled user presses "Continue" and proceeds to the second form where i pass and store value from first form in hidden inputs. After filling and submitting second form, i want pop up window which means successful submission of the form and inserting all the data into database. It seems that everything is working fine and all data is in database, however i dont get pop up window, what i get is undefined index warning about my hidden inputs.
Ok here is code for create.php:
<form class="formcss" method="post" action="create2.php" id="reportform" enctype="multipart/form-data">
<fieldset style="background-color:white;">
<legend style="font-size: 20px;">New Project</legend>
<br>
<div class="row">
<div class="small-8 large-8 columns">
<label>Project Code: <small style="color:red;">*</small>
<input type="text" name="code" maxlength="155" id="code" class="input input1 name" onkeyup="limitTextCount('code', 'divcount0', 155, 0);" onkeydown="limitTextCount('code', 'divcount0', 155, 0);" <?php if (isset($code)) echo 'value="'.$code.'"' ?>/>
<label class="tool tool1" for="name" style="margin-top:-8px;">Code of the project</br>e.g. ASD001</label>
</label>
</div>
</div>
<div class="row">
<div class="small-8 large-8 columns">
<label>Project Name: <small style="color:red;">*</small>
<input type="text" name="title" maxlength="155" id="title" class="input input1 name" onkeyup="limitTextCount('title', 'divcount0', 155, 0);" onkeydown="limitTextCount('title', 'divcount0', 155, 0);" <?php if (isset($title)) echo 'value="'.$title.'"' ?>/>
<label class="tool tool1" for="name" style="margin-top:-8px;">Title of the project</br>e.g. Leon</label>
</label>
</div>
</div>
<div class="row">
<div class="small-8 large-8 columns">
<label>Process
<div class="multiselect">
<div class="selectBox">
<select onclick="showCheckboxes()" class="input input1 name">
<option>-- Select an option --</option>
</select>
<div class="overSelect"></div>
</div>
<div class="scrollable" id="checkboxes">
<?php
while ($row = mysql_fetch_array($result))
{
$row[0] = cleanOutputData($row[0]);
?>
<div class="row">
<div class="small-12 large-12 columns">
<label style="height: 37px; width:80%; float:left;">
<input type="checkbox" class="checkbox" style="margin-left:5%; width:15%;" name="process[]" id=<?php echo $row[0] ?> value=<?php echo $row[0]?> /><?php echo $row[0] ?>
</label>
<label style="width:40%; margin-left:60%;"><input type="text" class="field" disabled style="width:40%;" name="numberpl[]" id=<?php echo $row[0] ?> />
</label>
</div>
</div>
<?php
}
mysql_free_result($result);
?>
</div>
</div>
</label>
</div>
</div>
<div class="row">
<div class="small-8 large-8 columns">
<label>Comments
<textarea style="resize:none;" class="input input1 name" name="remark" rows="8" cols="50" maxlength="255" id="remark" onkeyup="limitTextCount('remark', 'divcount5', 255, 0);" onkeydown="limitTextCount('remark', 'divcount5', 255, 0);"><?php if (isset($remark)) echo $remark ?></textarea>
<label class="tool tool1" for="name" style="left:-140px;">Further comments</label>
</label>
</div>
<div class="small-6 large-6 columns">
<label> <?php if (isset($remark)){ echo "<label id='divcount5'></label>"; echo "<script>limitTextCount('remark', 'divcount5', 255, 0);</script>";} else echo "<label id='divcount5'>255 characters remaining</label>";?></label>
</div>
</div>
<div class="row">
<div class="small-8 large-8 columns">
<input type = "submit" name ="submit" style="margin-left:600px; width:150px;" class="button" onclick="userSubmitted = true;" value = "Continue"/>
</div>
</div>
<br/><br/>
</fieldset>
</form>
And for the second form create2.php:
<?php
session_start();
//if user haven't sign in will redirect user to login page
if(empty($_SESSION['login_user'])){
session_destroy();
header("Location: login.php");
}
$proc = isset($_POST['process'])?$_POST['process']:'';
//$proc=$_POST['process'];
$len = count($proc); // getting length of ur array that u need to condition ur loop
$num = isset($_POST['numberpl'])?$_POST['numberpl']:'';
//$num=$_POST['numberpl'];
//$len2 = count($num); // getting length of ur array that u need to condition ur loop
include 'verification/verify_form_details2.php';
require_once('inc/config.php');
//include 'verification/verify_form_details.php';
ob_start();
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "pp";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<form class="formcss" method="POST" name="checkoutForm" action="create2.php#err" id="reportform" enctype="multipart/form-data">
<?php
$res = verifyFormFields();
?>
<!-- hidden inputs from first form(create.php) -->
<input type="hidden" name="holdcode" value="<?php echo isset($_POST['code'])?$_POST['code']:'';?>">
<input type="hidden" name="holdtitle" value="<?php echo isset($_POST['title'])?$_POST['title']:'';?>">
<?php
//an array of inputs
for($y=0;$y<$len;$y++)
{
?>
<input type='hidden' name='holdprocess[]' value="<?php echo $proc[$y]?>">
<input type='hidden' name='holdnumber[]' value="<?php echo $num[$y]?>">
<?php
}
?>
<!-- hidden inputs from first form(create.php) -->
<br>
<fieldset style="background-color:white;">
<legend style="font-size: 20px;">Add Stuff</legend>
<br><br><br>
<div class="small-3 large-3 columns">
<label>Choose username</label>
<input placeholder="Search Me" id="box" type="text" />
<div id="myAccordion">
<?php for($i=321; $i<347; $i++)
{
echo "<h3>".chr($i)."</h3>";
echo '<ul class="source">';
$sql = "SELECT username FROM user WHERE username LIKE '".chr($i+32)."%' ";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
$name= $row["username"];
echo"<li>". $name ."</li>";
}
} else
{
echo "0 results";
}
echo '</ul>';
}
?>
</div>
</div>
<div id="project" class="small-9 large-9 columns">
<label style="font-size: 40px; margin-left:10%;">Project <?php echo isset($_POST['code'])?$_POST['code']:''; ?></label>
<div class="rowone">
<div id="leader">
<label>Leader:</label>
<div class="ui-widget-content">
<div id="projLeader">
<ol>
<li class="placeholder" name="leader" <?php if (isset($leader)) echo 'value="'.$leader.'"' ?>>Add leader here</li>
<input type="hidden" name="leader" id="hiddenListInput1" />
</ol>
</div>
</div>
</div>
<div id="checker">
<label>Checker:</label>
<div class="ui-widget-content">
<div id="projChecker">
<ol>
<li class="placeholder" name="checker" <?php if (isset($checker)) echo 'value="'.$checker.'"' ?>>Add checker here</li>
<input type="hidden" name="checker" id="hiddenListInput2" />
</ol>
</div>
</div>
</div>
<div id="info">
<label>Information:</label>
<div class="ui-widget-content">
<ol>
<li>Total:</li>
<li>Total:</li>
<li>Total:</li>
<li>Total:</li>
<li>Total:</li>
</ol>
</div>
</div>
</div>
<div class="row">
<input type = "submit" id="savebutton" style="margin-left:300px; width:150px;" name ="submit" class="button" value = "Create Project" onclick="userSubmitted = true;" />
</div>
</div>
<div id="formModal" class="reveal-modal small" data-reveal aria-labelledby="modalTitle" aria-hidden="true" role="dialog" data-options="close_on_background_click:false">
<h2 id="modalTitle">Success!</h2>
<div style="font-weight: 400;font-size: 1.5em; font-family: 'Raleway', Arial, sans-serif;">Your Accident Report was Successfully Submitted!</div>
<div class="right">
Ok
</div>
</div>
<?php
if($counta==1)
{
if($res=="")
{
$testing = JSON_encode($_SESSION['role']);
echo '<script>userSubmitted = true;</script>';
insertRecord();
echo "<script type ='text/javascript'>callShowAlert();</script>";
}
else{
echo "
<br><br><a style='color:red';>
$res
</a>
";
}
}
?>
<script>var testing = JSON.parse('<?= $testing; ?>');</script>
</fieldset>
</form>
Here is what i got after submitting second form:
Notice:
Undefined index: process in C:\xampp\htdocs\Projects\1ver\create2.php
on line 9
Notice:
Undefined index: numberpl in C:\xampp\htdocs\Projects\1ver\create2.php
on line 12
Notice:
Undefined index: code in
C:\xampp\htdocs\Projects\1ver\create2.php on line 256
Notice:
Undefined index: title in
C:\xampp\htdocs\Projects\1ver\create2.php on line 257
Notice:
Undefined index: title in C:\xampp\htdocs\Projects\1ver\create2.php on
line 302
I'm using another php page to insert data into database. I just don't get what can be a problem. Thanks for any help
Since POST array is not available for first time. Therefore, you are getting this error. If you really need to use those post variables, you should apply a condition in this case to avoid these errors.
I'm here adding for one, you can do the same for remaining.
Try this:
<?php echo isset($_POST['code'])?$_POST['code']:''; ?>

How to save data of text area in php

I'm a PHP learner. I have a website built on PHP. On the front end of one of our website pages there are four tabs. See the pic below for reference -
I want to add one more tab here. There should be a simple option of adding content in the admin panel for this tab (Which I have accomplished)
My problem is, when I am adding content to the text area in admin panel and hitting submit, the content disappears. I guess the content is not being stored in the database. I checked the SQL file made the possible changes. Although I'm not sure if I did it right. But I'm quite sure that there's a very small lag here which I am not able to figure out.
P.S. Check the screenshot of admin panel for more clarification about my issue.
The text area with heading Table of Contents - Simple is the one which I added. But as I mentioned, even if add content here and hit submit it becomes blank.
Below is the code of the page in screenshot -
"<?php
require_once '../config/config.php';
require_once '../class/dbclass.php';
require_once 'class/content.php';
require_once 'class/category.php';
require_once 'class/common.php';
require './isLogin.php';
$content = new Content();
$category = new Category();enter code here
$catList = $category->fetchCategoryTree();
//echo '<pre>';
//print_r($catList);
//echo '</pre>';
//exit;
//$catParentList = $category->fetchParentCategory(30);
//echo '<pre>';
//print_r($catParentList);
//echo '</pre>';
//echo implode("->",$catParentList);
//echo '<pre>';
//print_r(array_reverse($catParentList));
//echo '</pre>';
//exit;
$cat_id = 0;
$title = '';
$price = '';
$description = '';
$descriptions = '';
$author = $published = $report_code = '';
$content_id = isset($_REQUEST['id']) && $_REQUEST['id'] != "" ? $_REQUEST['id'] : 0;
//$category_list = $category->getAllCategory();
if ($content_id) {
$contentData = $content->getContentById($content_id);
$cat_id = isset($contentData[0]['cat_id']) ? $contentData[0]['cat_id'] : '';
$title = isset($contentData[0]['title']) ? $contentData[0]['title'] : '';
$price = isset($contentData[0]['price']) ? $contentData[0]['price'] : '';
$description = isset($contentData[0]['description']) ? $contentData[0]['description'] : '';
$descriptions = isset($contentData[0]['descriptions']) ? $contentData[0]['descriptions'] : '';
$report_code = isset($contentData[0]['report_code']) ? $contentData[0]['report_code'] : '';
$published = isset($contentData[0]['published']) ? $contentData[0]['published'] : '';
$author = isset($contentData[0]['author']) ? $contentData[0]['author'] : '';
}
if($content_id == 0)
$pageName = "Add Report";
else
$pageName = "Edit Report";
?>
<?php require_once './includes/header.php'; ?>
<?php require_once './includes/sidebar.php'; ?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>
<b><?php echo $pageName; ?></b>
</h1>
<ol class="breadcrumb">
<li><i class="fa fa-dashboard"></i> Home</li>
<li class="active"><?php echo $pageName; ?></li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<?php if (isset($_SESSION['error_message']) && $_SESSION['error_message'] != ''): ?>
<div class="alert alert-danger alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="glyphicon glyphicon-remove"></i></button>
<?php echo $_SESSION['error_message']; ?>
</div>
<?php endif; ?>
<?php if (isset($_SESSION['success_message']) && $_SESSION['success_message'] != ''): ?>
<div class="alert alert-success alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="glyphicon glyphicon-remove"></i></button>
<?php echo $_SESSION['success_message']; ?>
</div>
<?php endif; ?>
<?php if (isset($_SESSION['info_message']) && $_SESSION['info_message'] != ''): ?>
<div class="alert alert-info alert-dismissable">
<button aria-hidden="true" data-dismiss="alert" class="close" type="button"><i class="glyphicon glyphicon-remove"></i></button>
<?php echo $_SESSION['info_message']; ?>
</div>
<?php endif; ?>
</div><!-- /.box-header -->
<!-- form start -->
<form id="content-form" action="models/contentProcess.php" enctype="multipart/form-data" method="post" novalidate>
<div class="box-body">
<input type="hidden" name="type" value="<?php echo ($content_id == 0) ? "addContent" : "editContent"; ?>">
<input type="hidden" name="content_id" id="content_id" value="<?php echo $content_id ?>">
<div class="form-group">
<label>Select Category</label>
<select id="cat_id" name="cat_id" class="form-control">
<?php foreach ($catList as $cl) { ?>
<option value="<?php echo $cl["id"] ?>" <?php echo ($cl["id"] == $cat_id) ? 'selected' : '' ; ?> ><?php echo $cl["name"]; ?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label>Title</label>
<input type="text" name="title" id="title" placeholder="Enter title" class="form-control" value="<?php echo $title ?>">
</div>
<div class="form-group">
<label>Report Code</label>
<input type="text" name="report_code" id="report_code" placeholder="Enter Report Code" class="form-control" value="<?php echo $report_code ?>">
</div>
<div class="form-group">
<label>Image</label>
<input type="file" class="btn btn-default btn-file" name="image" id="image">
</div>
<div class="form-group">
<label>Published</label>
<input type="text" name="published" id="published" placeholder="Enter published" class="form-control" value="<?php echo $published ?>">
</div>
<div class="form-group">
<label>Author</label>
<input type="text" name="author" id="author" placeholder="Enter author" class="form-control" value="<?php echo $author ?>">
</div>
<div class="form-group">
<label>Price</label>
<input type="text" name="price" id="price" placeholder="Enter price" class="form-control" value="<?php echo $price ?>">
</div>
<div class="form-group">
<label>Description</label>
<textarea id="description" name="description" class="form-control" rows="10" cols="80">
<?php echo $description; ?>
</textarea>
</div>
<div class="form-group">
<label>Table of Contents - Simple</label>
<textarea id="descriptions" name="descriptions" class="form-control" rows="15" cols="100">
<?php echo $descriptions; ?>
</textarea>
</div>
<button class="btn btn-primary" type="submit" id="submitform">Submit</button>
Cancel
</div>
</form>
</div><!-- /.box -->
</div><!--/.col (left) -->
<!-- right column -->
</div> <!-- /.row -->
</section><!-- /.content -->
</div><!-- /.content-wrapper -->
<?php require_once './includes/footer.php'; ?>
<script type="text/javascript" src="<?php echo ADMIN_ROOT; ?>plugins/ckeditor/ckeditor.js"></script>
<script language="javascript">
CKEDITOR.replace('descriptions',{
//uiColor:"#532F12",
toolbar: 'MyToolbar',
});
</script>
<script language="javascript">
CKEDITOR.replace('description',{
//uiColor:"#532F12",
toolbar: 'MyToolbar',
});
</script>"
Code snippet of reportDetail.php
<div class="tab-content" style="min-height:775px;">
<div id="menu1" class="tab-pane <?php if (!isset($_SESSION['user_id'])) { ?>active<?php } ?>" style="overflow: auto;<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { ?>max-height: 1520px;<?php } else { ?> height: 795px;<?php } ?>">
<?= $contentData['description'] ?>
</div>
<div id="menu2" class="tab-pane fade <?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { ?>active in<?php } ?>" style="overflow: auto;<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { ?>max-height: 1520px;<?php } else { ?> height: 795px;<?php } ?>">
<?= $contentData['descriptions'] ?>
</div>
<div id="menu3" class="tab-pane fade <?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] > 0) { ?>active in1<?php } ?>" >
html:-
<form action="" method="post">
<textarea name="textarea" rows="10" cols="50"></textarea>
<input type="submit" name="submit">
</form>
php:-
if(isset($_POST["submit"]))
{
$yourtextarea= $_POST["textarea"];
}

PHP CodeIgniter - Array upload file

I run my php code to upload multiple file but until right now i get error like this :
PHP erorr Undefined index: link_to_doc_file_
And here is my controller :
function insert_data(){
$this->form_validation->set_rules('tool_code', 'Tool Code', 'required');
if ($this->form_validation->run()){
for($i=1;$i<=10;$i++) {
$link_to_doc_file_[$i] = (isset($_GET['link_to_doc_file_'][$i]) ? $_GET['link_to_doc_file_'][$i] : null);
$link_to_doc_file_[$i] = "";
$file_uploaded = false;
//UPLOAD DOC
if(is_uploaded_file($_FILES['link_to_doc_file_']['tmp_name'][$i])){
$folder = /*base_url() .*/ 'material/';
$ext = substr($_FILES['link_to_doc_file_']['name'][$i],strpos($_FILES['link_to_doc_file']['name'][$i],'.'));
$file_name = $this->input->post('tool_code') . (int)microtime(true) . $ext;
$target_file = $folder .$file_name;
if(!file_exists($folder))
mkdir($folder);
//if(file_exists($target_file)) unlink($target_file);
if(move_uploaded_file($_FILES['link_to_doc_file_']["tmp_name"][$i], $target_file)){
$file_uploaded = true;
$$link_to_doc_file_[$i] = $target_file;
}
}
}
$tool_code = $this->input->post($tool_code);
$data_doc = null;
//Data Description
for($i=1;$i<=10;$i++){
$data_doc['title'][$i-1] = $this->input->post('doc_title_' . $i);
$data_doc['link'][$i-1] = $this->input->post('link_to_doc_file_'.$i);
$data_doc['show'][$i-1] = $this->input->post('doc_display_' . $i);
}
$data['doc'] = $data_doc;
if($this->input->post('is_edit')){
//UPDATE
$this->model_tool->update_tool_document($this, $data);
}else{
//INSERT
$this->model_tool->insert_tool_document($this, $data);
}
redirect(MENU_TOOL_DOC);
}else{
}
}
}
Here my View :
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<?php echo (($id)?"Edit":"Add") . " Document"; ?>
</div>
<div class="panel-body">
<?php echo form_open_multipart(base_url() . MENU_TOOL_DOC . '/insert_data');?>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<input type="hidden" name="tool_code" value="<?php echo $tool_code;?>">
<label>Tool Code : <?php echo $tool_name;?></label>
<?php
for($i=1;$i<=10;$i++){
?>
<div class="form-group">
<label>Document <?php echo $i;?></label>
<div class="form-group">
<label>Show</label>
<select class="form-control" name="doc_show_<?php echo $i;?>">
<?php
for($j=0;$j<count($show);$j++){
?>
<option value="<?php echo ($j); ?>" <?php echo (isset($row))?(($doc['show'][$i-1] == $j)?"selected":""):"";?>>
<?php echo $show[$j];?>
</option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label>Title</label>
<input class="form-control" name="doc_title_<?php echo $i;?>" value="<?php echo (isset($row))?$doc['title'][$i-1]:"";?>">
</div>
<div class="form-group form-inline">
<label>File</label>
<input type="file" name="link_to_doc_file_<?php echo $i;?>" value="<?php echo (isset($row))?$doc['link'][$i-1]:"";?>">
</div>
</div>
<?php
}
?>
</div>
<div class="col-lg-12">
<input type="hidden" name="is_edit" value="<?php echo $is_edit; ?>" />
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</div>
<?php echo form_close();?>
<!-- /.row (nested) -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
if only one upload i can but if many uploads file not yet until right now.
After your ist update, you are using an incremental variable in form input name.
<input type="file" name="link_to_doc_file_<?php echo $i;?>">
Now, you are getting undefined index array because you are defining index as:
link_to_doc_file_
This should be defined as:
$_FILES['link_to_doc_file_'.$i]
More explanation:
link_to_doc_file_ != link_to_doc_file_1
Side Note:
Also check this variable $_GET['link_to_doc_file_'][$i], you need to change it also.
You're looking for $FILES['link_to_doc_file'] but you're setting it with an integer and the end:
name="link_to_doc_file_<?php echo $i;?>"
in your upload script you have to look for that same integer
if(is_uploaded_file($_FILES['link_to_doc_file_$some_integer']['tmp_name'][$i])){

Error in storing the records in database

The following code for create edit form to update records. If I give all field it update correctly if I didn't change image it does not update the record. I want to update record without change image and also I want to update records by only changing the image.
<section id="main-content">
<section class="wrapper">
<h3><i class="fa fa-angle-right"></i> About Components</h3>
<!-- BASIC FORM ELELEMNTS -->
<div class="row mt">
<div class="col-lg-12">
<div class="form-panel">
<h3><i class="fa fa-angle-right"></i> Team Update</h3>
<form class="form-horizontal style-form" enctype="multipart/form-data" method="post">
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<textarea type="text" name="Title" class="form-control" required><?php echo $img['a_title']; ?></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<textarea type="text" name="Description" class="form-control" required><?php echo $img['a_description']; ?></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Picture</label>
<div class="col-sm-10">
<div class="clear" id="im">
<?php echo "<img src='/myproject/cp/image/".$img['a_image']."'height='50' width='50' >"; ?>
<button type="button" id="remove" >remove</button>
</div>
<div id="browse" style="display:none;">
<input type="file" name="imageupload" value="imageupload" />
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label"></label>
<div class="col-sm-10">
<input class="btn btn-theme" id="focusedInput" type="submit" name="submit" value="Submit" />
</div>
</div>
<a class="btn btn-primary" href="about.php">
<span>List view</span>
</a>
</form>
</div>
</div><!-- col-lg-12-->
</div><!-- /row --><?php
if(isset($_POST['submit']))
{
$var=$_GET['a_id'];
$file=$_SERVER['DOCUMENT_ROOT'].'myproject/cp/image/'.$img['a_image'];
unlink($file);
$var1=$_POST['Title'];
$var2=$_POST['Description'];
$image=$_FILES['imageupload']['name'];
$root=$_SERVER['DOCUMENT_ROOT'].'/myproject/cp/image/';
$file_exts = array("jpg", "bmp", "jpeg", "gif", "png");
$expo=explode(".", $_FILES["imageupload"]["name"]);
$upload_exts = end($expo);
if ((($_FILES["imageupload"]["type"] == "image/gif")|| ($_FILES["imageupload"]["type"] == "image/jpeg")|| ($_FILES["imageupload"]["type"] == "image/png")|| ($_FILES["imageupload"]["type"] == "image/jpg"))&& ($_FILES["imageupload"]["size"] < 2000000)&& in_array($upload_exts,$file_exts))
{
if ($_FILES["imageupload"]["error"] > 0)
{
echo "Return Code: " . $_FILES["imageupload"]["error"] . "<br>";
}
else
{
$image= rand(0,9999).'.'.$upload_exts;
move_uploaded_file($_FILES["imageupload"]["tmp_name"],$root.$image);
$sql=mysql_query("UPDATE about SET a_title='".$var1."',a_description='".$var2."',a_image='".$image."' WHERE a_id='".$var."'") or die(mysql_error());
echo "<meta http-equiv=refresh content=\"0; URL=about.php\">";
}
}
}
?>
As you said in comment , when you save the edits all other details get saved but your image get's removed even if you haven't changed it , clearly it's your php code , even before checking that if you are submiting an image or not you already doing an unlink on it , you have to use the edit below :
<?php
if(isset($_POST['submit']))
{
$var=$_GET['a_id'];
$file_del =$_SERVER['DOCUMENT_ROOT'].'myproject/cp/image/'.$img['a_image'];
$var1=$_POST['Title'];
$var2=$_POST['Description'];
$image=$_FILES['imageupload']['name'];
$root=$_SERVER['DOCUMENT_ROOT'].'/myproject/cp/image/';
$file_exts = array("jpg", "bmp", "jpeg", "gif", "png");
$expo=explode(".", $_FILES["imageupload"]["name"]);
$upload_exts = end($expo);
if ((($_FILES["imageupload"]["type"] == "image/gif")|| ($_FILES["imageupload"]["type"] == "image/jpeg")|| ($_FILES["imageupload"]["type"] == "image/png")|| ($_FILES["imageupload"]["type"] == "image/jpg"))&& ($_FILES["imageupload"]["size"] < 2000000)&& in_array($upload_exts,$file_exts))
{
if ($_FILES["imageupload"]["error"] > 0)
{
echo "Return Code: " . $_FILES["imageupload"]["error"] . "<br>";
}
else
{
unlink($file_del);
$image= rand(0,9999).'.'.$upload_exts;
move_uploaded_file($_FILES["imageupload"]["tmp_name"],$root.$image);
$sql=mysql_query("UPDATE about SET a_title='".$var1."',a_description='".$var2."',a_image='".$image."' WHERE a_id='".$var."'") or die(mysql_error());
echo "<meta http-equiv=refresh content=\"0; URL=about.php\">";
}
}
}

Ajax File Upload And insert details and Form File Details to Db

Please I Know that some of the Topics relating to my post is here but it does not actually seems to solve my problem. I have an uploader class and my Ajax upload is working fine without PHP connection. Now after Upload am trying to call in my file class to store the details to Database but not actually working out. I have searched all around both on youtube and none see to solve my problem
error_reporting(0);
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
$path = "uploads/"; //set your folder path
//set the valid file extensions
$valid_formats = array("jpg", "png", "gif", "bmp", "jpeg", "GIF", "JPG", "PNG", "doc", "mp3", "txt", "docx", "pdf", "xls", "xlsx", "mp4"); //add the formats you want to upload
$name = $_FILES['myfile']['name']; //get the name of the file
$size = $_FILES['myfile']['size']; //get the size of the file
if (strlen($name)) { //check if the file is selected or cancelled after pressing the browse button.
list($txt, $ext) = explode(".", $name); //extract the name and extension of the file
if (in_array($ext, $valid_formats)) { //if the file is valid go on.
if ($size < 9433098888) { // check if the file size is more than 2 mb
$file_name = $_POST['filename'];
$new = $_POST['music_new']; //get the file name
$tmp = $_FILES['myfile']['tmp_name'];
if (move_uploaded_file($tmp, $path . $file_name.'.'.$ext)) { //
$sam->musicUpload('name','format','so on');
//please am in need of this. if i type echo $file_name works but can actually insert to my db.. i have no problem with my back end
}
else {
echo "failed";
}
} else {
echo "File size max 2 MB";
}
} else {
echo "Invalid file format..";
}
} else {
echo "Please select a file..!";
}
include'../../header.php';
echo $url;
}
<div class='category-tab shop-details-tab'><!--category-tab-->
<div class='col-sm-12'>
<ul class='nav nav-tabs'>
<li><a href='#details' data-toggle='tab'>Details</a></li>
<li><a href='#companyprofile' data-toggle='tab'>Company Profile</a></li>
<li><a href='#tag' data-toggle='tab'>Tag</a></li>
<li class='active'><a href='#reviews' data-toggle='tab'>Reviews (5)</a></li>
</ul>
</div>
<div class='tab-content'>
<div class='tab-pane fade' id='details' >
<div class='col-sm-3'>
<div class='product-image-wrapper'>
<div class='single-products'>
<div class='productinfo text-center'>
<img src='images/home/gallery1.jpg' alt='' />
<h2>$56</h2>
<p>Easy Polo Black Edition</p>
<button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
</div>
</div>
</div>
</div>
</div>
<div class='tab-pane fade' id='companyprofile' >
<div class='col-sm-3'>
<div class='product-image-wrapper'>
<div class='single-products'>
<div class='productinfo text-center'>
<img src='images/home/gallery4.jpg' alt='' />
<h2>$56</h2>
<p>Easy Polo Black Edition</p>
<button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
</div>
</div>
</div>
</div>
</div>
<div class='tab-pane fade' id='tag' >
<div class='col-sm-3'>
<div class='product-image-wrapper'>
<div class='single-products'>
<div class='productinfo text-center'>
<img src='images/home/gallery4.jpg' alt='' />
<h2>$56</h2>
<p>Easy Polo Black Edition</p>
<button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
</div>
</div>
</div>
</div>
</div>
<div class='tab-pane fade active in' id='reviews' >
<div class='col-sm-12'>
<ul>
<li><a href=''><?php if($logged){ echo $username;}else{echo'Not Logged';}?></a></li>
<li><a href=''><i class='fa fa-clock-o'></i>12:41 PM</a></li>
<li><a href=''><i class='fa fa-calendar-o'></i>31 DEC 2014</a></li>
</ul>
<p> Plese make sure to upload Relevant files or else it will be deleted by the Head Admin(s). Thanks for Understanding</p>
<p><b>Write Your Review</b></p>
<div class="row">
<div class='tab-pane fade active in' id='reviews' >
<div class='col-sm-12'>
<h3>jQuery Ajax file upload with percentage progress bar</h3>
<form id="myform" method="post">
<div class="form-group">
<label>Enter the file name: </label>
<input class="form-control" type="text" id="filename" />
</div>
<span>
<input type="text" placeholder="Database Name" id='music_name'/>
<input type="text" placeholder="Producer"" id="music_producer" />
</span>
<br>
<span>
<input type="text" placeholder="Artist Name" id="music_artist"/>
<input type="text" placeholder="Album Name"/>
</span><br>
<textarea name="" placeholder="Music Description" id='music_desc'></textarea>
<div class="form-group">
<label>Select file: </label>
<input class="form-control" type="file" id="myfile" />
</div>
<div class="form-group">
<div class="progress">
<div class="progress-bar progress-bar-success myprogress" role="progressbar" style="width:0%">0%</div>
</div>
<div class="msg"></div>
</div>
<input type="button" id="btn" class="btn-success" value="Upload" />
</form>
<?php include'generalModal.php';
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!--/category-tab-->
<?php
include_once'../../music/reCommend.php'; echo'
<script src="'.$url.'panel/uploadMusic/processUpload.js"></script>';
include '../../Blog/Footer.php';

Categories