I'm using the following code to submit a login form:
<div data-role="content">
<form id="test" method="post" action="login.php">
<table>
<tr>
<td>User ID</td>
<td><input type="text" name="userid" size="20" /></td>
<br />
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" size="20" /></td>
</tr>
</table>
<p>
<input type="submit" name="mysubmit" value="Login" />
</p>
</form>
</div>
This form submission works fine on Firefox, Internet Explorer, Chrome, and Safari on Windows. However, when I'm using Device Preview in Dreamweaver and trying it from my Iphone, I get 'error loading page' on all my form submits. If I put in data-ajax="false", I then get
'{"code":"MethodNotAllowedError","message":"POST is not allowed"}'
when I submit my form. Also, I'm using local server for my sql server.
I even tried using test.php as the action instead of my login.php page with the following blank code for test.php and it still came up 'error loading page':
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
I've tried all this from an android phone also and still get 'error loading page' in Device Preview. This is my first app so once I can figure out this problem, I'll be full steam ahead.
Add ids to your inputs. Instead of
<input type="text" name="userid" size="20" />
Put
<input type="text" id="userid" name="userid" size="20" />
Related
I have complete coding in PHP Codeignitor 4 for inserting data into database, but whenever i try to access localhost its giving error.
i changed my base url too but nothing working...
i have project name ci4_crud then app and subfolders i m using different links like localhost/insert or localhost/ci4_crud/app/views/insert but nothing working ...
in App.php my base url is http://localhost/ci4_crud/
can someone help me plz
<!DOCTYPE html>
<html>
<head>
<title> Registration Form </title>
</head>
<body>
<form method="post" action="<?=base_url() ?> Crud/savedata">
<table border="1" width="600">
<tr>
<input type="text" name="first_name" placeholder="Enter First Name">
</tr>
<tr>
<input type="text" name="last_name" placeholder="Enter Last Name">
</tr>
<tr>
<input type="text" name="address" placeholder="Enter Address">
</tr>
<tr>
<input type="text" name="email" placeholder="Enter Email ID">
</tr>
<tr>
<input type="submit" name="save" value="Save Data">
</tr>
</table>
</body>
</html>
Try putting the following rule in public/.htaccess on line 17:
RewriteBase /ci4_crud
try this
action="<?php echo base_url(); ?>crud/savedata"
or this
action="<?php echo base_url(); ?>index/crud/savedata"
and also may I know what error message you get.
When the user clicks submit, it is sending both a post AND get request to the script. The Post returns a 302 Found, and the Get returns a 200, but the print_r shows an empty array after the form is submitted. I can't figure out why this is happening.
This is running on an AWS Linux instance with PHP 5.4 and Apache 2.4.
Here is the code:
<?php
print_r($_REQUEST);
?>
<!doctype html>
<html>
<meta charset="UTF-8" />
<title>Login</title>
<head>
</head>
<body>
<p>Please login:</p>
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<table>
<tr>
<td>
username
</td>
<td>
<input type="text" name="username" id="username" style="width:400px;"> (case sensitive)
</td>
</tr>
<tr>
<td>
password
</td>
<td>
<input type="password" name="password" id="password" style="width:400px;">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="submit">
</td>
</tr>
</table>
</form>
</body>
</html>
When I click submit, this is what I see in the FF dev tools:
Your are not sending POST and GET - only POST.
Your server then responds with a redirect (302) which makes your browser load the given URL via GET. At this point your data is lost (due to the redirect) and the array is empty. The question is why your server instructs to redirect.
The most likely reason is your htaccess file. Could you please send it.
Was trying to follow a tuitorial online on how to submit data using html to mysql database.
I created 2 php files named index.php and process.php. What i wanted to show was what I typed in inside index.php will show on process.php when I clicked on the button "add employee". But nothing showed up.
Here is what's inside index.php
<!DOCTYPE html>
<html>
<head>
<style>
label{display:inline-block;width:100px;margin-bottom:10px;}
</style>
<title>Add Employee</title>
</head>
<body>
<form method="post" action="">
<label>First Name</label>
<input type="text" name="first_name" />
<br />
<label>Last Name</label>
<input type="text" name="last_name" />
<br />
<label>Department</label>
<input type="text" name="department" />
<br />
<label>Email</label>
<input type="text" name="email" />
<br />
<input type="submit" value="Add Employee">
</form>
</body>
</html>
Here is a Screenshot of the form.
click here for index.php image
Wile here is what's inside the process.php
<?php
print_r($_POST);
This is what shows up
process.php image
Sorry a beginner at this. Hope you guys can help. Thank you!
Maybe you are missing the "action"?
<form method="post" action="/process.php">
You should specify what you need.Somethings like this:
<?php
print_r($_POST['first_name']);
Or use foreach loop to get full array value.
You can go through with fill up action tag so when you submit the form it will go to proccess.php page.
<form method="post" action="process.php">
As requested by Shankar I am going to post the form code and the php code to this issue. Since yesterday I have moved over to my MAC and installed XAMPP to try to solve the problem but I am still having the same issue. Firstly here is the form code as set in text mate:
<!DOCTYPE HTML>
<head>
</head>
<title>Practising my PHP</title>
<body>
<h2>Subscriber Form</h2>
</body>
<form id="subscriber" action="practice.php" method="post">
<table cellpadding="0" cellspacing="25" border-width="0">
<tr>
<td><label for name="name" id="name" value="">Name:</td>
<td><input type="text" id="name" maxlength="30" maxsize="24"></td>
</tr>
<tr>
<td><label for name="email" id="email" value="">Email:</td>
<td><input type="text" id="name" maxlength="30" maxsize="24"></td>
</tr>
<tr>
<td><input type="reset" id="reset" value="reset"></td>
<td><input type="submit" id="submit" value="submit"</td>
</tr>
</table>
</form>
</html>
Next we have the processing PHP code.
<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$server = mysql_connect('localhost', 'root', '') or die("The Server Cannot
Be Accessed at This Time");
$db = mysql_select_db('practising') or die("The Database Cannot Be Accessed,
Please Try Again Later");
$query = mysql_query("INSERT INTO `subscribers`(`name`,`email`)
VALUES ('$name','$email')");
if(empty($name) || empty($email)) {
echo "All Fields Must Be Filled Out";
} else {
echo "Your Information has Been Added to Our Database";
}
}
?>
I look forward to your comments and help. Oh by the way both files are saved as .php files.
Whatever errors there are in the above can somebody please advise.
What is happening at my end is this. I open the newsletter.php page which displays the form in the browser. When I do anything like fill in one field and test for if statement to notify me that all fields must be filled in nothing happens. I just get the form processing and a bland newsprocess.php page is returned in the processor. Also there is nothing being inserted into the database. I hope that this information is clear enough if you can help me it will be much appreciated. I have also changed my copy of WAMP to 4.0.4. to see if this helps. I also open the file in the urle with the following http://localhost/wamp/TrainingPHP/newsletter.php
Another strange thing is if I us a <?php echo "hello world" ?>as a test outside of this code but on the same page then the echo returns the hello world.
change your mysql_query code
$query = mysql_query($sql, "INSERT INTO subscribers(name,email)
VALUES('$name','$email')") or die(mysql_error());
to
$query = mysql_query("INSERT INTO subscribers(name,email)
VALUES('$name','$email')") or die(mysql_error());
Remove $sql inside mysql_query
Note: Try to use Mysqli or PDO as mysql_* function will be deprecated in future versions of PHP
=========== Edit ===========
change this line <td><input type="submit" id="submit" value="submit"</td>
to
<td><input type="submit" id="submit" name="submit" value="submit"></td>
you have missed ending ">" for input type = submit
give name to the submit button like name="submit" as i have given. as with out name PHP will not recognize this field
you only have given id to the email and name fields you have to give them names. PHP do not recognize ids but it know a field by name. change your both email and name html field like this.
as
<input type="text" id="name" name="name" maxlength="30" maxsize="24">
<input type="text" id="email" name="email" maxlength="30" maxsize="24">
your PHP code is ok but you have issues in your HTML code. you need to have some more practice in HTML and there were some basic mistakes.anyways im posting working code of HTML you can use this and compare it with yours and remove mistakes in you code.
<!DOCTYPE HTML>
<head>
<title>Practising my PHP</title>
</head>
<body>
<h2>Subscriber Form</h2>
<form id="subscriber" action="practice.php" method="post">
<table cellpadding="0" cellspacing="25" border-width="0">
<tr>
<td><label for name="name" id="name" value="">Name:</td>
<td><input type="text" id="name" name="name" maxlength="30" maxsize="24"></td>
</tr>
<tr>
<td><label for name="email" id="email" value="">Email:</td>
<td><input type="text" name="email" id="name" maxlength="30" maxsize="24"></td>
</tr>
<tr>
<td><input type="reset" id="reset" value="reset"></td>
<td><input type="submit" id="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>
for example the following file is SamePage.php
<!DOCTYPE html>
<html lang="en">
<head><title>Personal Information</title></head>
<body>
<?php
if(!empty($_POST))
{
echo $_POST['var'].'<br />';
//do a bunch of stuff
...
echo "Inserted into database succesfully! You will now be redirected.<meta http-equiv=refresh content=4;url=database.php><br /></body></html>";//meta refresh gets rid of old POST data
exit;
}
?>
Add another entery:<br />
<form method="POST" action="SamePage.php"><--!It sends the information to itself-->
name: <input type="text" name="name" size="10" maxlength="25" /><br />
telephone: <input type="text" name="telephone" size="10" maxlength="25" /><br />
birthday: <input type="text" name="birthday" size="10" maxlength="25" /><br />
<input type="submit" value="add" />
<input type="reset" value="clear" />
</form>
</body>
</html>
It's not very nice to have the exit there and sometimes I don't want to refresh the page, but it has to be done encase the user presses the refresh on the browser and the same POST data gets sent again and things get messed up. Can anyone think of a better way?
Best is to send the form to another page and the reload your page... But if you don't want, you can:
Use AJAX
Put all your HTML code between { } symbols
Use templates (avoid mix PHP and HTML)