I am working on one project in which there is one form filled by user and that value displayed in another page. All data I get in another page but image can't display on that page only image name is displayed. I want to display image so how can I do this?
page1
<form action="save.php" class="contact-form" method="post" name="inputname">
<table>
<tr>
<td class="label">Name:</td>
<td><input type="text" class="input-text" name="pname" /></td>
</tr>
<tr>
<td class="label">City:</td>
<td><input type="text" class="input-text" name="pcity" /></td>
</tr>
<tr>
<td class="label">Country:</td>
<td><input type="text" class="input-text" name="pcountry" /></td>
</tr>
<tr>
<td class="label">Email:</td>
<td><input type="text" class="input-text" name="pemail" /></td>
</tr>
<tr>
<td class="label">Upload Your Photo:</td>
<td><input type="file" accept="image/jpg,image/gif" class="input-text" name="pphoto"/></td>
</tr>
page 2 save.php
mysql_connect("localhost","root","");
mysql_select_db("my_db");
$p_name=$_POST['pname'];
$p_city=$_POST['pcity'];
$p_country=$_POST['pcountry'];
$p_email=$_POST['pemail'];
$p_photo=$_POST['pphoto'];
<table>
<ul>
<tr>
<td><li class="image"><img src="<? echo $p_photo; ?>" /></li></td>
<li class="text">
<td class="label">
Name: <? echo $p_name; ?></br>
City: <? echo $p_city; ?></br>
Country: <? echo $p_country; ?></br>
E-Mail: <? echo $p_email; ?></br>
</td>
</li>
</tr>
</ul>
</table>
If you upload image as file then you should work with $_FILES array. And you should save uploaded image first.
#$file = fopen($_FILES['file'] ['tmp_name'], "r");
#$image = addslashes(fread($file, filesize($_FILES['file']['tmp_name'])));
Use your file name instead of 'file'.
Related
I have two PHP pages from one I input the year and after submitting year value goes in next page via form input as in image enter image description here
image just after clicking the submit button of first page
code for the first page is
<div class="col-sm-12" style="background-color:lavender;">
<form method="post" action="next.php">
<table id="emi" width="100%">
<tr>
<td width="100%">
<div align="center"><b>
<h3> Enter Fiancial Information:</h3>
</b> </td>
<table width="100%" border="0" id="emi">
<tr>
<td><strong>First Calender Year of DATA! ( i.e. 1999 ) </strong></td>
<td><input type="text" class="form-control" placeholder="Enter the First Assesment Year" name="year" pattern="\d*" maxlength="4"></td>
<td><input type="submit" value="Go" name="submit"class="btn btn-success"></td>
</tr></table>
</table></form>
</table>
I have two PHP pages from one I input the year and after submitting year value goes in next page via form input as in image enter image description here
In next page I have one form input also and after input the values in next page and after clicking compute button the value of year which we call from page one disappear. As shown in image
Image after clicking the compute button on next.php
code for the next.php which is called after the first page is
<?php
error_reporting(0);
$year=$_REQUEST['year'];
$x=$year+1;
$y=$x+1;
?>
<table id="emi"width="100%">
<tr>
<td width="40%"><strong>INCOME STATEMENT
</strong></td>
<td width="20%"><strong> 31-03-<?php echo $year;?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $x?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $y?></strong></td>
</tr>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<table id="emi" width="100%">
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a1" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a2" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
</table>
<table id="emi" width="100%">
<tr>
<td colspan="3">
<center>
<input type="submit" value="Compute" name="submit"class="btn btn-success"></center>
</td>
</tr>
</table>
</form>
<?php
error_reporting(0);
if($_SERVER['REQUEST_METHOD']=="POST"){
$a=$_POST['a1'];
$b=$_POST['a2'];
echo $a+$b;
}?>
I have only call the value of year then plus one in it as you see 2000 2001 2002 to next page and when I enter the value of sundry it disappears the value of year and we get only plus means value of year become 0 after clicking the compute button.
When you submit the form on the second page via your "Compute" button $_REQUEST['year'] is no longer set because it was from the previous request.
One way around this would be to add a hidden input field which stores the $_REQUEST['year'] value for the next request.
Something like this should work:
<input type="hidden" name="year" value="<? echo $_REQUEST['year']; ?>">
replace your next.php with this code
<?php
error_reporting(0);
$year=$_REQUEST['year'];
if($year==null){
$year=$_POST['year'];
}
$x=$year+1;
$y=$x+1;
?>
<table id="emi"width="100%">
<tr>
<td width="40%"><strong>INCOME STATEMENT
</strong></td>
<td width="20%"><strong> 31-03-<?php echo $year;?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $x?></strong></td>
<td width="20%"><strong> 31-03-<?php echo $y?></strong></td>
</tr>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<table id="emi" width="100%">
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a1" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
<tr>
<td width="40%"><strong>Sundray Creditors</strong></td>
<td width="20%"><input type="text" name="a2" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="suncre" size="8" class="form-control"></td>
<td width="20%"><input type="text" name="inv" size="8" class="form-control"></td>
</tr>
</table>
<table id="emi" width="100%">
<tr>
<td colspan="3">
<center>
<input type="hidden" id="year" name="year" value="<?php echo($year);?>">
<input type="submit" value="Compute" name="submit"class="btn btn-success"></center>
</td>
</tr>
</table>
</form>
<?php
error_reporting(0);
if($_SERVER['REQUEST_METHOD']=="POST"){
$a=$_POST['a1'];
$b=$_POST['a2'];
echo $a+$b;
}?>
I have two websites. I would like to simply echo message on the second page (example: echo "FOO") at the commented place on the first page. How can I solve it?
Second page: msg.html
echo "foo";
First page: index.php
<form id="form_1" method="post" action="dbconn.php">
<table id="table_form">
<tr>
<td colspan="2" id="table_main">Jelentkezés</td>
</tr>
<tr>
<td>Név</td>
<td><input class="text_box" type="text" name="nev" placeholder="Név"></td>
</tr>
<tr>
<td>E-mail cím</td>
<td id="bubble_pos"><input class="text_box" type="text" name="email" placeholder="Email cím">
<div id="bubble_box">
<div class="bubble"><?php echo ///////////;?></div>
</div>
</td>
</tr>
I have a client with a website made in php who is newly hosted with us. I have no idea why, but after transferring his website on our servers, the Contact us form's php code is visible to the public. I have no idea why that is, and would appreciate to be directed towards a solution.
(Sorry about the ugly display)
example of what is happening on the live website
<?php
if ($error) error_message($error);
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<form name="form1" method="post" action="index.php?go=sendcontact#chkerr">
<tr valign="top">
<td class="formfield1" width="30%">Name</td>
<td style="padding-bottom: 5px;" width="70%"><input name="name" type="text" size="25" maxlength="50" value="<? echo $_POST["name"] ?>"></td>
</tr>
<tr valign="top">
<td class="formfield1">Phone number</td>
<td style="padding-bottom: 5px;"><input name="phone" type="text" size="25" maxlength="50" value="<? echo $_POST["phone"] ?>"></td>
</tr>
<tr valign="top">
<td class="formfield1">Email address</td>
<td style="padding-bottom: 5px;"><input name="email" type="text" size="25" maxlength="100" value="<? echo $_POST["email"] ?>"></td>
</tr>
<tr valign="top">
<td class="formfield1">How do you prefer to be contacted?</td>
<td style="padding-bottom: 5px;"><input name="contactpref" type="radio" value="Phone"<? if ($POSTED["contactpref"] == "Phone") echo " checked"; ?>> Phone <input name="contactpref" type="radio" value="Email"<? if ($POSTED["contactpref"] == "Email") echo " checked"; ?>> Email</td>
</tr>
<tr valign="top">
<td class="formfield1">How did you find out about Bella Vista?</td>
<td style="padding-bottom: 5px;"><input name="heardfrom" type="text" size="25" maxlength="50" value="<? echo $_POST["heardfrom"] ?>"></td>
</tr>
<tr valign="top">
<td class="formfield1">Please tell us what you're looking for, or if you have any questions.</td>
<td style="padding-bottom: 5px;"><textarea name="question" cols="40" rows="8"><? echo $_POST["question"] ?></textarea></td>
</tr>
<!--
<tr valign="top">
<td class="formfield1"> </td>
<td style="padding-bottom: 5px;">
<div>Please enter the code in the text field below</div>
<div><img src="captcha.php" width="230" height="45" alt="Captcha code" /></div>
<div><input type="text" name="frm_cap" size="25" value="" /></div>
</td>
</tr>
-->
<tr valign="top">
<td class="formfield1"><!-- Verification --></td>
<td style="padding-bottom: 5px;"><input type="submit" name="Submit" value="Send"></td>
</tr>
</form>
</table>
<?php
You have to replace all the short PHP opening tags <?with the long version : <?php
Or you can take a look at this : How to enable PHP short tags?
some of my code in addUser.php it pure html
addUser.php
<form action="process/addNewUser.php" method="POST" id="userForm">
<table width="79%" border="0" cellspacing="6" cellpadding="1"
class="tabcont">
<tr>
<td width="47%" align="right">Title:</td>
<td width="53%">
<select name="title"><option value='0'>- - select - -</option>
</select>
</td>
</tr>
<tr>
<td width="47%" align="right">
First Name:</td>
<td width="53%"><input type="text" id="firstname" name="firstName" class="required" /></td>
</tr>
<tr>
<td align="right">Middle Name:</td>
<td><input type="text" id="middlename" name="middleName" class="name" /></td>
</tr>
<tr>
<td align="right">Password:</td>
<td><input name="password" value="" readonly="readonly"
id="password" class="required" " /></td>
</tr>
<tr>
<td align="right" colspan="2">
<input name="addNewUser" type="submit" class="submit" id="submit" value="Submit" />
</td>
</tr>
</table>
</form>
addNewUser.php
Here i am doing validations and displaying error messages and if it is success sending him to another page.
But i want to show an error message on addUser.php instead of validations page. Please give me a sample code how i can do it.
addNewUser.php
Add the message in the session
$_SESSION["ErrorMsg"]="Name already exists";
And in your addUser.php , you put the following code in the place you need to show the msg :
if($_SESSION["ErrorMsg"])
{
echo $_SESSION["ErrorMsg"];
$_SESSION["ErrorMsg"]="";
}
I wonder whether someone may be able to help me please.
I've put together a form and php code (below) that allows an administrator to search for member records from a mysql database using the email address as the search criteria.
HTML Form
<form name="memberpasswordresetform" id="memberpasswordresetform" method="post" action="search.php">
<div class="container">
<p align="justify">Member Details </p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="26%" height="25"><strong>Email Address </strong></td>
<td width="4%"> </td>
<td width="70%"><input name="email" type="email" id="email" size="50" /></td>
</tr>
<tr>
<td height="25"><strong>Confirm Email Address </strong></td>
<td> </td>
<td><input name="conf_email" type="email" id="conf_email" size="50" /></td>
</tr>
<tr>
<td height="25"><label>
<input type="submit" name="Submit" value="search" />
</label></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"><strong>First Name </strong></td>
<td> </td>
<td><input name="fname" type="text" id="fname" size="30" /></td>
</tr>
<tr>
<td height="25"><strong>Last Name </strong></td>
<td> </td>
<td><input name="lname" type="text" id="lname" size="30" /></td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"><strong>New Password</strong></td>
<td> </td>
<td><input name="newpass" type="password" id="newpass" size="30" /></td>
</tr>
<tr>
<td height="25"><strong>Confirm New Password </strong></td>
<td> </td>
<td><input name="conf_newpass" type="password" id="conf_newpass" size="30" /></td>
</tr>
<tr>
<td height="25"><input type="submit" name="save" value="save" /></td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
</form>
PHP Script
<?php
include("admin/link.php");
include("admin/opendb.php");
mysql_select_db ("userdetails");
$term = $_POST['email'];
$sql = mysql_query("select forename, surname, email address from userdetails where emailaddress like '%$email%'");
while ($row = mysql_fetch_array($sql)){
echo '<br/> First Name: '.$row['forename'];
echo '<br/> Last Name: '.$row['surname'];
echo '<br/><br/>';
}
?>
The search functionality works fine, but I can't work out how to populate the forename and surname fields on my form from the records retrieved from my database. I've been looking for, and found examples on how to do this, if I want to simply show the data as a table, but I can't find any that explain how to populate the fields in a form.
I just wondered whether it would be at all possible that someone could provide some guidance please on how I can do this.
Many thanks
The previous answer will work fine if short tags are enabled on the server. You should stick to the long syntax as below in case you change hosting providers at a later date.
<input name="fname" type="text" id="fname" size="30" value="<?php echo $row['surname']; ?>" />
just set the value of your input element
<tr>
<td height="25"><strong>First Name </strong></td>
<td> </td>
<td><input name="fname" type="text" id="fname" size="30" value="<?= $row['surname'] ?>" /></td>
</tr>