I am working on oops based project in php when I upload an image it is not uploade with information that I want to upload with this image. Here i connect the controller page I create object for uploading the image and information in database.
Code for html page
<?php
include('include/control.php');
include('include/connect.php');
error_reporting(0);
if(count($_FILES) > 0){
if(is_uploaded_file($_FILES['image']['tmp_name'])){
$i=addslashes(file_get_contents($_FILES['image']['tmp_name']));
$j=getimagesize($_FILES['image']['tmp_name']);
$objectNew=new add;
if(isset($_POST['submit'])){
$info1=$_POST['info1'];
$info2=$_POST['info2'];
$info3=$_POST['info3'];
$info4=$_POST['info4'];
$info5=$_POST['info5'];
$imagetype=$i;
$imageData=$j;
$ob=$objectNew->addInfo($imagetype,$imagedata,$info1,$info2,$info3,$info4,$info5);
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
add info<br />
<form name="form" enctype="multipart/form-data" action="" method="post">
<input type="text" name="info1" /><br />
<input type="text" name="info2" /><br />
<input type="text" name="info3" /><br />
<input type="text" name="info4" /><br />
<input type="text" name="info5" /><br />
<input type="file" name="image"/><br />
<input type="submit" name="submit" />
</form>
</body>
</html>
Code for controller
function addInfo($imagetype,$imagedata,$info1,$info2,$info3,$info4,$info5)
{
$addI=$this->conn->prepare('insert into `addinfo` (imagetype,image,info1,info2,info3,info4,info5) VALUES (?,?,?,?,?,?,?) ');
$addI->bind_param("sbsssss",$imagetype,$imagedata,$info1,$info2,$info3,$info4,$info5) ;
$addI->execute();
}
This is just a suggestion.
You could add "required" attribute to your inputs so it won't be submitted if its empty.
This works on latest browser
your code
<input type="text" name="info1" /><br />
<input type="text" name="info2" /><br />
can be
<input type="text" name="info1" required /><br />
<input type="text" name="info2" required /><br />
Related
I am trying to pass the 'name' text field input to blank2.php. I can send the data across
but anything after I type the space bar all the other input after it is omitted. What am I missing?
blank.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>First Page</title>
</head>
<body>
<form action="http://www.example.com/blank2.php" method="post">
<label for="name"></label>
<input type="text" name="name" placeholder="Name" id="name">
<div>
<input type="submit" id="submit" name="submit" value="Send">
</div>
<div>
</form>
</body>
</html>
Here is the second page:
<?php
session_start();
$_SESSION['name'] = $_POST['name'];?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Second Page</title>
</head>
<body>
<form action = "http://example.com/blank3.php" method="post">
<label for="name"></label>
<input type="text" name="name" placeholder="Name" id="name" value=<?php echo $_POST['name'];?>>
<br>
<div>
<input type="button" id="submit" name="submit" value="Send Message">
</div>
</form>
</body>
</html>
I'd really appreciate if if anyone can assist me.
Put quotes around the value.
<input type="text" name="name" placeholder="Name" id="name" value="<?php echo $_POST['name'];?>">
I am trying to catch some text from the textbox, to save it in a variable and then post it on my browser if I click the submit button. My code is this:
<?php
$var1=$_POST['text1'];
$var2=$_POST['display'];
if(isset($var2)){
var_dump( $var1);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<input type="text" value="gdf" name="text1" id="text1" /><br /><br />
<input type="submit" id="display" name="display"><br /><br />
</body>
</html>
I don't know what is wrong. The code on rextester
For starters you need to implement a form on you HTML page and set the action to a new .php page.
<form action='display.php' method='post'>
*your input fields go here*
Now create a new php page (in this case display.php)
Declare the variables as you did....
$var1=$_POST['text1'];
$var2=$_POST['display'];
if(isset($var2)){
var_dump( $var1);
then you can simply echo each variable accordingly...
Final Result
HTML PAGE:
<form action='result.php' method='post'>
<input type="text" value="gdf" name="text1" id="text1" /><br /><br />
<input type="submit" id="display" name="display"><br /><br />
</form>
result.php
<?php
$var1 = $_POST['text1']; // create variables of your form elements
$var2 = $_POST['display'];
echo '$var1 . ' ' . $display . '.';
?>
Basically the php page is saying get text1 and display from the form (names) and create variables of them...
Then echo (print) these variables on the screen. (in plain english xD)
p.s
Your rextester isn't working because you haven't specified a form.
You need to setup the FORM tags so they have the correct attributes for POST. Try:
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" value="gdf" name="text1" id="text1" /><br /><br />
<input type="submit" id="display" name="display"><br /><br />
</form>
</body>
</html>
You need to use a form, otherwise you aren't posting anything.
Something like:
form.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form method="post" action="yourphpfile.php">
<input type="text" value="gdf" name="text1" id="text1" /><br /><br />
<input type="text" value="display" name="display" id="display" /><br /><br />
<input type="submit" value="submit"><br /><br />
</form>
</body>
</html>
yourphpfile.php
<?php
if(!empty($_POST['text1']) and !empty($_POST['display'])){
$var1=$_POST['text1'];
$var2=$_POST['display'];
echo "$var1 $var2";
}
?>
Check this complete example
To display text box and button on clicking submit button
<form>
<input type="submit" value="OK" name="btn_name"/><br />
<?php
if(isset($_GET['btn_name']))
{
echo "<input type=text name=txt_userinput />";
echo "<input type=submit value=Area name='btn_calculate'/>";
}
?>
</form>
Exact problem: Trying to pass a param from the url to a search box destination page.
The param is "subid" this way:
http://www.domain.com/?subid=3456
and the current (non working) search form code in php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<form action="http://search.yahoo.com/search?subid=<?php print $_GET['subid'];?>&" target="_blank" id="search-box">
<input type="text" name="p" size="31" />
<input type="submit" value="Search" />
</form>
</body>
</html>
I can see with firebug that the subid is in the form action when I go here:
http://www.domain.com/?subid=3456
but when I run a query in the form, is not passing to yahoo.
so where is the problem?
You should post subid as a parameter also, and specify method as get.
<form action="http://search.yahoo.com/search" target="_blank" method="get" id="search-box">
<input type="hidden" name="subid" value="<?php print $_GET['subid'];?>" />
<input type="text" name="p" size="31" />
<input type="submit" value="Search" />
</form>
As was asked by the author, added some filtering for GET parameter:
<form action="http://search.yahoo.com/search" target="_blank" method="get" id="search-box">
<input type="hidden" name="subid" value="<?=(int)$_GET['subid']?>" />
<input type="text" name="p" size="31" />
<input type="submit" value="Search" />
</form>
Or you can use strip_tags + htmlentities functions, before output.
I have made a form. Why aren't the submit (enviar) and reset (restablecer) buttons displayed? If I remove the PHP code, they do appear. Why?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Documento sin título</title>
</head>
<body>
<div>
<form action="" id="noti-form"method="post" enctype="multipart/form-data" name="noticia">
Antetítulo de la Noticia<br />
<input type="text" name="ante" size="70" id="ante" class="inputbox" />
<br />
Título de la Noticia<br />
<input type="text" name="titulo" size="70" id="titulo" class="inputbox" />
<br />
Subtítulo de la Noticia<br />
<input type="text" name="sub" size="70" id="sub" class="inputbox" />
<br />
Autor:<br />
<input type="text" name="autor" size="30" id="autor" class="inputbox" />
<br />
Texto de la Noticia<br />
<div align="center">
<textarea id="elm1" name="noticia" class=".noticia" rows="15" cols="80" style="width: 80%"></textarea></div>
<br />
<input type="file" name="foto" id="foto" />
<br />
<?php
echo '<select class="chosen" name="tags[ ]" multiple="true" style="width:400px;">';
$query=$database->tags();
foreach ($query as $data) {
echo '<option value="'.$data['tag'].'">'.$data['tag'].'</option>';
}
echo'</select>';
?>
<input type="submit" name="enviar" value="Enviar" class="button" />
<input type="reset" name="button" id="button" value="Restablecer" class="button" />
</form>
</div>
</body>
</html>
I've started learning PHP. Managed to setup things.
I'm using php version 5.3.13.
I'm trying to post some info to a html form and receive it in a php file.
For the purpose i'm using $_Post variable and the ouput at the php file is blank.
Below is the html code.
<body>
<form action="report.php" method="POST" >
<label for="firstname">First name:</label>
<input type="text" id="firstname" name="firstname" /><br />
<input type="submit" value="Report Abduction" name="submit" />
</form>
</body>
And below is the report.php code
<html>
<head>
<title></title>
</head>
<body>
<?php
$name = $_POST['firstname'] ;
print($name);
?>
</body>
</html>
Can any one advise what i'm missing ?
Thanks
Here is a super simple example, I suggest you begin to look for example tutorials # your favorite search engine, or buy a book.
Edit: Do you even have PHP installed? you mention inetpub which is a IIS path.
<?php
error_reporting(E_ALL);
if($_SERVER['REQUEST_METHOD']=='POST' && !empty($_POST['firstname'])){
//Do something with posted data
$out = htmlentities($_POST['firstname']).' has been abducted!';
}else{
//Form has not been posted so show form
$out = <<<FORM
<form action="" method="POST" >
<label for="firstname">First name:</label>
<input type="text" id="firstname" name="firstname" /><br />
<input type="submit" value="Report Abduction" name="submit" />
</form>
FORM;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My first test Script</title>
</head>
<body>
<h1>My first test Script</h1>
<?php echo(isset($out))?$out:null; ?>
</body>
</html>