I am trying to execute this html form code, the php script is not executing properly. Can you point out the problems?
<form action="form.php" method="post">
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
php script
<?php
if (isset($_POST['submit']))
{
$k=0;
foreach($_POST['languages'] as $language) {
echo $language = htmlentities($language);
echo $title = $_POST['titles'][$k];
$k++;
}
}
?>
HTML
<form action="form.php" method="post">
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<p>
<input type="text" name="titles[]" /><br />
<textarea name="languages[]" ></textarea><br />
</p>
<input type="submit" name="submit" id="submit" value="Submit">
</form>
PHP
<?php
if (isset($_POST['submit']))
{
foreach($_POST['languages'] as $key => $language) {
echo $language = htmlentities($language);
echo " -- ";
echo $title = $_POST['titles'][$key];
echo "<br/>";
}
}
?>
Related
I have a site where I make a payment, a bill is created through it, but the problem is that I can not use $ _POST twice in one, and this example:
<? if (isset($_POST['submit'])) { ?>
<form action="" method="POST" >
<input name="invoice" value="" type="text" />
<input name="pay" value="Pay Now" type="submit" />
</form>
<? } if (isset($_POST['pay'])) {
// MY QUERY HERE
// HEADERS HERE
} else { ?>
<form action="" method="POST" >
<input name="info" value="" type="text" />
<input name="submit" value="Submit" type="submit" />
</form>
<? } ?>
Try this.
Kindly check the code for comment.
<?
if (isset($_POST['submit'])) {
$info = $_POST['info'];
// use echo to display second form
echo '
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
<!-- // Note the action value, it's for post back. This allow you to post back to the current page -->
<!-- This is to keep the record passed from the first form -->
<input name="info" value="'. $info .'" type="hidden" />
<input name="invoice" value="" type="text" />
<input name="pay" value="Pay Now" type="submit" />
</form>';
} else if (isset($_POST['pay'])) {
// MY QUERY HERE
} else {
// Note the action value, it's for post back. This allow you to post back to the current page
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" >
<input name="info" value="" type="text" />
<input name="submit" value="Submit" type="submit" />
</form>
}
?>
Not the prettiest way to do this but to achieve your result try this...
<?php if (isset($_POST['submit'])) { ?>
<form action="" method="POST" >
<input name="invoice" value="" type="text" />
<input name="pay" value="Pay Now" type="submit" />
</form>
<?php } elseif (isset($_POST['pay'])) {
// Perform query here
} else { ?>
<form action="" method="POST" >
<input name="info" value="" type="text" />
<input name="submit" value="Submit" type="submit" />
</form>
<?php } ?>
Using php, i created an edit option that basically lets u change the data in the record. However, after clicking on submit, the data doesn't get saved on the table nor do i get any errors.. I am quite confused. Here r my codes:
<html>
<body>
<?php
include('db.php');
if (isset($_GET['Id'])) {
$Id=$_GET['Id'];
if (isset($_POST['submit'])) {
$Fname=$_POST['Fname'];
$Lname=$_POST['Lname'];
$Age=$_POST['Age'];
$Nationality=$_POST['Nationality'];
$PhoneNumber=$_POST['PhoneNumber'];
$Email=$_POST['Email'];
$query3=mysql_query("UPDATE `students` SET `Fname`='$Fname',`Lname`='$Lname',`Age`='$Age',`Nationality`='$Nationality',`PhoneNumber`='$PhoneNumber',`Email`='$Email' WHERE `Id`='$Id'");
if($query3) {
header('location:index1.php');
}
}
$query1=mysql_query("select * from students where Id='$Id'");
$query2=mysql_fetch_array($query1);
?>
<form method="post" action="">
First Name:<input type="text" name="name" value="<?php echo $query2['Fname']; ?>" /><br />
Last Name:<input type="text" name="name" value="<?php echo $query2['Lname']; ?>" /><br />
Age:<input type="text" name="age" value="<?php echo $query2['Age']; ?>" /><br />
Nationality:<input type="text" name="name" value="<?php echo $query2['Nationality']; ?>" /><br />
Phone Number:<input type="text" name="name" value="<?php echo $query2['PhoneNumber']; ?>" /><br />
Email:<input type="text" name="name" value="<?php echo $query2['Email']; ?>" /><br />
<br />
<input type="submit" name="submit" value="update" />
</form>
<?php
}
?>
</body>
</html>
I have two text boxes and one button. I want when i will type any value in 1st textbox and click on a button the value which i'll type in 1st text box should be the value of 2nd text box. And i was using this code. Can some one help me on this?
<?php
if(isset($_POST['sum']))
{
$v1=$_POST['abc'];
if($v1=="vivek")
{
echo "welcome Mr.".$v1;
}
else
{
echo "Unauthorised User Mr. ".$v1;
}
}
?>
<html>
<body>
<form method="post" action="">
<p>Name:     
<input type="text" name="abc" value=""/>  
</br></br>
Passed Value: <input type="text" name="xyz" value="<?php echo $v1;?>"/>
</p>
<p>
<input type="submit" name="sum" value=" Submit "/>
</p>
</form>
</body>
</html>
try this one.
<form method="post" action="">
<p>Name:     
<input type="text" name="abc" value=""/>  
</br></br>
Passed Value: <input type="text" name="xyz" value="<?php if(isset($_POST['abc'])) { echo $_POST['abc']; } ?>"/>
</p>
<p>
<input type="submit" name="sum" value=" Submit "/>
</p>
</form>
Passed Value:
<input type="text" name="xyz" value="<?php
if(isset($_POST['abc']))
echo htmlentities($_POST['abc'],ENT_QUOTES);
?>"/>
This should do it :)
Try this code.
<script type="text/javascript">
function sub() {
document.getElementById('xyz').value = document.getElementById('abc').value;
}
</script>
<form>
<label>Amonut</label>
<input type="text" name="abc" onkeyup="sub();" id="abc" />
<br /><br />
<label>Discount</label>
<input type="text" name="xyz" id="xyz" />
<input type="submit" name="sum" value=" Submit "/>
</form>
<script type="text/javascript">
function sub() {
document.getElementById('xyz').value = document.getElementById('abc').value;
}
</script>
<form onsubmit="sub();">
<label>Amonut</label>
<input type="text" name="abc" id="abc" />
<br /><br />
<label>Discount</label>
<input type="text" name="xyz" id="xyz" />
<input type="submit" name="sum" value=" Submit "/>
</form>
I think you want this.
Try this code
$v1='';
if(isset($_POST['sum']))
{
if($v1=="vivek")
{
echo "welcome Mr.".$v1;
$v1=$_POST['abc'];
}
else
{
echo "Unauthorised User Mr. ".$v1;
}
}
I can't seem to figure out how to make this script write data to the section of the file. Here is an excerpt of the code that applies:
$file = $url.'.php';
if (!$file_handle = fopen($file,"a+"))
{
echo $lang['cannot_open_file'];
}
if (!fwrite($file_handle,stripslashes(html_entity_decode($data))))
{
echo $lang['file_is_not_writable'];
}
fclose($file_handle);
echo ($lang['success']);
echo ('<meta http-equiv="Refresh" content="4;url='.$url.'.php" />');
}
}
?>
<form action="<?php echo $url;?>.php" method="post">
<?php echo $lang['name']?> <span style="font-weight:100;">(<?php echo $lang['required']?>)</span>:<br />
<input class="textfield" type="text" name="name" value="" /><br />
<?php echo $lang['website']?> <span style="font-weight:100;">(<?php echo $lang['without_http'];?>)</span>:<br />
<input class="textfield" type="text" name="site" value="" /><br />
<?php echo $lang['message']?>:<br />
<textarea class="textarea" rows="2" cols="25" name="message"></textarea><br />
<img src="captcha-image.php" alt="Image verification" /> <br />
<?php echo $lang['value_from_the_image'];?>:<br />
<input class="textfield" type="text" name="img_ver" value="" /><br />
<input type="reset" name="reset" value="<?php echo $lang['reset'];?>" />
<input type="submit" name="send" value="<?php echo $lang['send'];?>" />
</form>
<hr>
<h3>Comments:</h3>
<!--comments -->
<?php include('../templates/footer.php'); ?>
Would anyone mind helping me out on this one? It would be much appreciated.
Use file get contens to retrieve the contens first.
Then use preg_replace to find where or what you want to be replaced.
Then rewrite the file with the new content.
Here is my form element
<form method="post" id="add_facility_form" class="blocks" action="<?php echo base_url(); ?>index.php/facility_management/add">
<div id="contact_wrapper">
<p>Name: </p>
<input type="text" class="inp-form" name="contact_name[]" />
<p>Department: </p>
<input type="text" class="inp-form" name="department_name[]" />
<p>Email: </p>
<input type="text" class="inp-form" name="contact_email[]" />
<p>Phone number: </p>
<input type="text" class="inp-form" name="contact_phone_number[]" />
<p>Fax number: </p>
<input type="text" class="inp-form" name="contact_fax_number[]" />
</div>
<img width="21" height="21" alt="" src="<?php echo base_url() ?>images/forms/icon_plus.gif" class="add_new_contact add_new" />
</form>
when I click on the image it clones the whole div.I want to post the data but the problem is that it posts only first div's information.How can I post the cloned element's data?
here is jquery function and php
$(".add_new_contact").click(function () {
$("#contact_wrapper").clone().attr('id','contact_wrapper'+new Date().getTime()).appendTo($(this).parent());
return false;
});
PHP
$contact_name = $this->input->post('contact_name');
$department = $this->input->post('department_name');
$contact_phone = $this->input->post('contact_phone_number');
$contact_fax = $this->input->post('contact_fax_number');
$contact_email = $this->input->post('contact_email');
$contact_count = count($contact_name);
<?php
$array=$_POST['contact_name'];
foreach($array as $name)
{
echo "Name is ".$name."<br>";
}
$array=$_POST['contact_email'];
foreach($array as $email)
{
echo "email is ".$email."<br>";
}
?>