View Full Version : action form command to php file

03-31-2010, 03:59 AM
I have a <form> element in one of my html files and the action="" command is supposed to send the textfield strings to a php file that's in the folder used to access mySQL via the localhost. Once the data gets to the php file, it will get put into mySQL. But when I hit the submit button, an error comes up and says it can't find C:/wamp/www/wamp/www/file.php. I have no idea why it's trying to look through two sets of the same file (/wamp/www). With WAMP I thought the file used to access the database was supposed to be in a specific location. Am I wrong? How can I fix all this?

03-31-2010, 05:18 AM
Sounds like you've used the wrong path in the form's action attribute. Show some code and maybe someone can confirm.

03-31-2010, 05:45 AM
Ok. Here's the form section for the html file. Right now, all the files related to my website are in the folder where localhost pulls from.

<script type="text/javascript">
function notEmpty(elem, elem1, elem2, helperMsg, helperMsg2){
if(elem.value.length == 0){
return false;
if(elem1.value.length == 0){
return false;
if(elem2.value.length == 0){
return false;

var alphaExp = /^[a-zA-Z]+$/;
return true;
return false;

return true;

<div id="main">
<form align="center" method="post" action="wamp/www/recipesubmit.php">
<font color="red"><i>* = Required Field</i></font>
<table border="0" bordercolor="darkblue">
<tr><td align="right"><font color="red">*</font>Recipe Name:</td><td><input type='text' id='recipeName' size=50></td></tr>
<tr><td align="right"><font color="red">*</font>Ingredients:</td><td><input type='text' id='ingredients' size=50></td></tr>
<tr><td></td><td><font font size="2" color="red">Reminder: </font><font font size="2">Make sure you put a space between each ingredient.</br>Example: <b>chicken cream of mushroom soup</b>. DO NOT PUT</br>MEASUREMENTS! It is also important to correctly spell the</br>ingredients otherwise your recipe may not be found when searched.</td></tr>
<tr><td align="right"><font color="red">*</font>Directions:</td><td><textarea id='description' cols=50 rows=10></textarea></td></tr>
<tr><td align="right"><font color="red">*</font>Cook/Prep Time:</td>
<td><select name="cooktimedrop">
<option value="zerofive">0-5</option>
<option value="sixten">6-10</option>
<option value="elevenfifteen">11-15</option>
<option value="sixteentwenty">16-20</option>
<option value="twentyonetwentyfive">21-25</option>
<option value="twentysixthirty">26-30</option>
<option value="thirtyonethirtyfive">31-35</option>
<option value="thirtysixforty">36-40</option>
<option value="fortyonefortyfive">41-45</option>
<option value="fortysixfifty">46-50</option>
<option value="fiftyonefiftyfive">51-55</option>
<option value="fiftysixsixty">56-60</option>
<option value="sixtyoneplus">61+</option>
</select> minutes</td>
<tr><td align="right"><font color="red">*</font>Genre:</td>
<td><select name="genredrop">
<option value="alcoholic">Alcoholic</option>
<option value="appetizers">Appetizers</option>
<option value="beverages">Beverages</option>
<option value="breads">Breads</option>
<option value="breakfast">Breakfast</option>
<option value="cakes">Cakes</option>
<option value="candies">Candies</option>
<option value="casseroles">Casseroles</option>
<option value="cookies">Cookies</option>
<option value="crockpot">Crockpot</option>
<option value="desserts">Desserts</option>
<option value="dipsdressings">Dips/Dressings</option>
<option value="entrees">Entrees</option>
<option value="fatfree">Fat Free</option>
<option value="georgeforeman">George Foreman</option>
<option value="halal">Halal</option>
<option value="herbal">Herbal</option>
<option value="italian">Italian</option>
<option value="jams">Jams</option>
<option value="jello">Jell-O</option>
<option value="lowfat">Low Fat</option>
<option value="mexican">Mexican</option>
<option value="puddings">Puddings</option>
<option value="rice">Rice</option>
<option value="salads">Salads</option>
<option value="sauces">Sauces</option>
<option value="seafood">Seafood</option>
<option value="snacks">Snacks</option>
<option value="soups">Soups</option>
<option value="vegan">Vegan</option>
<option value="vegetarian">Vegetarian</option>
<tr><td align="right">Submitted By:</td><td><input type='text' id='submittedBy' size=40></br></td></tr>
<tr><td></td><td align="right"><input type='submit' onclick="notEmpty(document.getElementById('recipeName'), document.getElementById('ingredients'), document.getElementById('description'),'You have not filled in all required fields.', 'I thought I said no measurements! (No Numbers)')" value='Submit Recipe'></td></tr>


03-31-2010, 11:02 AM
I reckon tomws is right.

<form align="center" method="post" action="wamp/www/recipesubmit.php">

maybe this should rather be

<form align="center" method="post" action="/wamp/www/recipesubmit.php">

I *think* the problem is that you're relatively addressing your PHP. "wamp/www/" means "go from current directory (in general, server root) to wamp, then to www".
That could explain the double path issue.
Also try a plain "recipesubmit.php", I wonder if this works as well in your case.

03-31-2010, 07:08 PM
I tried
<form align="center" method="post" action="/wamp/www/recipesubmit.php">
but it didn't work. It actually does absolutely nothing. When I press the submit button, nothing happens, as opposed to leaving off that first "/" which takes me to an error page.
Now, i know for php files to communicate to mySQL the directory has to say "localhost" in the name. For example, in C:/wamp/www folder, I have a php file called phpmysqltest that I made to test the connection between php and mySQL. When typing the address into the browser, C:/wamp/www/phpmysqltest.php does not work. But changing it to localhost/phpmysqltest.php DOES work. But how do i specify that in the form?

03-31-2010, 07:55 PM
<form align="center" method="post" action="recipesubmit.php">

03-31-2010, 08:17 PM
That doesn't work because it looks through the same folder as the rest of my website's files.

03-31-2010, 08:21 PM
That doesn't work because it looks through the same folder as the rest of my website's files.

But that's where you were trying to direct it before, yes?

<form align="center" method="post" action="wamp/www/recipesubmit.php">

03-31-2010, 08:31 PM
No. All the files that are used by my website are kept in a folder on my desktop. The only file in the C:/wamp/www folder is the one the action command is trying to access. If I use this...

<form align="center" method="post" action="wamp/www/recipesubmit.php">

...the place the action command is looking for the file is C:.../desktop/website/wamp/www/file.php.
If I use...

<form align="center" method="post" action="/wamp/www/recipesubmit.php">

..nothing happens. The submit button doesn't do anything. The page stays on the screen just as it was.

03-31-2010, 08:47 PM
wamp/www/recipesubmit.php is relative to the current directory - the directory where the form is sitting. That won't work.

/wamp/www/recipesubmit.php is relative to the website root directory. That won't work.

Why do you have files tossed all around the filesystem? That's going to screw things up and is not an accurate representation of a folder structure on a web host. If you'll put everything in standard locations, this will be infinitely easier.

03-31-2010, 09:04 PM
The files are in two different locations. One file is in the /wamp/www folder and the rest are in a folder on my desktop. Should I put all the files in the /wamp/www folder? Or is there a better place?

03-31-2010, 09:05 PM
Should I put all the files in the /wamp/www folder?

Yes. I'm not sure, but I suspect the WAMP docs would have said that.

03-31-2010, 11:44 PM
Sorry about that cross-post. I figured out how to make it work. Thanks for the help.