PHP CodeIgniter - Array upload file - php

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])){

Related

update not working without any error i am using php and sql

I want to update my form using PHP and SQL but update query not working. select query working but update not working. there is no error. when I am using a select query for show value in the input field and it's working. I am trying much think but not figure out what is the error. I am trying much think but not figure out what is the error.
<?php
include 'connection.php';
include 'config.php';
if (isset($_GET['edit'])) {
{
$topHeading=$_POST['topHeading'];
$mainHeading=$_POST['mainHeading'];
$bottomHeading=$_POST['bottomHeading'];
$filesname = $_FILES['file']['name'];
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
// Select file type
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Valid file extensions
$extensions_arr = array("jpg","jpeg","png","gif","svg");
// Check extension
if( in_array($imageFileType,$extensions_arr) ){
// Convert to base64
$image_base64 = base64_encode(file_get_contents($_FILES['file']['tmp_name']) );
$images = 'data:image/'.$imageFileType.';base64,'.$image_base64;
$sql = "update banner set topHeading='$topHeading', filesname='$filesname', images='$images', mainHeading='$mainHeading', bottomHeading='$bottomHeading' where id='$id'";
if (mysqli_query($connection, $sql)) {
echo "Done";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($connection);
}
// mysqli_close($connection);
// Upload file
move_uploaded_file($_FILES['file']['tmp_name'],$target_dir.$filesname);
if($sql)
{
echo "";
}
else
{
echo "<script>alert('Data not inserted');</script>";
}
}
}
}
$query = mysqli_query($connection, "select * from banner");
while ($row = mysqli_fetch_array($query)) {
echo "<b><a href='editbanner.php?id={$row['id']}'>{$row['topHeading']}</a></b>";
echo "<br />";
}
if (isset($_GET['edit'])) {
echo '<div class="form" id="form3"><br><br><br><br><br><br>
<Span>Data Updated Successfuly......!!</span></div>';
}
?>
<?php
if (isset($_GET['id'])) {
$id = $_GET['id'];
$count = 0;
$mysqli = mysqli_query($connection,"SELECT * FROM banner");
foreach($mysqli as $row){
$count++;
?>
<form class="form-horizontal" method="post" name="form1" id="form1" enctype="multipart/form-data">
<div class="form-group label-floating form-rose">
<label for="brandname" class="control-label col-xs-2">Brand Name of Stock Broker</label>
<div class="col-xs-12">
<input type="text" name="topHeading" id="brandname" class="form-control" value="<?php echo $row["topHeading"]; ?>"/>
<span class="error" id="pointfn"></span>
</div>
</div>
<div class="form-group label-floating form-rose">
<label for="name" class="control-label col-xs-2">Contact Person</label>
<div class="col-xs-12">
<input type="text" name="mainHeading" id="name" class="form-control" value="<?php echo $row["mainHeading"]; ?>"/>
<span class="error" id="pointln"></span>
</div>
</div>
<div class="form-group label-floating form-rose">
<label for="designation" class="control-label col-xs-2">Designation</label>
<div class="col-xs-12">
<input type="text" name="bottomHeading" id="designation" class="form-control" value="<?php echo $row["bottomHeading"]; ?>"/>
<span class="error" id="designationln"></span>
</div>
</div>
<div class="label-floating form-rose file-upload">
<div class="file-select">
<div class="file-select-button" id="fileName">Upload Logo</div>
<div class="file-select-name" id="noFile">No file chosen...</div>
<input type="file" name="file" id="chooseFile" required>
</div>
</div>
<div class="form-group label-floating form-rose">
<div class="col-xs-12"> <input type='checkbox' name='checkbox' id="checkbox" required /> <label for="checkbox" class="col-xs-10 term">I accept the terms and condition</label>
</div>
</div>
<button type="submit" name="edit" value="Submit" id="formT" class="button-cta cta btn" onClick="return validateForm()"> I am Interested!</button>
</form>
<?php }} ?>
</body>
</html>
$id is missing above your update query...
$id = $_REQUEST['id'];
$sql = "update banner set topHeading='$topHeading', filesname='$filesname', images='$images', mainHeading='$mainHeading', bottomHeading='$bottomHeading' where id='$id'";

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"];
}

I Want to update/ Edit my data ..data get updated but showing some error in view page in PHP

It's showing the following errors:
1.Severity: Warning
Message: Missing argument 1 for Super_Admin::edit_category()
Filename: controllers/super_admin.php
Severity: Notice
Message: Undefined variable: category_id
Filename: controllers/super_admin.php
Below is Model's code :
<?php
class Super_Admin_Model extends CI_Model
{
public function select_catgory_info_by_id($category_id)
{
$this->db->select('*');
$this->db->from('tbl_category');
$this->db->where('category_id', $category_id);
$query_result = $this->db->get();
$result = $query_result->row();
return $result;
}
public function update_category_by_id($category_id, $data)
{
$this->db->where('category_id', $category_id);
$this->db->update('tbl_category', $data);
}
}
?>
Below is controller's code :
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Super_Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$admin_id = $this->session->userdata('admin_id');
if ($admin_id == NULL)
{
redirect('admin_login', 'refresh');
}
}
public function edit_category($category_id)
{
$data = array();
$data['category_info'] = $this->super_admin_model->select_catgory_info_by_id($category_id);
$data['maincontent'] = $this->load->view('admin/edit_category', $data, true);
$data['title'] = 'Edit Category';
$this->load->view('admin/admin_master', $data);
}
public function update_category()
{
$data = array();
$category_id = $this->input->post('category_id', TRUE);
$data['category_name'] = $this->input->post('category_name', TRUE);
$data['category_description'] = $this->input->post('category_description', TRUE);
$data['publication_status'] = $this->input->post('publication_status', TRUE);
$this->super_admin_model->update_category_by_id($category_id, $data);
$sdata['message'] = "Updated successfully";
$this->session->set_userdata($sdata);
redirect('super_admin/edit_category');
}
}
?>
This is my view page:
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Category Info</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
Edit Category
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<form action="<?php echo base_url(); ?>super_admin/update_category" method="post" >
<div>
<?php
$message = $this->session->userdata('message');
if ($message)
{
echo $message;
$this->session->unset_userdata('message');
}
?>
</div>
<div class="form-group">
<label>Category Name</label>
<input class="form-control" name="category_name" value="<?php echo $category_info->category_name; ?>">
<input type="hidden" class="form-control" name="category_id" value="<?php echo $category_info->category_id; ?>">
<!-- <p class="help-block">Example block-level help text here.</p> -->
</div>
<div class="form-group">
<label>Category Description</label>
<textarea class="form-control" rows="3" name="category_description" ><?php echo $category_info->category_description; ?> </textarea>
</div>
<div class="form-group">
<label>Category Status</label>
<div class="radio">
<?php
if ($category_info->publication_status == 1)
{
?>
<label>
<input type="radio" name="publication_status" id="optionsRadios1" value="1" checked>Published
</label>
<?php
}
else
{
?>
<label>
<input type="radio" name="publication_status" id="optionsRadios1" value="1" >Published
</label>
<?php
}
?>
</div>
<div class="radio">
<?php
if ($category_info->publication_status == 0)
{
?>
<label>
<input type="radio" name="publication_status" id="optionsRadios2" value="0" checked>Unpublished
</label>
<?php
}
else
{
?>
<label>
<input type="radio" name="publication_status" id="optionsRadios2" value="0">Unpublished
</label>
<?php
}
?>
</div>
</div>
<button type="submit" class="btn btn-default">Submit </button>
<button type="reset" class="btn btn-default">Reset </button>
</form>
</div>
</div>
<!-- /.row (nested) -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
At the end of Super_Admin::update_category() you call redirect('super_admin/edit_category');. This makes an HTTP redirection to the URL /super_admin/edit_category that is handled by method Super_Admin::edit_category().
This method requires an argument but no one is given in the URL (this is the warning). The cause of the notice is obvious: since edit_category() is called without any argument, its parameter $category_id is not set.
You should call redirect() like this (for example):
redirect('super_admin/edit_category/'.$category_id);

sending $_SERVER['request_uri'] via post

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'].

Categories