how to insert logic work on php - php

i got template php from internet. then i want make other insert. but i dont know this code work
in code have submit button like this
<input type="submit" class="btn btn-primary" value="Добави">
and form like this
<div class="form-group">
<label>Nama</label>
<input type="text" class="form-control" name="name" required="required">
</div>
<div class="form-group">
<label> Deskripsi</label>
<textarea class="form-control" name="description"></textarea>
</div>
<div class="form-group">
<label>Gambar</label>
<input type="file" name="image" class="form-control" required="required">
</div>
<div class="form-group">
<label>Harga</label>
<input type="text" name="price" class="form-control" required="required">
</div>
<div class="form-group">
<label>
Cafe Yang Menjual</label>
<select name="cafe_id" class="form-control" required="required">
<option value="">Silahkan Pilih Restoran Yang Akan Menjual Makanan Ini</option>
<?php foreach($admin->getAllMenus() as $menu) { ?>
<option value="<?php echo $menu->id; ?>"><?php echo $menu->nama; ?></option>
<?php } ?>
</select>
</div>
and php syntax from that food.php
if(isset($_POST["name"])){
$image_name=$_FILES["image"]["name"];
$image=$_FILES["image"]["tmp_name"];
$image_name=time().$image_name;
move_uploaded_file($image, "../foods/".strtolower($image_name));
$_POST["image"]=strtolower($image_name);
$admin->addFood($_POST);
}
and modul code for insert
public function addFood($data){
if($this->db->query("insert into foods(name,image,description,price,cafe_id) values('".$data['name']."','".$data['image']."','".$data['description']."',".$data['price'].",".$data['cafe_id'].")")){
echo"<script>window.location.href='index.php?page=foods';
alert('Успешно добавяне на храна');</script>";
}
else{
echo"<script>window.location.href='index.php?page=foods';
alert('Проблем при добавяне на храна');</script>";
}
}
i dont know how that code connect with that submit button. with value value="Добави"
that i know is isset($_POST["value submit button"])) but in this code there is name.

I'm not sure I totally understand your question but basically a <form> HTML element can be used to transfer data to the server, such as:
<form method="POST" action="food.php">
...
</form>
Then when the submit method is triggered, the data will be POSTed to food.php.
Just to be clear, you need to have PHP installed and running on a webserver before this will work; you can't just copy PHP code into a HTML file and hope it works.

Related

PHP not getting any response from the form on the previous page

I have the file "1.php" and the file "2.php" ...
In "1.php", there's a HTML form:
<form action="2.php" method="post">
<div class="form-group">
<label for="db_username">Field 1:</label>
<input type="text" class="form-control" id="db_username">
</div>
<div class="form-group">
<label for="db_password">Field 2:</label>
<input type="password" class="form-control" id="db_password">
</div>
<div class="form-group">
<label for="db_passphrase">Field 3:</label>
<input type="text" class="form-control" id="db_passphrase">
</div>
<button type="submit" class="btn btn-default">Next</button>
</form>
While in "2.php", the action must be applied in PHP .. like that:
<?php
// Process of Step "1"
$db_username = $_POST['db_username'];
$db_password = $_POST['db_password'];
$db_passphrase = $_POST['db_passphrase'];
if( !isset($db_username) || !isset($db_password) || !isset($db_passphrase) ) {
header("Location: 1.php?error=1");
die();
}
?>
However .. the values of $_POST['db_username'], $_POST['db_password'] and $_POST['db_passphrase'] is empty...
You need to use the name attribute to later access the $_POST data, as in:
<input type="text" class="form-control" id="db_username" name="db_username">
You need to give the inputs a name and acces that value through $_POST['name'].
id is not relevant for php form handling
You have to give name for the textfields like this
<input type="text" class="form-control" id="db_username" name="db_username">
Put name instead of id. it should work

How to get value from textarea in Laravel 5.2?

I'm currently working on Laravel 5.2 and I'm finding difficult to fetch value from textarea inside controller.
I've tried $request->input just like we used to fetch values from inputs but it's not working in my case. I have done this far.
managecategories.blade.php
<form action="/addcategories" method="post" id="addcategory_form" name="addcategory_form">
<div>
<label>Insert Category</label>
<input type="text" name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$">
</div>
<div>
<label>Insert Category</label>
<textarea name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$" row="5" col="200"></textarea>
</div>
<input type="submit" value="Add Category" id="category_btn">
</form>
AdminAjaxController
public function addcategory(Request $request)
{
$category=$request->input('category');
$category_description=$request->input('description');
$insertcategory= DB::insert('insert into categories(category_name,description) values(?, ?)',[$category,$category_description]);
$fetch_category= DB::select('select category_name,category_id from categories');
return response()->json(array('add_category' => $category),200);
}
Oops Pity me! Both fields are named category. I need to change the name on the textarea to description caught by Aynber.
here is the edited and correct code
<form action="/addcategories" method="post" id="addcategory_form" name="addcategory_form">
<div>
<label>Insert Category</label>
<input type="text" name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$">
</div>
<div>
<label>Insert Category</label>
<textarea name="description" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$" row="5" col="200"></textarea>
</div>
<input type="submit" value="Add Category" id="category_btn">
thanks mate! :)

Why php form not submitting?

I'm developing a script for online admission in a website. Below is php code of the page. The problem is that it's not submitting.
<?php
include ("include/header.php"), include ("include/config.php");
if(isset($_POST['applyAdmission'])) {
$admission_no = $_POST['admission_no'];
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$p_add = $_POST['p_add'];
$c_add = $_POST['c_add'];
$dob = $_POST['dob'];
$education = $_POST['education'];
$mobile = $_POST['mobile_no'];
$course = $_POST['course'];
$subjects = $_POST['subjects'];
$timing = $_POST['timing'];
$filepath_pic = $_FILES['picture']['name'];
$res_move_pic = move_uploaded_file($_FILES['picture']['tmp_name'], "/admission/".$filepath_pic);
$filepath_sign = $_FILES['sign']['name'];
$res_move_sign = move_uploaded_file($_FILES['sign']['tmp_name'], "/admission/".$filepath_sign);
$agree_terms = $_POST['agree_terms'];
$agree_cond = $_POST['agree_cond'];
if ($res_move_pic == 1 && $res_move_sign == 1 ) {
$query = "INSERT into online_admission (f_name, l_name, p_add, c_add, dob, degree, mobile_no, course, subjects, timing, pic, sign, agree_terms, agree_cond, applied_on)
values ('$f_name','$l_name','$p_add','$c_add','$dob','$education','$mobile','$course','$subjects','$timing','$filepath_pic','$filepath_sign','$agree_terms','$agree_cond','now()')";
$res = mysql_query($query) or die("ERROR: Unable to insert into database.");
if ($res == 1) {
header('Location:http://adarshclasses.in/admission_success.php/');
exit();
} else {
header('Location:http://adarshclasses.in/admission_failed.php/');
exit();
}
} else {
echo "Error in updateing profile pic and sign";
}
} else {
//echo "Please submit the form, thanks!";
}
;?>
Everything in form is correct like I added same name in form which i used in $_POST but still it's not working, please help me to fix this issue.
Here is html codes of form:
<form class="form-horizontal" id="admission_form" method="post" action="" enctype="multipart/form-data">
<!--div class="row">
<div class="col-lg-6">
<label for="admission_no"> Admission No. </label>
<input type="hidden" class="form-control" name="admission_no" value="<?php echo $admission_no ;?>" readonly disabled>
</div>
</div--><br>
<div class="row">
<div class="col-lg-6">
<label for="f_name"> First Name <span class="required">*</span> </label>
<input type="text" class="form-control" name="f_name" placeholder="Your first name" value="<?php echo $f_name ;?>" required>
</div>
<div class="col-lg-6">
<label for="l_name"> Last Name <span class="required">*</span></label>
<input type="text" class="form-control" name="l_name" placeholder="Your last name" value="<?php echo $l_name ;?>" required>
</div>
</div><br>
<div class="row">
<div class="col-lg-12">
<label for="p_add"> Permanent Address <span class="required">*</span></label>
<textarea class="form-control" name="p_add" placeholder="Please write your permanent address" value="<?php echo $p_add ;?>" required></textarea>
</div>
</div><br>
<div class="row">
<div class="col-lg-12">
<label for="c_add"> Current Address in Jodhpur <span class="required">*</span></label>
<textarea class="form-control" name="c_add" placeholder="Please write your address where you currently living" value="<?php echo $c_add ;?>" required></textarea>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="dob"> Date of birth <span class="required">*</span></label>
<input type="date" class="form-control" name="dob" placeholder="Your date of birth eg:- 25/11/1996" value="<?php echo $dob ;?>" required>
</div>
<div class="col-lg-6">
<label for="education"> Recent passed degree/exam - </label>
<input type="text" class="form-control" name="education" placeholder="for example - BA/ B.Sc etc." value="<?php echo $education ;?>" >
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="mobile_no"> Mobile Number <span class="required">*</span></label>
<input type="number" class="form-control" name="mobile_no" placeholder="Enter your mobile number, eg - 8384991980" value="<?php echo $mobile_no ;?>" required>
</div>
<div class="col-lg-6">
<label for="course"> Select course <span class="required">*</span> </label>
<select class="form-control" name="course" required>
<option value="none"> --- Select one course --- </option>
<option value="IAS"> IAS </option>
<option value="RAS"> RAS </option>
<option value="Police constable"> Police constable </option>
<option value="SI"> SI </option>
<option value="Railway"> Railway </option>
<option value="REET"> REET </option>
<option value="Teacher"> Teacher </option>
<option value="Patwar"> Patwar </option>
<option value="Bank PO"> Bank PO </option>
<option value="Jr Accountant"> Jr Accountant </option>
<option value="Rajasthan police"> Rajasthan police </option>
<option value="SSC (10+2)"> SSC (10+2) </option>
</select>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="subjects"> Subjects - </label>
<input type="text" class="form-control" name="subjects" placeholder="Enter your subject you want to read" value="<?php echo $subjects ;?>" required>
</div>
<div class="col-lg-6">
<label for="timing"> Classes Timing - </label>
<input type="text" class="form-control" name="timing" placeholder="Your preferred time for coaching" value="<?php echo $timing ;?>" required>
</div>
</div><br>
<div class="row">
<div class="col-lg-6">
<label for="picture"> Upload your picture <span class="required">*</span></label>
<input type="file" class="form-control" name="picture" required>
</div>
<div class="col-lg-6">
<label for="sign"> Upload your signature <span class="required">*</span></label>
<input type="file" class="form-control" name="sign" required>
</div>
</div><br>
<div class="row">
<div class="col-md-12">
<input type="checkbox" aria-label="..." name="agree_terms" value="1"> I agree with Rules and Regulations mentioned below.<br>
<input type="checkbox" aria-label="..." name="agree_cond" value="1"> I hearbly declare that Adarsh Classes can use my pictures after my selection for advertising purpose.
</div><!-- /.col-lg-6 -->
</div><!-- /.row -->
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
</div>
</div>
</div>
</form>
The reason behind that in the input type of the HTML Page for the submit you are using <input type="button"
instead of <input type="submit". Use <input type="submit" that's work.
Example:
<input type="submit" name="" value="Submit">
Changed
<button type="text">
to
<button type="submit">
Change
button type="text" to type="button" Or input type ="submit/button"
You need to change this code:
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
with below code :
<input type="submit" name="applyAdmission" value="Submit my application form" class="btn btn-success btn-lg btn-block" />
You also need to make sure that your wrote PHP code in same file, otherwise you have to add PHP file name in action tag in below line:
<form class="form-horizontal" id="admission_form" method="post" action="" enctype="multipart/form-data">
You also have some PHP error in your code, so you have to add first line in your PHP code and then fix your PHP Fatal error.
ini_set('display_errors', '1');
I see a little syntax error and I think fixing this will fix your issue.
Change
include ("include/header.php"), include ("include/config.php");
to
include ("include/header.php");
include ("include/config.php");
To show you the syntax error, here is an example:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');
include("test.php"), include("someother.php");
The response:
Parse error: syntax error, unexpected ',' in ...\tests\includeTest.php on line 6
Incorrect input type
You should also change your button type.
Change
<button type="text"...
to
<button type="submit"...
Change <button> to <input>. Buttons can work with javascript but with only php button cant work with post data. You can not get POST data by <button>. For this you have to use <input>
Change this
<button type="text" name="submit" class="btn btn-success btn-lg btn-block" name="applyAdmission"> Submit my application form </button>
to
<input type="submit" name="applyAdmission">
Second:
Here is looking syntax error include ("include/header.php"), include ("include/config.php");
PHP requires instructions to be terminated with a semicolon at the end of each statement. Make them seperate by ; not by ,.
include ("include/header.php");
include ("include/config.php");
You can see documentation for more deep information

PHP include .tpl file without smart framework

ok so I use a PHP framework called lemonade it allows me to instead of creating PHP files for each link e.g.
http://example.com/social.php
The code allows me to call functions in our core php script which loads all the important PHP stuff and then i use .tpl files (not i just name them that i don't use the smarty framework - I name them .tpl because they are a template file)
But i seem to be having issues with one page
it sometimes loads fully and other times it's like it dies half way from loading the part that does not show is the sign up section
I have included the full code here
<div class="background">
<div class="contentarea">
<div class="Grid-cell u-size4of4 no-bg">
<div class="banner">
<div class="float_bottom cnetertext">
<center> <span class="slogen" align="center"><?=$lang["frontpage"]["banner"][0];?>
<br>
<?=$lang["frontpage"]["banner"][1];?></span>
</center>
</div>
</div>
</div>
<div class="Grid-cell u-size3of4" style="float:left;">
<div class="internal">
texthere
</div>
</div>
</div>
<script src="//<?=siteurl;?>/template/main/js/registervalidation.js"></script>
<div class="Grid-cell u-size3of4">
<div class="internal">
<h1 class="hevetics">Sign up</h1>
<p class="signuptext">It's free and always will be.</p>
<form action="/signup" name="register" method="post" class="ipetsignup" enctype="multipart/form-data" onsubmit="return registervalidation();">
<label class="half">
<input id="firstname" type="text" name="firstname" placeholder="<?=$lang["form"]["signup"]["FirstName"];?>" onchange="name();" required/>
</label>
<label class="half" style="float:right; margin-right:2%;">
<input id="lastname" type="text" name="lastname" onchange="name();" placeholder="<?=$lang["form"]["signup"]["LastName"];?>" required >
</label>
<label>
<input id="emailone" type="email" name="email" placeholder="<?=$lang["form"]["signup"]["email"];?>" onchange="checkemails();" required >
</label>
<label>
<input id="emailtwo" type="email" name="checkemail" placeholder="<?=$lang["form"]["signup"]["reemail"];?>" onchange="checkemailtwo();" required>
</label>
<label>
<input id="password" type="password" name="password" placeholder="<?=$lang["form"]["signup"]["newpassword"];?>" required>
</label>
<label class="h1">Birthday</label>
<label class="select">
<select name="day">
<option value="00" disabled selected>Day</option>
<?php
for($i=1;$i<=31; $i++)
{
$n = sprintf("%02s", $i);
echo '<option value="'.$n.'">'.$n.'</option>';
}
?>
</select>
</label>
<label class="select">
<select name="month">
<option value="00" disabled selected>Month</option>
<?php
for($i=1;$i<=12; $i++)
{
$n = sprintf("%02s", $i);
echo '<option value="'.$n.'">'.date("F",strtotime('01.'.$n.'.2001')).'</option>';
}
?>
</select>
</label>
<label class="select">
<select name="year">
<option value="00" disabled selected>Year</option>
<?php
$year = date("Y");
for($i=$year-99;$i<=$year; $i++)
{
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>
</label>
<label>
<input id="signup" type="submit" class="button" value="Sign up">
</label>
</form>
</div>
</div>
</div>
You should look at this line:
<script src="//<?=siteurl;?>/template/main/js/registervalidation.js"></script>
It seems that you forgot to use $ before variable name - it should be probably $siteurl and the other thing is if $siteurl starts with http://. If yes, this line probably should look like:
<script src="<?= $siteurl ?>/template/main/js/registervalidation.js"></script>

Using "action" in Twitter Boostrap classes

I'm a newbie programmer trying to utilize Twitter Bootstrap to build out a concept. I'm using PHP and assigning actions within HTML tags to POST data and essentially take a user through the navigation. This has been pretty straightforward when using forms: i.e. here is a snippet that does work. For example, for this snippet of HTML:
<form action="?viewnotes" method="post">
<input type="hidden" name="id" value="<?php htmlout($note['id']); ?>">
</form>
It successfully triggers the following if statement in my index.php:
if (isset($_GET['viewnotes']))
However, I'm trying to do the same thing in my registration page, using a Twitter Bootstrap class for buttons. Here is the HTML:
<a class="btn btn-primary btn-large" action="?register">Sign Up Free!»</a></p>
The PHP code is:
if (isset($_GET['register']))
{
include 'register.html.php';
}
Clicking on the Sign Up button is not invoking the PHP code. If I hard code the URL it works, but then I have a similar issue on the register.html.php page. HTML on the register page has:
<form class="form-horizontal" action="?storeuser" method="post">
<fieldset>
<legend>It's quick and easy...</legend>
<div class="control-group">
<label class="control-label">First Name</label>
<div class="controls">
<input type="text" name="fname" class="input-xlarge" id="fname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="lname">Last Name</label>
<div class="controls">
<input type="text" name="lname" class="input-xlarge" id="lname">
</div>
</div>
<div class="control-group">
<label class="control-label" name="email">Email Address</label>
<div class="controls">
<input type="text" name="email" class="input-xlarge" id="email">
</div>
</div>
<div class="control-group">
<label class="control-label" name="password">Password</label>
<div class="controls">
<input type="password" name="password" class="input-xlarge" id="password">
</div>
</div>
</fieldset>
<button type="submit" name="action" class="btn btn-primary btn-large">Complete Registration</button>
</form>
However, when clicking on the button, the index file does not trigger the following, which would store the fields into the DB.
if (isset($_GET['storeuser']))
If I hardcode the URL to register.html.php, then the resulting URL looks like localhost/register.html.php?storeuser instead of localhost/?storeuser. I'm not sure if that's affecting the behavior here.
Thank you for the help!
I think you're approaching this the wrong way, and it's not Twitter Bootstrap's fault.
Usually, you'd use POST, not GET, to handle user registrations. Your form would look like this:
<form action="register.php" method="post">
<!-- your form -->
<fieldset>
<input type="submit" name="register" value="Register" class="btn btn-primary" />
</fieldset>
</form>
You can then build register.php as follows:
<?php
if (isset($_POST['register'])) {
// handle user registration
}
// display form
?>
This will display the form when the user visits register.php, but will try and process the user registration first if the form's been POSTed.
try passing a value with your GET variable
<form action="?viewnotes=1" method="post">

Categories