Firstable, hello everyone. I have issue about the $_POST method, when I write this code block;
if (isset($_POST['menuduzenle'])) {
$menu_id=$_POST['menu_id']; //It didn't turn with value in mysql
$ayarguncelle=mysql_query("update menuler set menu_ad='".$_POST['menu_ad']."',menu_link='".$_POST['menu_link']."'where menu_id='$menu_id'");
if(mysql_affected_rows())
{
header("Location:../menuleriduzenle.php?guncelleme=basarili&menu_id=$menu_id");
}else{
header("Location:../menuleriduzenle.php?guncelleme=basarisiz&menu_id=$menu_id");}
}
menu_id turns emty, what I need to do for solve this?
and here it's html code
form
<form action="network/islem.php" method="POST">
<div class="col-md-12">
<div class="form-group col-md-9">
<label>Menu Adı: </label>
<input class="form-control" name="menu_ad" value="<?php echo $menucek['menu_ad']; ?>" />
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-9">
<label>Menu Link: </label>
<input class="form-control" name="menu_link" value="<?php echo $menucek['menu_link']; ?>" />
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-6">
<input class="btn btn-primary col-md-3" type="submit" name="menuduzenle" value="Edit Menu">
</div>
</form>
and
<td><button class="btn btn-primary col-md-12">Edit</button></td>
You not send any one input with name 'menu_id' on your from.
<form action="network/islem.php" method="POST">
<div class="col-md-12">
<div class="form-group col-md-9">
<label>Menu Adı: </label>
<input class="form-control" name="menu_ad" value="<?php echo $menucek['menu_ad']; ?>" />
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-9">
<label>Menu Link: </label>
<input class="form-control" name="menu_link" value="<?php echo $menucek['menu_link']; ?>" />
</div>
</div>
<div class="col-md-12">
<div class="form-group col-md-6">
<input class="btn btn-primary col-md-3" type="submit" name="menuduzenle" value="Edit Menu">
</div>
<input type="hidden" name="menu_id" value="<?php echo $_GET['menu_id'] ?>" />
</form>
You input name "menu_ad" would be "menu_id" or fault other input with name "menu_id" on you sample.
Related
I am trying to create a short code for html form. because I want to use this multiple time in my word-press page.
I have no idea how to do this . if any help please let help me
<form action="<?php echo get_page_link(2599) ?>" method="POST" >
<input type='hidden' name='page_id' value='2599'>
<div class="row">
<div class="form-group col-sm-3 col-md-2" id="bgform_text2">
<h4>SEARCH</h4>
<p>For Your Favourite Place</p>
</div>
<div class="form-group col-sm-5 col-md-2">
<label>Where to ? </label>
<input type="text" name="names" class="input-text full-width" placeholder="start typing here....">
</div>
<div class="form-group col-sm-5 col-md-4">
<div class="row">
<div class="col-xs-6">
<label>Arrive </label>
<div class="controls">
<input type="text" name="arive_time" id="departing">
</div>
</div>
<div class="col-xs-6">
<label>Departs </label>
<div class="controls">
<input type="text" name="depart_time" id="returning">
</div>
</div>
</div>
</div>
<div class="form-group col-sm-9 col-md-2">
<label>Sleeps </label>
<div class="controls">
<i class="fa fa-sort"></i>
<select name="sleeps">
<option value="" disabled="" selected=""></option>
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></option>
</select>
</div>
</div>
<div class="form-group col-sm-3 col-md-2">
<input type="submit" value="submit" name="submit_btn" class="button">
</div>
</div>
</form>
Try this.
<?php
function my_shortcode(){
$pagelink = get_page_link(2599);
return '<form action="'.$pagelink.'" method="POST" >
<input type="hidden" name="page_id" value="2599">
<div class="row">
<div class="form-group col-sm-3 col-md-2" id="bgform_text2">
<h4>SEARCH</h4>
<p>For Your Favourite Place</p>
</div>
<div class="form-group col-sm-5 col-md-2">
<label>Where to ? </label>
<input type="text" name="names" class="input-text full-width" placeholder="start typing here....">
</div>
<div class="form-group col-sm-5 col-md-4">
<div class="row">
<div class="col-xs-6">
<label>Arrive </label>
<div class="controls">
<input type="text" name="arive_time" id="departing">
</div>
</div>
<div class="col-xs-6">
<label>Departs </label>
<div class="controls">
<input type="text" name="depart_time" id="returning">
</div>
</div>
</div>
</div>
<div class="form-group col-sm-9 col-md-2">
<label>Sleeps </label>
<div class="controls">
<i class="fa fa-sort"></i>
<select name="sleeps">
<option value="" disabled="" selected=""></option>
<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></option>
</select>
</div>
</div>
<div class="form-group col-sm-3 col-md-2">
<input type="submit" value="submit" name="submit_btn" class="button">
</div>
</div>
</form>';
}
add_shortcode('my_shortcode_name','my_shortcode');
?>
you can use this shortcode in your page
<?php echo do_shortcode('[my_shortcode_name]');?>
I think you are saying that you do not want to copy-paste the exact same code on multiple places inside your project, PHP has an include control structure method to take any file and use the contents on run-time.
Your code could eventually look something like this:
# form definition inside the main page that needs the form
<form action="<?php echo get_page_link(2599) ?>" method="POST" >
# include the template
<?php include('template.php') ?>
</form>
# template.php contains the html form
<input type='hidden' name='page_id' value='2599'>
UPDATE.php
<?php
include('DB.php');
if(isset($_GET['id'])){
$id=$_GET['id'];
if(isset($_POST['update'])){
$name=mysqli_real_escape_string($link,$_POST["ename"]);
$email=mysqli_real_escape_string($link,$_POST["eemail"]);
$enpassword=mysqli_real_escape_string($link,$_POST["epassword"]);
$dateofbirth=mysqli_real_escape_string($link,$_POST["edateofbirth"]);
$mobile=mysqli_real_escape_string($link,$_POST["emobile"]);
$presentaddress=mysqli_real_escape_string($link,$_POST["epresentaddress"] );
$drivinglicense=mysqli_real_escape_string($link,$_POST["edrivinglicense"]);
if(mysqli_query("UPDATE hrmsinfo SET emp_name=$name,emp_email=$email,emp_password=$enpassword,emp_dob=$dateofbirth,emp_phno=$mobile,emp_address=$presentaddress,emp_proof=$drivinglicense WHERE emp_id='$id'")){
$msg="Successfully Updated!!";
header('Location:VIEW.php');
}
else{
$msg="Unsucessfull!!";
}
}
} //update ends here
?>
When ever i try to execute this update code with following edit code it displays blank page help me with it
The below is edit code which executes perfectly but update doesnt work at all help me where am i stuck
<?php
//error_reporting(0);
include("DB.php");
if(isset($_GET['id'])){
$id=$_GET['id'];
$sql="SELECT * FROM hrmsinfo WHERE emp_id='$id'";
$sqll=mysqli_query($link,$sql);
while($profile=mysqli_fetch_array($sqll)){
$username=$profile['emp_name'];
$usermail=$profile['emp_email'];
$userdob=$profile['emp_dob'];
$usermobile=$profile['emp_phno'];
$useraddress=$profile['emp_address'];
$userproof=$profile['emp_proof'];
?>
<div>
<form action="UPDATE.php" method="post" name="insertform">
<div class="form-group">
<div class="row">
<div class="col-xs-3">Name:</div>
<div class="col-xs-4"><input type="text" class="form-control" name="ename" placeholder="Enter Name" value="<?php echo $username; ?>" id="inputid"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Email:</div>
<div class="col-xs-4"><input type="text" class="form-control" name="eemail" placeholder="Enter Email" value="<?php echo $usermail; ?>" id="inputid"></div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Password:</div>
<div class="col-xs-3"><input type="password" class="form-control" name="epassword" id="inputid" placeholder="Enter Password" id='input_id'></div>
<div class="col-xs-3"><input type="password" class="form-control" name="epassword" id="inputid" placeholder="Re-Enter Password" id='input_id'></div>
<div class="col-xs-3">
<div class="checkbox"><input type="checkbox"> Auto Generate</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Date Of Birth:</div>
<div class="col-xs-5">
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="date" class="form-control pull-right" name="edateofbirth" value="<?php echo $userdob; ?>" id="inputid">
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Mobile Number:</div>
<div class="col-xs-5">
<input type="text" class="form-control" placeholder="Enter Mobile" name="emobile" value="<?php echo $usermobile; ?>" id="inputid">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Address:</div>
<div class="col-xs-5">
<textarea class="form-control" rows="3" placeholder="Enter Address" name="epresentaddress" value="<?php echo $useraddress; ?>" id="inputid"></textarea>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3">Proof:</div>
<div class="col-xs-5">
<input type="text" class="form-control" placeholder="Enter Proof" name="edrivinglicense" value="<?php echo $userproof; ?>" id="inputid">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-3"></div>
<div class="col-xs-5">
<input type="submit" name="update" value="Update" id="inputid1" />
</div>
</div>
</div>
</form>
</div>
<?php } } ?>
Please help me with proper guidance where am i stuck here or i am making mistake
as per your code you put one condition i.e.
if(isset($_GET['id']))
{
.....
}
but in html form you are not pass any id field add id field and try your condition will verify and update will work.
just add one field like below.. remaining is same.
<form action="UPDATE.php?id=<?php echo $id; ?>" method="post" name="insertform">
<input type="hidden" name="id" value="<?php echo $id; ?>" >
...............
.................
</form>
Note: In HTML page id of field should be unique.
I have a simple Login page where I show a error message on failed authentication. I have a div with some classes applied , and inside it I display the error message through a <label.../>.
Now when the page is loaded for the first time, there is obviously no error message and thus there is an blank space left.
What I want is if there is no error message, the div should occupy no space or should be hidden and should only show if there is any text(error message) inside the div.
Here is my HTML :
<form id="login-form" action="authenticate.php" method="post" role="form" style="display: block;">
<div class="form-group">
<input type="text" name="login_email" id="login_email" tabindex="1" class="form-control" placeholder="Email" value="">
</div>
<div class="form-group">
<input type="password" name="login_password" id="login_password" tabindex="2" class="form-control" placeholder="Password">
</div>
<div class="form-group text-center">
<label style="color:red"><?php if(isset($error)) echo $error; ?></label>
</div>
<div class="form-group text-center">
<input type="checkbox" tabindex="3" class="" name="remember" id="remember">
<label for="remember"> Remember Me</label>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="login-submit" id="login-submit" tabindex="4" class="form-control btn btn-login" value="Log In">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<div class="text-center">
Forgot Password?
</div>
</div>
</div>
</div>
</form>
PHP code :
<?php
if(isset($_GET['login_error'])){
if($_GET['login_error']== 'true'){
$error = "Email and/or Password was incorrect! Please try again!";
}
}
?>
Change it so that it calls out all the HTML in the php function. Like this
<?php
if(isset($_GET['login_error'])){
if($_GET['login_error']== 'true'){
$error = '<div class="form-group text-center">';
$error .= '<label style="color:red">Email and/or Password was incorrect! Please try again!</label>';
$error .= '</div>';
}
}
?>
<form id="login-form" action="authenticate.php" method="post" role="form" style="display: block;">
<div class="form-group">
<input type="text" name="login_email" id="login_email" tabindex="1" class="form-control" placeholder="Email" value="">
</div>
<div class="form-group">
<input type="password" name="login_password" id="login_password" tabindex="2" class="form-control" placeholder="Password">
</div>
<!-- ERROR MESSAGE IS HERE -->
<?php if(isset($error)) echo $error; ?>
<div class="form-group text-center">
<input type="checkbox" tabindex="3" class="" name="remember" id="remember">
<label for="remember"> Remember Me</label>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="login-submit" id="login-submit" tabindex="4" class="form-control btn btn-login" value="Log In">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<div class="text-center">
Forgot Password?
</div>
</div>
</div>
</div>
</form>
Change the content of the if statement to include the entire element, like so:
<?php if(isset($error)) { ?>
<div class="form-group text-center">
<label style="color:red"><?php echo $error; ?></label>
</div>
<?php } ?>
I have a form like below:
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].title" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0].isbn" placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0].price" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="button" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
How to get value of this form in php $_Post because the name of fields are like <br/>name="book[0].title"**<br/>?
and there are many dynamic different name input fields.
If you can use for multiple books then use book[0].title like below,
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
If you want to use same form then change name of all textbox like,
<form id="bookForm" method="post" class="form-horizontal">
<div class="form-group">
<label class="col-xs-1 control-label">Book</label>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][title]" placeholder="Title" />
</div>
<div class="col-xs-4">
<input type="text" class="form-control" name="book[0][isbn]." placeholder="ISBN" />
</div>
<div class="col-xs-2">
<input type="text" class="form-control" name="book[0][price]" placeholder="Price" />
</div>
<div class="col-xs-1">
<button type="submit" class="btn btn-default addButton"><i class="fa fa-plus"></i></button>
</div>
</div>
And get value of this form like echo $_POST['book'][0]['title'];
I hope this can help you.
You need to change name attribute,
<div class="col-xs-4">
<input type="text" class="form-control" name="book_title" placeholder="Title" />
</div>
book[0].title, this is not valid name.
You can now get something like this,
$_POST['book_title']
Here's a form I have. I want to post the form entries to the same page and then do something else with it. However, echoing the values doesn't seem to be working. What am I doing wrong?
Here's the HTML part:
<div class="well">
<form name="myform" class="form-horizontal" id="form" onsubmit="return validateForm(this);" action="my.php" method="post">
<div class="control-group input-append">
<label for="text" class="control-label">Field1</label>
<div class="controls">
<div class="left">
<input id="Field1" name="Field1" type="text"/>
</div>
</div>
</div>
<br>
<div class="control-group input-append">
<label for="passwd" class="control-label">Field2</label>
<div class="controls">
<div class="left1">
<input id="Field2" name="Field2" type="password" />
</div>
</div>
</div>
<br>
<div class="control-group input-append">
<label for="passwd" class="control-label">Field3</label>
<div class="controls">
<div class="left1">
<input id="Field3" name="Field3" type="password"/>
</div>
</div>
</div>
<br>
<div class="control-group input-append">
<label for="select" class="control-label">Field4</label>
<div class="controls">
<div class="left1">
<select class="form-control" name="Field4">
<option value="OP1">OP1</option>
<option value="OP2">OP2</option>
<option value="OP3">OP3</option>
<option value="OP4">OP4</option>
</select>
</div>
</div>
</div>
<br>
<div class="control-group input-append">
<label for="text" class="control-label">Field5</label>
<div class="controls">
<div class="left">
<input type="Field5" id="Field5" name="type"/>
</div>
</div>
</div>
<br>
<div class="control-group input-append">
<label for="text" class="control-label">Field6</label>
<div class="controls">
<div class="left">
<input type="text" id="Field6" name="Field6"/>
</div>
</div>
</div>
<br>
<div class="control-group">
<div class="controls">
<div class="left1">
<input type="submit" class="btn btn-success"/>
</div>
</div>
</div>
</form>
</div>
PHP part:
<?php
if (isset($_POST['submit']))
{
echo $_POST['name'];
} else {?>
<?php;}?>
There is no field with the name $_POST['name'], though you have fields with numbered names, e.g. $_POST['Fields3'].
To debug the form request print out the whole $_POST array first:
var_dump( $_POST );
The type of an input is not the same as it's name!
Another option is to replace
if (isset($_POST['submit']))
with:
if($_SERVER['REQUEST_METHOD'] == 'POST')
Replace <input type="submit" class="btn btn-success"/>
to <input type="submit" name="submit" class="btn btn-success"/>
The problem is here:
if (isset($_POST['submit']))
Your submit button
<input type="submit" class="btn btn-success" />
does not have a value, nor does it have a name. Post works with these attributes:
$_POST['<name>'] = <value>
change your input to
<input type="submit" name="submit" value="Submit" class="btn btn-success" />
Btw, nice to see people still coding in XHTML. If you are using HTML 5, you should not end your non-closing tags with a slash ... />.