473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Wampserver 2.0 and php

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 :(



Expand|Select|Wrap|Line Numbers
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title> Connect To Database</title>
  5. </head>
  6. <body>
  7.  
  8. <form action="results.php" method="post">
  9. <input name="name" type="text" value="name">
  10. <input name="" type="submit" value="search">
  11. </form>
  12.  
  13. </body>
  14. </html>
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo $name;
  3. ?>
Dec 11 '09 #1
19 3084
kovik
1,044 Expert 1GB
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.

Expand|Select|Wrap|Line Numbers
  1. if (!empty($_POST)) { // A form has been submitted
  2.     if (!empty($_POST['name'])) {
  3.         echo $_POST['name'];
  4.     }
  5. }
Dec 11 '09 #2
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!
Dec 11 '09 #3
kovik
1,044 Expert 1GB
Try to print_r() the $_POST array to see if anything has been submitted.

Expand|Select|Wrap|Line Numbers
  1. print_r($_POST);
Dec 11 '09 #4
No, nothing.

I tried this:

Expand|Select|Wrap|Line Numbers
  1. <?
  2. if (!empty($_POST)) { // A form has been submitted
  3.      if (!empty($_POST['name'])) {
  4.       echo $_POST['name'];
  5.     }
  6.  }
  7.  
  8. print_r($_POST);
  9. ?>
Dec 11 '09 #5
kovik
1,044 Expert 1GB
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.
Dec 11 '09 #6
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 =)
Dec 11 '09 #7
kovik
1,044 Expert 1GB
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:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. print_r($_POST);
  3. ?>
  4. <form method="post" action="#">
  5.   <input type="text" name="name" value="" />
  6.   <button type="submit">Submit</button>
  7. </form>
Dec 11 '09 #8
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 )
Dec 11 '09 #9
kovik
1,044 Expert 1GB
Good. That means that if you echo $_POST['name'], it would output "hello."
Dec 11 '09 #10
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
Dec 11 '09 #11
kovik
1,044 Expert 1GB
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
Dec 11 '09 #12
I dont know why it doesnīt work, I use this script for the html and php file:

Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <?php
  3. echo $_POST['name']
  4. ?>
  5.  
  6. <form action="#" method="post">
  7. <input name="name" type="text" value="name">
  8. <input name="" type="submit" value="search">
  9. </form>
  10.  
  11. </body>
Expand|Select|Wrap|Line Numbers
  1. <?
  2. if (!empty($_POST)) { // A form has been submitted
  3.      if (!empty($_POST['name'])) {
  4.       echo $_POST['name'];
  5.     }
  6.  }
  7. echo $_POST['name']
  8. ?>
Dec 11 '09 #13
kovik
1,044 Expert 1GB
The "action" attribute of the <form> element must correspond to the file that should be receiving the data.
Dec 11 '09 #14
Tried that 2 doesnt work. :/
Programming canīt be this hard lol

meybe itīs something wrong with wampserver.. dont know..
Dec 11 '09 #15
kovik
1,044 Expert 1GB
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.
Dec 11 '09 #16
Markus
6,050 Expert 4TB
Also, it's probable your PHP configuration has PHP's short-opening tags disabled. Always use <?php over <?.
Dec 11 '09 #17
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. =))
Dec 11 '09 #18
kovik
1,044 Expert 1GB
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.
Dec 11 '09 #19
Aha ok, thanks for the explanation. And for all the help.
Dec 11 '09 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

10
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....
12
usafshah
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...
1
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...
1
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!!!
1
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...
1
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...
0
by: nakatsu | last post by:
can xampp/wampserver connect to visual basic? please help me how to do it?tq
4
by: Erwin Moller | last post by:
Can someone give me some help?
8
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...
0
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,...
0
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$) { } ...
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.