Image is not posting through form post method - php

I am beginner in codeignitor.I want to post an image through a post method. All data is being posted but the image is not posting in controller.
Here is my view code.
<form action="<?php echo site_url('adminpanel/add_event');?>" method="post" name="addform" enctype="multipart/form-data">
<fieldset>
<p>
<label style="width:20%;float:left;">Event Title<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_title" id="event_title" placeholder="Event Title" value="<?php if(isset($teenzstore_edit_data['product_name'])) echo $teenzstore_edit_data['product_name'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Select Age<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<select name="age" id="age" class="form-control" class="form-control" onChange="return get_product_filter('<?php echo base_url();?>',this.value);">
<option value="0">Select Age</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
</select>
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Image</label>
<label style="width:1%;float:left;">:</label>
<input type="file" name="event_image" id="event_image" onchange="checkExtension(this.value)" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Date<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_date" id="event_date" placeholder="Event Date" value="<?php if(isset($teenzstore_edit_data['product_points'])) echo $teenzstore_edit_data['product_points'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Time<span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<input class="text-input small-input" type="text" name="event_time" id="event_time" placeholder="Event Time" value="<?php if(isset($teenzstore_edit_data['product_points'])) echo $teenzstore_edit_data['product_points'];?>" />
</p>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Venue <span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<label style="width:20%;float:left;">
<textarea cols="80" id="event_venue" style="width:77% !important;" name="event_venue" rows="10">
<?php if(isset($restaurant_edit_data[ 'rest_description'])) echo $restaurant_edit_data[ 'rest_description'];?>
</textarea>
</p>
<script type="text/javascript">
CKEDITOR.replace('event_venue', {
width: "630",
});
</script>
<p style="clear:both;"></p>
<p>
<label style="width:20%;float:left;">Event Description <span style="color:red">*</span>
</label>
<label style="width:1%;float:left;">:</label>
<label style="width:20%;float:left;">
<textarea cols="80" id="event_desc" style="width:77% !important;" name="event_desc" rows="10">
<?php if(isset($restaurant_edit_data[ 'rest_description'])) echo $restaurant_edit_data[ 'rest_description'];?>
</textarea>
</p>
<script type="text/javascript">
CKEDITOR.replace('event_desc', {
width: "630",
});
</script>
</fieldset>
<div class="clear"></div>
<p>
<label style="width:20%;float:left;"> </label>
<label style="width:1%;float:left;"> </label>
<input class="button" type="submit" name="submit" value="Submit" />
<input class="button" type="button" value="Cancel" name="cancel" onclick="javascript:history.go(-1);" />
</p>
</form>

I can't find problem, because in my computer everything works fine, but can explain you method debug:
1) Remove from your code any fragment that is not connected with problem:
I created index.html with this:
<html>
<head>
<meta lang="en">
</head>
<body>
<form action="test.php" method="post" name="addform" enctype="multipart/form-data">
<fieldset>
<hr>
<p>
<label style="width:20%;float:left;">Event Image</label>
<label style="width:1%;float:left;">:</label>
<input type="file" name="event_image" id="event_image" onchange="checkExtension(this.value)" />
</p>
<p style="clear:both;"></p>
<hr>
</fieldset>
<div class="clear"></div>
<p>
<label style="width:20%;float:left;"> </label>
<label style="width:1%;float:left;"> </label>
<input class="button" type="submit" name="submit" value="Submit" />
<input class="button" type="button" value="Cancel" name="cancel" onclick="javascript:history.go(-1);" />
</p>
</form>
</body>
</html>
Next I created file test.php in the same directory with content:
<?php
var_dump($_POST);
var_dump($_FILES);
After connecting file in form I obtained the following content:
array(1) { ["submit"]=> string(6) "Submit" } array(1) { ["event_image"]=> array(5) { ["name"]=> string(38) "image.png" ["type"]=> string(9) "image/png" ["tmp_name"]=> string(14) "/tmp/phpBQAZXv" ["error"]=> int(0) ["size"]=> int(124622) } }
Show me your result of this test. Probably problem is in processing, not in form.

Create a function in Your Controller by the name of add_event because your are posting your form data to this action. your code may like below
class adminpanel extands CI_Controller{
function add_event(){
echo $_FILES['event_image']['name'];
}
}

Related

Created simple HTML form with PHP, but won't POST email and opens blank page

I created the following HTML and PHP documents. When I fill in the information and click submit, I don't receive any errors, but I get a blank page and also don't receive an email with the form information. I'm fairly new at this, but could use the help on why I'm not getting the email and how to get rid of the blank page. Thank you.
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<div id="title">
<div id="titlecontact">
<h1>Excelerate Growth, LLC</h1>
<h4><em>Consulting to Help Small Businesses Excel</em></h4>
</div>
</div>
<header id="header">
<nav class="links" style="--items: 5;">
Home
About
Services
Results
Contact
<span class="line"></span>
</nav>
</header>
<?=$thankYou ?>
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
<div id="social">
<img class="linkedin" src="linkedin.png">
<img class="email2" src="email.png">
<img class="facebook" src="facebook.png">
<br/>
<br/>
</div>
<br/>
<br/>
<?php
if($_POST["submit"]) {
$recipient="jscotty78#gmail.com";
$subject="Form to email message";
$sender=$_POST["sender"];
$senderEmail=$_POST["senderEmail"];
$senderPhone=$_POST["senderPhone"];
$type=$_POST["type"];
$message=$_POST["message"];
$mailBody="Name: $sender\nEmail: $senderEmail\nPhone: $senderPhone\nType: $type\n$message";
mail($recipient, $subject, $mailBody, "From: $sender <$senderEmail>");
$thankYou="<p>Thank you! Your message has been sent.</p>";
}
?>
Try This Code Below with name="submit"
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" name="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
POST form data is sent using name => value. Here:
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
</form>
you have no input with name="submit". This is why $_POST['submit'] is equal to "", which is considered false in PHP. So mail() is not running.
Instead, try this:
<form class="form" action="contact2.php" method="POST">
<h1>CONTACT US</h1>
<p class="name">Name</p><input class="nametext" type="text" name="sender" />
<p class="email">Email</p><input class="emailtext" type="text" name="senderEmail" />
<p class="phone">Phone</p><input class="phonetext" type="tel" name="senderPhone" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" required />
<br />
<br />
<p class="interest">Interest</p>
<select class="package" name="type" size="1">
<option value="update">Free Consultation</option>
<option value="change">Growth Management</option>
<option value="addition">Customer Service</option>
<option value="new">Process Management</option>
</select>
<br />
<br />
<p class="message">Share More About Your Business</p><textarea class="text" name="message" rows="6" cols="25"></textarea><br /><br />
<input class="submit" type="submit" value="Send"><input class="reset" type="reset" value="Clear">
<input type="hidden" name="submit" value="a" />
</form>
Notice name="submit". This gets sent along with the form data.

Update form to edit record in the DB PHP HTML

guys I have a problem with a PHP page.
I'm trying to make a form to update the record of a DB.
I'm displaying the form with an echo but I have some problems with quotes
<? echo'
<img src="logo.jpg">
<fieldset>
<input name="aspettogen2" type="text" value="<?php echo $aspettogen;?>">
</fieldset>
<fieldset>
<input name="desc" type="text" maxlength="255">
</fieldset>
<fieldset>
<input name="ragsoc" type="text" maxlength="100">
</fieldset>
<fieldset>
<input name="numcivico" type="text" maxlength="20">
</fieldset>
<fieldset>
<input name="validita" type="text">
</fieldset>
<fieldset>
<input name="odierna" type="data">
</fieldset>
<fieldset>
<input name="preavviso" type="text">
</fieldset>
<fieldset>
<input name="scadenza" type="text">
</fieldset>
<fieldset>
<input name="presc" type="text" maxlength="255">
</fieldset>
<fieldset>
<input name="freq" type="number">
</fieldset>
<fieldset>
<input name="datacontr" type="text">
</fieldset>
<fieldset>
<input name="proxcontr" type="text">
</fieldset>
<fieldset>
<input name="note" type="text">
</fieldset>
</form>
</div>
</body>
</html>';
in the first fieldset value="<?php echo $aspettogen;?"> it appears gray because the quote after the echo turn it into a "comment" and i cant print the value..
how can i solve it?
i've tried to do like this Value="'<?php echo $aspettogen;?'"> but i receive the error Parse error: syntax error, unexpected '?' in /var/..... on line 50
You have wrong syntax in that line. I have made the necessary changes.
Code:
<? echo'
<img src="logo.jpg">
<fieldset>
<input name="aspettogen2" placeholder="Aspetto Generale" type="text" value="<?php echo $aspettogen;?>">
</fieldset>
<fieldset>
<input name="desc" placeholder="Descrizione" type="text" maxlength="255">
</fieldset>
<fieldset>
<input name="ragsoc" placeholder="Ragione Sociale" type="text" maxlength="100">
</fieldset>
<fieldset>
<input name="numcivico" placeholder="Numero Civico" type="text" maxlength="20">
</fieldset>
<fieldset>
<input name="validita" placeholder="Validita" type="text">
</fieldset>
<fieldset>
<input name="odierna" placeholder="Data" type="data" id="today" readonly >
</fieldset>
<fieldset>
<input name="preavviso" placeholder="Preavviso" type="text">
</fieldset>
<fieldset>
<input name="scadenza" placeholder="Scadenza" type="text">
</fieldset>
<fieldset>
<input name="presc" placeholder="Prescrizioni" type="text" maxlength="255">
</fieldset>
<fieldset>
<input name="freq" placeholder="Frequenza (in giorni)" type="number">
</fieldset>
<fieldset>
<input name="note" placeholder="Note" type="text">
</fieldset>
<fieldset>
<button name="submit" type="submit" id="contact-submit">Inserisci</button>
</fieldset>
</form>
</div>
</body>
</html>';?>

Not able to print data from Html in Php file

<body>
<span>
<div class="heading">
<h3><img src="http://zicom.com/img/ilayashop-1482233381.jpg" alt="Zicom Logo" ></h3>
<h1><i>Zicom </i> SMS Application</h1><br>
</span>
</div>
<br>
<div>
<form method='post' action=''>
<label for="fname">Contact Number</label>
<input type="text" id="fname" name="number" placeholder="Contact Number....">
<label for="sms" id="msg">Message</label>
<select id="country" name="message">
<option value="" name="message">Blank</option>
<option value="hello" name="message">Abandoned Call</option>
<option value="" name="message">Audit Call </option>
</select>
<input type="text"id="msg" name="message" placeholder="Type your Message...." >
<input type="submit" value="Send" name="send">
</form>
</div>
<?php
if(isset($_POST)) {
$n = $_POST['number'];
$m = $_POST['message'];
echo "$n $m";
}
?>
</body>
</html>
I have used the same method many times and i have succesfully sent the data to php file, but im unable to do the same. I try to print the content of form, but is not executing.

How to assign array value to textarea in smarty php

I have form where i have to edit this information. I can fetch all the fields to edit except description. Why textarea is not accepting dynamic array value? this is my issue.Please help me to fix this. Thanks in advance!!.
<form id="commentForm" name="commentForm" action="index.php?mdf=addbiography" method="POST" enctype="multipart/form-data" >
{if $admindetails[0].name neq ''}
<input type="hidden" id="action" name="action" value="saveupdate">
<input type="hidden" id="upid" name="upid" value="{$admindetails[0].id}">
{else}
<input type="hidden" id="action" name="action" value="add_biography">
{/if}
<article class="module width_full">
<header><h3 style="color: white;"> Add Biography</h3></header>
<div class="module_content">
<fieldset>
<div><label>Name<span class="star">*</span></label>
<input type="text" id="cname" name="name" class="required" value="{$admindetails[0].name}"></div></br></br></br>
<label>Description:<span class="star">*</span></label>
<textarea cols="60" rows="5" type="text" class="required" name="description" id="description" value="{$admindetails[0].description}"></textarea></br></br></br><br><br><br><br>
<div><label>Type<span class="star">*</span></label>
<select name="type" id="type" >
<option value="personal">Personal</option>
<option value="professional">Professional</option>
</select>
</div></br>
<div><label>Image<span class="star">*</span></label>
{if $admindetails[0].image eq ''}
<input type="file" name="file" id="file" style="margin-left:10px;" accept="image/*" class="required" value="">
{else}
<input type="file" name="file" id="file" style="margin-left:10px;" accept="image/*" value="">
{/if}
</div></br>
<img src="upload/{$admindetails[0].image}" width="300" height="300" alt="">
</fieldset>
<div class="clear"></div>
</div>
<footer>
<div class="submit_link">
<input type="submit" value="Save">
<input type="reset" value="Reset">
</div>
</footer>
</article><!-- end of stats article -->
</form>
Have you try doing this..
<textarea cols="60" rows="5" type="text" class="required" name="description" id="description" >{$admindetails[0].description}</textarea>

My table is not being displayed

I am trying to make a registration page for a website however for some reason it won't display my table? I can't seem to locate the problem and it was working fine earlier. My site can be accessed on the server at cs12jkk.icsnewmedia.net
I am a second year undergraduate at the university of Leeds and i'm trying to make a log in and system as part of a project and can't get it to display anything at all!
<?php require_once("functions.inc");?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="register.js">
<link rel="stylesheet" type="text/css" href="form.css">
<title>Registration Page</title>
</head>
<body>
<form id="userForm" method="POST" action="register-process.php">
<div>
<fieldset>
<legend>Registration Information</legend>
<div id="errorDiv">
<?php
if (isset($_SESSION['error']) && isset($_SESSION['formAttempt'])) {
unset($_SESSION['formAttempt']);
print "Errors encountered<br />\n";
foreach ($_SESSION['error'] as $error) {
print $error . "<br />\n";
} //end foreach
}
?>
</div>
<label for="fname">First Name:* </label>
<input type="text" id="fname" name="fname" />
<span class="errorFeedback errorSpan"
id="fnameError"> First Name is required</span>
<br />
<label for="lname">Last Name:* </label>
<input type="text" id="lname" name="lname">
<span class="errorFeedback errorSpan"
id="lnameError">Last Name is required</span>
<br />
<label for="email">E-mail Address:*</label>
<input type="text" id="email" name="email">
<span class="errorFeedback errorSpan"
id="emailError">E-mail is required</span>
<br />
<label for="password1">Password:*</label>
<input type="password" id="password1" name="password1"> <span class="errorFeedback errorSpan"
id="password1Error">Password required</span>
<br />
<label for="password2">Verify Password:*</label>
<input type="password" id="password2" name="password2">
<span class="errorFeedback errorSpan"
id="password2Error">Password required</span>
<br />
<label for="addr">Address: </label>
<input type="text" id="addr" name="addr">
<br />
<label for="city">City:</label>
<input type="text" id="city" name="city">
<br />
<label for="state">State:</label>
<select name="county" id="county">
<option></option>
<option value="AL">Alabama</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="FL">Florida</option>
<option value="Il">Illinois</option>
<option value="NJ">New Jersey</option>
<option value="NY">New York</option>
<option value="WI">Wiscon</option>
</select>
<br />
<label for="zip">ZIP:</label>
<input type="text" id="zip" name="zip">
<br />
<label for="phone">Phone Number:</label>
<input type="text" id="phone" name="phone">
<span class="errorFeedback errorSpan"
id="phoneError">Format: xxxx-xxx-xxxx</span>
<br />
<br />
<label for="mobile"> Number Type:</label>
<input class="radioButton" type="radio"
name="phonetype" id="mobile" value="mobile">
<label class="radioButton" for="mobile">Mobile</label>
<input class="radioButton" type="radio"
name="phonetype" id="home" value="home">
<label class="radioButton" for="home">Home</label>
<span class="errorFeedback errorSpan phoneTypeError"
id="phonetypeError">Please choose an option</span>
<br />
<input type="submit" id="submit" name="submit">
</fieldset>
</div>
</form>
</body>
</html>
If you are talking about: http://cs12jkk.icsnewmedia.net/RestaurantApplication/register.php
If you look at the html source you will see the html is all there. The problem is with line 5:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="register.js">
You don't have a closing /> or a </script> after you include register.js so all of the html after that isn't being rendered because it assumes it is part of your <script>.

Categories