I am trying to update and upload image to folder using php fileupload also some contents in the text area and text field. Here is my code,problem is I am not getting any result from the database. Please help.
$id=(isset($_GET['id']))?$_GET['id']:'';
$val=view_data_event($id);
if (isset($_POST["events"])&&isset($_POST["description"]))
{
$id=$_POST["id"];
$title=$_POST["events"];
$description=$_POST["description"];
$filetmp=$_FILES["images"]["tmp_name"];
$filename=$_FILES["images"]["name"];
$filetype=$_FILES["images"]["type"];
$filepath= "photo2/".$filename;
move_uploaded_file( $filetmp,$filepath);
$data=array( $title,$description,$filename,$filepath,$id);
$update1=update_event($data);
if($update1)
{
echo "<script>location.href='hotel2_galery_event.php'</script>";
}
}
HTML
<form action="hotel2_galery_eventedit.php" method="post" class="col-sm-4">
<input type="hidden" name="id" value="">
<div class="form-group has-info">
<label class="control-label" for="inputSuccess">Event title</label>
<input type="text" class="form-control" name="events" value="">
</div>
<div class="form-group has-info">
<label>Event Description</label>
<textarea name="description" class="form-control " rows="3">
</textarea><br><br>
</div>
<div class="form-group has-info">
<label>Event Related images</label>
<input type="file" name="images">
<input type="hidden" value="">
<input type="hidden" value="">
</div>
<button type="submit" class="btn btn-primary">
<span>UPDATE</span>
</button>
</form>
Whenever you want to upload files, you must put a enctype="multipart/form-data" attribute on the form tag. Standard POST encoding cannot handle files.
Related
How is a mathematical operation performed in PHP with values received from "number1" and "number2" The result is shown in "result" ?
<div class="row">
<form class="form " action="" method="post" enctype="multipart/form-data">
<form class="form1">
<div class="form-group text-right font-12">
<label for="number">number 1</label>
<input type="number" name="number1" value="" class="form-control" placeholder="number1">
</div>
</form>
<form class="form1">
<div class="form-group text-right font-12">
<label for="number">number 2</label>
<input type="number" name="number2" value="" class="form-control" placeholder="number2">
</div>
</form>
<form class="form1">
<div class="form-group text-right font-12">
<label for="number">The result here</label>
<input type="number" value="" class="form-control" disabled="disabled">
</div>
</form>
<button class="btn btn-info font-12 " type="submit" name="save" value="Show Result">save</button>
</form>
</div>
First of all you don't need nested forms to make the UI.
I will write a simple example that you can change to match your UI needs.
<?php
$a = $_GET['number1'];
$b = $_GET['number2'];
$result = NULL;
if (isset($a) && isset($b)) {
$result = $a + $b;
}
?>
<form action="?" method="GET">
<input name="number1" value="" />
<input name="number2" value="" />
<input value="<?= $result ?>" disabled />
<button type="submit">Show Result</button>
</form>
Can you be more specific next time? I think your question is about how to handle such a form in PHP. Just first read some tutorials about it. A great website is w3schools.com. Here is one about form handling: https://www.w3schools.com/php/php_forms.asp
First, the reason why I have three forms on one page is for layout purposes. I have three input boxes going across one line and then another under it and so on. If I place them under one form tag, I get bad looking input boxes that goes from top to bottom. I have tried some solutions but they have not worked. Each line would put 3 three entries instead of one and some data would not show up or only one form would show up in the database.
HTML
<form class="form-inline" id="Test1" method="POST">
<div class="form-group">
<label>Name: <input name="FN" type="text" class="form-control" id="" value=""> </label> </div> </form>
<form class="form-inline" id="Test2" method="POST">
<div class="form-group">
<label>Name: <input name="LN" type="text" class="form-control" id="" value=""> </label> </div> </form>
<form class="form-inline" id="Test3" method="POST">
<div class="form-group">
<label>Name: <input name="EM" type="text" class="form-control" id="" value=""> </label> </div> </form>
<div class="form-group"><br>
<div class="col-sm-offset-2"> <button type="button" class="SB btn btn-default">Book Now</button> </div>
<script>
$(document).on('click','.SB',function(e) {
formData = $('#Test1, #Test2', '#Test3').serialize();
$.post(
'Process.php', formData
);
});
I only get the first form with this and the other two are blank but are on a single line. All inputs are unique. I have also tried the docbyid and it would add three lines but not work correctly. Any Help would be great.
PHP:
require('DBCon.php');
$statement = $link->prepare("INSERT INTO Database (FN, LN, EM) VALUES( :CFN, :CLN, :CE)");
$ClientFN = $_POST['FN'];
$ClientLN = $_POST['LN'];
$ClientEmail = $_POST['EM'];
$statement->execute(array(
":CFN" => "$ClientFN",
":CLN" => "$ClientLN",
":CE" => "$ClientEmail"));
$statement = null;
$link = null;
// Echo Successful attempt
echo "<p Data added to database.</p></br></br>";
?>
Your button should call a function rather than submit the form. Submitting will only send the data from the first form.
You should really use one form and use CSS to correct any display issues, but if you were to use separate forms, the following should do what you are looking for (make sure your closing tags are in the correct place):
<form class="form-inline" id="Test1">
<div class="form-group">
<label>Name: <input name="FN" type="text" class="form-control" id="" value=""></label>
</div>
</form>
<form class="form-inline" id="Test2" method="POST">
<div class="form-group">
<label>Name: <input name="LN" type="text" class="form-control" id="" value=""> </label>
</div>
</form>
<form class="form-inline" id="Test3" method="POST">
<div class="form-group">
<label>Name: <input name="EM" type="text" class="form-control" id="" value=""> </label>
</div>
</form>
<div class="form-group">
<div class="col-sm-offset-2"> <button type="button" class="sumbitButton btn btn-default">Book Now</button>
</div>
<script>
$(document).on('click','.sumbitButton',function(e) {
formData = $('#Test1, #Test2', '#Test3').serialize();
$.post(
'Process.PHP', formData
);
});
</script>
Try this:
<form method="post" action="Process.PHP">
<div class="form-inline">
<div class="form-group">
<label>Name: <input name="FN" type="text" class="form-control" id="" value=""></label>
</div>
</div>
<div class="form-inline">
<div class="form-group">
<label>Name: <input name="LN" type="text" class="form-control" id="" value=""> </label>
</div>
</div>
<div class="form-inline">
<div class="form-group">
<label>Name: <input name="EM" type="text" class="form-control" id="" value=""> </label>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2"> <button type="submit" class="sumbitButton btn btn-default">Book Now</button>
</div>
</form>
I am trying to submit form data using angular js to server (codeigniter)
my for data is:
<form>
<div class="form-group">
<label for="name">First name: </label>
<input type="text" class="form-control" name="fname" ng-model="fname">
</div>
<div class="form-group">
<label for="name">Last name: </label>
<input type="text" class="form-control" name="lname" ng-model="lname">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" name="email" ng-model="email">
</div>
<input type="hidden" name="<?=$this->security->get_csrf_token_name();?>" ng-model="csrfData" ng-init="csrfData='<?php echo $this->security->get_csrf_hash(); ?>'" />
<input type="hidden" ng-model="baseData" ng-init="baseData='<?=base_url();?>'" />
<div class="form-group row">
<div class="col-xs-6">
<a class="btn btn-block btn-info" ng-click="basicInfoAdd()">
<span>Next Section </span>
</a>
<!--ui-sref="reg.professional"-->
</div>
</div>
</form>
and my angular js controller code is
controller("basicInfo",function($scope,$http){
$scope.new_user = true;
$scope.basicInfoAdd = function(){
//alert($scope.baseData);
$http.get($scope.baseData+"angReg/basicReg/2",{'csrf_test_name':$scope.csrfData,'fname':$scope.fname,'lname':$scope.lname,'email':$scope.email})
.then(function(response){
alert(response.data);
})
}
and my server side code is
public function basicReg()
{
$data = json_decode(file_get_contents("php://input"));
echo $clmdata = $data->fname;
}
please tell me what is wrong in my code...?
I have this situation:
2 files (contact.html and booking.php)
On my contact.html I have the following code:
<form action="booking.php" method="POST" role="form" class="formular">
<h3>Online booking!</h3>
<br />
<div class="control-group">
<div class="controls">
<div class="input-group">
<input type="text" id="dateFrom" name="dateFrom" class="form-control" placeholder="Check in" style="width: 258px;"/>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<div class="input-group">
<input type="text" id="dateToInput" name="dateToInput" class="form-control" placeholder="Check out" style="width: 258px;"/>
</div>
</div>
</div>
</form>
On my booking.php file I have the following code:
<form>
<div class="booking">
<form name="" action=" " method="post">
<h1>BOOKING</h1>
<div class="bookingDate">
<p>Check in:</p>
<div id="dateFrom">
</div>
</div>
</div>
<div class="bookingDate">
<p>Check out:</p>
<div id="dateTo">
</div>
</div>
<input type="hidden" name="dateFrom" id="dateFromInput" value= $_POST["dateFrom"] />
<input type="hidden" name="dateTo" id="dateToInput" value=$_POST["dateTo"]/>
</form>
So, I have two calendars on my contact.html page and two calendars on booking.php.
I want that when I choose 2 dates (on my contact.html) form, those exact dates to be passed to the other two calendars that I have on booking.php
Could anyone please help me? I have searched a lot and I can't find an answer.
Modify the code to following in value section. Similary for other field as well.
<input type="hidden" name="dateFrom" id="dateFromInput" value= "<?php echo $_POST["dateFrom"] ?>" />
Contact has name="dateToInput" yet booking is looking for dateTo
Fix one: correct the name of the input in contact
<input type="text" id="dateToInput" name="dateTo" class="form-
Fix two: You have no PHP tags in your booking code, without them $_POST is not available, nor are those values being printed.
<input type="hidden" name="dateFrom"
id="dateFromInput" value="<?php echo $_POST["dateFrom"];?>">
<input type="hidden" name="dateTo"
id="dateToInput" value="<?php echo $_POST["dateTo"]; ">
Note I also wrapped the values with quotes
i need to get my input value using JavaScript but i get undefined only. Here is my code:
document.forms[0].elements[0] or
document.forms['form_id']['fieldname']
Where is my mistake?
Here is my form:
<form action="registrationHandler.php" onsubmit="return validateRegistrationForm()" method="post" name="reg_form" enctype="multipart/form-data" id="reg-form">
<div>
<label for="username">Username</label>
<input type="text" name="username" required="">
</div>
<div>
<label for="password">Password</label>
<input type="password" name="password" required="">
</div>
<div>
<label for="email">E-mail</label>
<input type="text" name="email">
</div>
<div>
<label for="telephone">Telephone</label>
<input type="text" name="telephone">
</div>
<div>
<label for="sex">Sex</label>
<input type="radio" value="male" name="sex">Male
<input type="radio" value="female" name="sex">Female
</div>
<div>
<label for="user_photo">User photo</label>
<input type="file" name="user_photo">
</div>
<div>
<label for="birthDate">Birth Date</label>
<input type="date" name="birthDate">
</div>
<div>
<label for="country">Country</label>
<input type="text" name="country">
</div>
<div>
<label for="info">Info about user</label>
<textarea name="info"></textarea>
</div>
<div>
<input type="hidden" name="PHPSESSID" value="<?php echo session_id(); ?>">
</div>
<div><input type="submit" value="Register"></div>
</form>
Form lies in php file, maybe problem in that? Because when i console log forms.length i get zero...
You need to put these DOM object accessing codes into the window.onload event handler,because it need to wait the document loaded before accessing the DOM objects.
Can you try for example:
document.forms['reg-form']['email'].value
I think you might not are not targeting the right Dom-element with
document.forms['form_id']['fieldname']
Please look at this jsfiddle-Sample:
http://jsfiddle.net/3gevoyn5/8/
I have two input fields and get the Values with this code, which is then output again:
function getValues(){
var test = document.forms['myform']['firstname'].value + " " + document.forms['myform']['lastname'].value;
document.getElementById("demo").innerHTML = test;
}