I've been looking through the site and going over pointers on similar problems but none have seemed to work for me. I'm a wee bit stuck, hoping someone can point out my stupidity.
I created a basic form to test as my main site was giving me problems. There is no error checking or filtering for malicious code, it's just a test to figure out why it won't work.
I can't retrieve any data from a textarea.
All other types work, text, number, etc... all fine.
Here is my basic form, can anyone see the error of my ways?
<?php
require_once('header.php');
if(isset($_POST['submit']))
{
echo "<br>single line comment: " .$_POST['singlelinecomment'];
if (!isset($_POST['comments']))
{
echo "<br>nothing in textarea data, move along, move along";
}
else
{
$comments = $_POST['comments'];
echo "<br>comments: ". $comments;
}
}
?>
<form name="conversation-form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>
<input type='text' name="singlelinecomment">
</td>
</tr>
<tr>
<td>
<textarea rows="20" cols="50" form="conversation-form" name="comments"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit" /><br>
</td>
</tr>
</table>
</form>
form="conversation-form" remove it from textarea, it's the main cause.
Plus, you don't need this name="conversation-form" in <form>, unless you want to use it for CSS purposes, then use id="conversation-form" or class="conversation-form"
<textarea rows="20" cols="50" form="conversation-form" name="comments"></textarea>
^^^^^^^^^^^^^^^^^^^^^^^^ remove it
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table>
<tr>
<td>
<input type='text' name="singlelinecomment">
</td>
</tr>
<tr>
<td>
<textarea rows="20" cols="50" name="comments"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" name="submit" value="Submit" /><br>
</td>
</tr>
</table>
</form>
Related
I would like click on submit and the value input in the field to be stored in database.
However, I do not want to use a form action. Is it possible to do it without creating form action with PHP?
<tr>
<form method="post">
<tr>
<td>
<label for="Item name"><b>Finish Product:</b></label>
</td>
<td>
<input id="finish_product" type="text" maxlength="100" style="width:100px"name="finish_product" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Save" id="submit" />
</td>
</tr>
<?php
if(isset($_POST['submit']))
{
var_dump($_POST); exit;
$SQL = "INSERT INTO bom (finish_product) VALUES ('$finish_product')";
$result = mysql_query($SQL);
}?>
</tr>
However, I do not want to use a form action. Is it possible to do it
without creating form action with PHP?
No, that's not possible.
Just do it like this:
<tr>
<form method="post" action="mypage.php">
<tr>
<td>
<label for="Item name"><b>Finish Product:</b></label>
</td>
<td>
<input id="finish_product" type="text" maxlength="100" style="width:100px"name="finish_product" required>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Save" id="submit" />
</td>
</tr>
</form>
<?php
if(isset($_POST['finish_product']))
{
var_dump($_POST); exit;
$SQL = "INSERT INTO bom (finish_product) VALUES ('$finish_product')";
$result = mysql_query($SQL);
}?>
</tr>
here is only part of my code, the action does not well ...action. when i view in the google javascript tools i have an id in the action line
when i hit the submit button, nothing happens, its suppose to go to php/form.php with ID 28 in this instance
......
if (mysqli_num_rows($result))
{
while ($row = mysqli_fetch_assoc($result))
{
?>
<form name="form-list" method="post" action='php/form.php?id=<?php echo $row["id"]; ?>' >
<table>
<tr>
<td valign="top">
<label for="surname">Surname</label>
</td>
<td valign="top">
<?php echo $row["title"]; ?>
</td>
</tr>
<tr>
<td valign="top">
<label for="name">Id</label>
</td>
<td valign="top">
<input type="text" value='<?php echo $row["id"]; ?>' name="name" maxlength="50" size="30">
</td>
</tr>
<tr>
<td valign="top">
<input type="button" value="Submit" />
</td>
</tr>
<?php } } ?>
</table>
</form> .....
<input type="submit" value="Submit" />
The input type is not button it is submit.
The value attribute just changes the written text on the button but does not change it's behavior.
Note to the other answers:
Using POST is fine if he handles the request in the right way. In the given code example everything except the submit button works and is fine.
In this case the id is transmitted as a GET and all other values are submitted via POST. You can mix them.
Later you do have to use $_GET["id"] and $_POST["name"].. or you can even use $_REQUEST["..."] for all of them.
Ok so im making a login system and for some reason when typed like this im getting issues with it posting without an echo or print and the following script the displays itself help anyone.
<?PHP $form = '
<form method="POST" action="login.php">
<table>
<tr>
<td>Username:<td>
<td><input type="text" name="user"><td>
</tr>
<tr>
<td>Password:<td>
<td><input type="password" name="password"><td>
</tr>
<tr>
<td><td>
<td><input type="submit" name="loginbtn" value="Login"><td>
</tr>
<tr>
<td>Register<td>
<td>Forgoten Password<td>
</tr>
</table>
</form>'
;
?>
<?php //Some PHP Code if necessary
if(true) { //Any html between this brace and the next brace will be included
?>
<form method="POST" action="login.php">
<table>
<tr>
<td>Username:<td><td>
<input type="text" name="user">
<td>
</tr>
<tr>
<td>Password:<td><td>
<input type="password" name="password">
<td>
</tr>
<tr>
<td><td><td>
<input type="submit" name="loginbtn" value="Login">
<td>
</tr>
<tr>
<td>Register<td><td>Forgoten Password<td>
</tr>
</table>
</form>
<?php
} //End of if statement.
else { //This won't be shown, because the if statement is always true
?>
<div>
This is not displayed
</div>
<?php
}
?>
<?php
if(isset($_POST['submit']))
{
$uname=$_POST['uname'];
$pswd=$_POST['pswd'];
$cpswd=$_POST['cpswd'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$address=$_POST['add'];
$mobile=$_POST['mobile'];
$con=mysqli_connect("localhost","root","","registration");
$sql1="select usname, email from registration1 where usname='$uname' or email='$email'";
$query=mysqli_query($con,$sql1) or die(mysqli_error($con));
$rownum=mysqli_num_rows($query);
if($rownum != 0)
{
echo "User With This User Name or Email Address Is Already Available";
}
else
{
$sql2="insert into registration1 (usname,psswd,fsname,lsname,email,address,mobileno) values ('$uname','$pswd','$fname','$lname','$email','$address','$mobile')";
mysqli_query($con,$sql2) or die(mysqli_error($con));
echo "Registration Successful";
}
}
?>
I am redirecting to home.php which is written in form action, the php code in this is not executing. can anybody help me to resolve this
this is my html code i am redirecting to home .php on clicking submit button values entered in textbox is not entering into database on clicking submit button.
`<html>
<head>
<title>Registration Form</title>
</head>
<body>
<center>
<form method="post" action="home.php">
<table>
<tr>
<td>
<p>User Name</p>
</td>
<td>
<input type="text" name="uname"/>
</td>
</tr>
<tr>
<td>
<p>Password</p>
</td>
<td>
<input type="password" name="pswd" />
</td>
</tr>
<tr>
<td>
<p>Confirm Password</p>
</td>
<td>
<input type="password" name="cpswd" />
</td>
</tr>
<tr>
<td>
<p>First Name</p>
</td>
<td>
<input type="text" name="fname" />
</td>
</tr>
<tr>
<td>
<p>Last Name</p>
</td>
<td>
<input type="text" name="lname" />
</td>
</tr>
<tr>
<td>
<p>Email Address</p>
</td>
<td>
<input type="email" name="email" />
</td>
</tr>
<tr>
<td>
<p>Address</p>
</td>
<td>
<input type="text" name="add" />
</td>
</tr>
<tr>
<td>
<p>Mobile No.</p>
</td>
<td>
<input type="text" name="mobile" />
</td>
</tr>
<tr>
<td>
<input type="submit" value="submit" name="submit" />
</td>
</tr>
</table>
</form>
</center>
</body>
</html>`
If there is no Output / No Errors .. Please Make Sure $_POST['submit'] Variable is Posted Vai From..
at first want to say please describe the error properly.there can be many reason.
option 1:maybe $_POST['submit'] or other values is not initialized properly.then it wont enter the if block ever
option 2:$con=mysqli_connect("localhost","root","password"); check if this connection establishment is okay or not.
option 3:i am not sure.but i think while fetching multiple column you need to use an array().
please debug the code..find out after which line the code stop executing.you can do this by using echo 'xxx'; as checkpoint in your code and report us
note:use mysqli_real_escape_string() and various php mysqli function to be safe from mysqli injection
<input type="submit" value="submit" name="submit" />
<input type="hidden" name="submit" value="submit" />
</form>
this is how your form should be done..add that hidden type
EDIT 1: if it doesn't work.then put echo 'step 1,2,3...' in your home.php.and check after which statement it stops executing.for exemple you can put a echo right after if() to check if it is entering in your if block or not
This is simple and should work but doesn't, so I'm obviously derping pretty hard somewhere. The uploaded file name should print after form submission.
<?php
if (isset($_POST["submit"])) {
$name_of_uploaded_file = $_FILES['uploaded_file1']['name'];
print($name_of_uploaded_file);
}
?>
<form id="contactform" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr>
<td>
<table>
<tr>
<td>
Attach Logo:
</td>
<td>
<input type="file" id="uploaded_file1" name="uploaded_file1" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<input name="submit" id="submit" type="submit" value="Send" />
</td>
</tr>
</table>
</form>
You need the content encoding type set on your form open tag.
<form enctype="multipart/form-data" action="uploader.php" method="POST">