Hi,
Iīve just started using php, and iīm trying to make it work with wampserver!
Iīm using wamperver 2 , PHP 5.30
on windows 7
I have installed wampserver correctly and the localhost seems to work.
When i try this script:
<?php echo "something" ?>
It works!
But when I try to send information from a html file to php file, the varibel doesn't go throw. I get this message: Notice: Undefined variable: name in C:\wamp\www\php\results.php on line 3
Please guys help me out :( -
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-
<title> Connect To Database</title>
-
</head>
-
<body>
-
-
<form action="results.php" method="post">
-
<input name="name" type="text" value="name">
-
<input name="" type="submit" value="search">
-
</form>
-
-
</body>
-
</html>
19 3084
The form uses the method "post," as you can see in the <form> element's attributes. So, you will find the values from the form in the $_POST superglobal array in PHP. - if (!empty($_POST)) { // A form has been submitted
-
if (!empty($_POST['name'])) {
-
echo $_POST['name'];
-
}
-
}
Thanks for the help kovik =)
Now there are no errors, but the browser page is emty! It doesnīt show anything...donīt know why!
Try to print_r() the $_POST array to see if anything has been submitted.
No, nothing.
I tried this: - <?
-
if (!empty($_POST)) { // A form has been submitted
-
if (!empty($_POST['name'])) {
-
echo $_POST['name'];
-
}
-
}
-
-
print_r($_POST);
-
?>
Then that means that nothing has been submitted. The $_POST array only has data after you press the submit button on a form that posts to the page.
Ok, I see. But script is right for both php and html right?
So what is the problem then, what have i done wrong?
As I said before when i just "echo" something it does show up..
But of course I understand itīs difficult for you to point the problem out with the information provided by me.
Thanks anywaym, please let me know if you get an new idea =)
What I'm trying to tell you is that you have to test this page AFTER pressing the submit button...
A better way to do it is to keep it in the same page: - <?php
-
print_r($_POST);
-
?>
-
<form method="post" action="#">
-
<input type="text" name="name" value="" />
-
<button type="submit">Submit</button>
-
</form>
ok sorry, didnīt understand that. This is very new for me =p
I tried that out and got this message in the browser when I typed hello;
Array ( [name] => hello )
Good. That means that if you echo $_POST['name'], it would output "hello."
yes it does, it (action = "#") but not when send it to another page.
But I can live with that for now I guess.
thanks a lot =D
It should work fine going from one page to another. Not sure what went wrong with yours, but it is still common practice to submit forms to the same page
I dont know why it doesnīt work, I use this script for the html and php file: - <body>
-
<?php
-
echo $_POST['name']
-
?>
-
-
<form action="#" method="post">
-
<input name="name" type="text" value="name">
-
<input name="" type="submit" value="search">
-
</form>
-
-
</body>
- <?
-
if (!empty($_POST)) { // A form has been submitted
-
if (!empty($_POST['name'])) {
-
echo $_POST['name'];
-
}
-
}
-
echo $_POST['name']
-
?>
The "action" attribute of the <form> element must correspond to the file that should be receiving the data.
Tried that 2 doesnt work. :/
Programming canīt be this hard lol
meybe itīs something wrong with wampserver.. dont know..
That is doubtful. Trying echoing something identifying in the receiving file, like "This file is X." I suspect that you are submitting the form to the wrong file.
Also, it's probable your PHP configuration has PHP's short-opening tags disabled. Always use <?php over <?.
YEEEEEEEEEES!!!!
Now it works, I used <?php instead of <?, But thats strange I used that in my first post, but it didnīt work. Well now it does thanks to Kovik and Markus. =))
The reason it didn't work in the first post is because you were using $name instead of $_POST['name']. $name would only exist if you had register_globals on, which is recommended against because of security reasons.
Aha ok, thanks for the explanation. And for all the help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Primal Oooze |
last post by:
XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use -
just download, extract and start....
|
by: usafshah |
last post by:
HI all,
i have a domain abc.info on a remote server and its files are hosted on let say 217.56.34.12, and a subdomain subdomain.abc.info hosted on let say 80.45.1.26 ("/docs/www/") and another...
|
by: phpphp |
last post by:
hi i ve install php through wampserver.i've made a program using session_start og login which run on m/c on which php is installed seperetely means all s/w is installed independently.bt its not work...
|
by: shahnoor |
last post by:
Refering to: WAMP and Perl - Getting Started
hey hello, i have installed activestate perl, but still perl is not configured in wamp! and there is no solution in wamp help files, so please help!!!
|
by: comp.lang.php |
last post by:
<pre>
if (!function_exists('mime_content_type_fileinfo')) {
/**
* Will use {@link http://us2.php.net/fileinfo FileInfo} functions
provided within {@link http://pecl.php.net PECL} bundle to return...
|
by: vayalumkan |
last post by:
Hi Sir,
I have a content management system software developed in PHP platform using Mysql.
I want 'Apache web server for windows' to run the Application.
My operating system is Windows XP...
|
by: nakatsu |
last post by:
can xampp/wampserver connect to visual basic? please help me how to do it?tq
|
by: Erwin Moller |
last post by:
Can someone give me some help?
|
by: john6630 |
last post by:
I am trying to get PDO for sqlite to work on my localhost system. I
have modified the PHP5.ini file as shown below and run the following
PHP script. As stated below, it reports the mssql, mysql and...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |