473,713 Members | 5,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form submit POST & php on one file problem.

42 New Member
For some reason the submit POST and php on one form doesn't work for me.

Here's my form code (it's dutch)

[html] <form method="POST">
<select name="locatie" size="1">
<option value="">Kies de locaties</option>
<option>Parij s</option>
<option>Lyon</option>
<option>Marseil e</option>
<option>Lile </option>

</select>
<br>
<br>
<select name="prijs" size="1">
<option value="">Kies de prijzen</option>
<option value="1">0-100.000 </option>
<option value="2">100.0 0-200.00 </option>
<option value="3">200.0 00-300.000 </option>
<option value="4">300.0 00-400.000 </option>
<option value="5">400.0 00-500.000 </option>
<option value="6">500.0 00-600.000 </option>
<option value="7">600.0 00 en meer </option>

</select>
<br>
<br>
<input type="submit" name="button" id="button" value="Zoeken" />
</form>[/html]


And here's my php code :

[PHP]<?
ERROR_REPORTING (E_ALL);
include("config .php");
if(isset($_POST['button']))
{
$location = $_POST['locatie'];
$price = $_POST['prijs'];

//check what price it is
if($locatie == ''){
echo"Foute locatie gekozen, Kies aub een goede locatie.";
}

if($price == ''){
echo"Foute prijs gekozen. Kies aub een goede prijs.";
}

elseif($price == '1'){


$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 0 AND price <= 100000";


}

elseif($price == '2'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 100000 AND price <= 200000";
}

elseif($price == '3'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 200000 AND price <= 300000";
}

elseif($price == '4'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 300000 AND price <= 400000";
}

elseif($price == '5'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 400000 AND price <= 500000";
}

elseif($price == '6'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 500000 AND price <= 600000";
}

elseif($price == '7'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price <= 600000";
}

while($results = mysql_fetch_arr ay($query))
{

echo "<table width='434' height='72' border='0'>";

echo "<tr><td width='133' height= '130'>";

echo "<img width='132' height='129' src='" . $results['Foto1'] . "'></img>";

echo "</td><td class='style5'> ";

echo "Type: " . $results['type'] . "<br>Descriptie :" . $results['description'];

echo "</td><td class='style5'> ";

echo "prijs: " . $results['price'] . ".-";

echo "</td></tr>";

echo "</table>";

}
}
?>[/PHP]


Any idea why it doesn't work?

Help is much appreciated.
Nov 10 '07 #1
8 2160
Atli
5,058 Recognized Expert Expert
Hi Dave.

First of all, I'd recommend changing the <? tag in your PHP code into <?php. The short-tags version you are currently using is disabled by default in PHP and can cause problems on other servers.

As for your problem. The <form> tag is missing the 'action' property. Without that the form won't know where to send the data. So even if the data is meant to be posted to the current page, set the 'action' property.

For example:
Expand|Select|Wrap|Line Numbers
  1. <form action="thisPage.php" method="POST">
  2.  
Nov 10 '07 #2
Dave Siegel
42 New Member
Hi Dave.

First of all, I'd recommend changing the <? tag in your PHP code into <?php. The short-tags version you are currently using is disabled by default in PHP and can cause problems on other servers.

As for your problem. The <form> tag is missing the 'action' property. Without that the form won't know where to send the data. So even if the data is meant to be posted to the current page, set the 'action' property.

For example:
Expand|Select|Wrap|Line Numbers
  1. <form action="thisPage.php" method="POST">
  2.  
Thanks, That worked.

But now its nagging with this error for some reason:

Warning: mysql_fetch_obj ect(): supplied argument is not a valid MySQL result resource in /home/content/C/o/l/Collussus/html/school/ict/search.php on line 213

this is my php(i left the tags on <? ?> because i know my server allows it. :

[PHP]<?
ERROR_REPORTING (E_ALL);
include("config .php");
if(isset($_POST['button']))
{
$location = $_POST['locatie'];
$price = $_POST['prijs'];

//check what price it is
if($locatie == ''){
echo"Foute locatie gekozen, Kies aub een goede locatie.<br>";
}

if($price == ''){
echo"Foute prijs gekozen. Kies aub een goede prijs.";
}

elseif($price == '1'){


$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 0 AND price <= 100000";


}

elseif($price == '2'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 100000 AND price <= 200000";
}

elseif($price == '3'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 200000 AND price <= 300000";
}

elseif($price == '4'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 300000 AND price <= 400000";
}

elseif($price == '5'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 400000 AND price <= 500000";
}

elseif($price == '6'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price >= 500000 AND price <= 600000";
}

elseif($price == '7'){
$query = "SELECT * FROM houses WHERE location = '" . $location . "' AND price <= 600000";
}

$results = mysql_query($qu ery);
while($results = mysql_fetch_obj ect($results))
{

echo "<table width='434' height='72' border='0'>";

echo "<tr><td width='133' height= '130'>";

echo "<img width='132' height='129' src='" . $results['Foto1'] . "'></img>";

echo "</td><td class='style5'> ";

echo "Type: " . $results['type'] . "<br>Descriptie :" . $results['description'];

echo "</td><td class='style5'> ";

echo "prijs: " . $results['price'] . ".-";

echo "</td></tr>";

echo "</table>";

}
}
?>[/PHP]
Nov 10 '07 #3
Atli
5,058 Recognized Expert Expert
These two lines are the source of your problem:
Expand|Select|Wrap|Line Numbers
  1. $results = mysql_query($query);
  2.     while($results = mysql_fetch_object($results))
  3.  
You are overwriting the database result resource with the return value of the mysql_fetch_obj ect() function. So on the next loop, the $results is not a valid MySQL resource, causing the function to fail and a warning to be printed.

You need to change the name of the variable you use to store the current row of data.
Nov 10 '07 #4
Dave Siegel
42 New Member
These two lines are the source of your problem:
Expand|Select|Wrap|Line Numbers
  1. $results = mysql_query($query);
  2.     while($results = mysql_fetch_object($results))
  3.  
You are overwriting the database result resource with the return value of the mysql_fetch_obj ect() function. So on the next loop, the $results is not a valid MySQL resource, causing the function to fail and a warning to be printed.

You need to change the name of the variable you use to store the current row of data.

Fixed that, still same problem.
Nov 10 '07 #5
Atli
5,058 Recognized Expert Expert
Have you check out if there was an error in your SQL?
Your code does not validate that the query executed successfully.

Try adding something like this before you try to use the result from the database:
Expand|Select|Wrap|Line Numbers
  1. if(!$result) {
  2.   echo "<pre><b>MySQL Query failed!</b>\n
  3.            <b>Error:</b> ". mysql_error() ."\n
  4.            <b>Query:</b> $query
  5.         </pre>";
  6. }
  7.  
Nov 10 '07 #6
Dave Siegel
42 New Member
Have you check out if there was an error in your SQL?
Your code does not validate that the query executed successfully.

Try adding something like this before you try to use the result from the database:
Expand|Select|Wrap|Line Numbers
  1. if(!$result) {
  2.   echo "<pre><b>MySQL Query failed!</b>\n
  3.            <b>Error:</b> ". mysql_error() ."\n
  4.            <b>Query:</b> $query
  5.         </pre>";
  6. }
  7.  
Fixed the first error.

Now it just gives me this error:

MySQL Query failed!

Error:

Query: SELECT * FROM houses WHERE region = 'Parijs' AND price >= 0 AND price <= 100000
Nov 10 '07 #7
Atli
5,058 Recognized Expert Expert
Note that the variable I used in my example was called $result, while the MySQL result in your code is called $results. (Force of habit for me. I always call mine $result :P)
Nov 10 '07 #8
Dave Siegel
42 New Member
That fixed it. Thanks.
Nov 10 '07 #9

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

Similar topics

4
4450
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most part, the scripts were created with http://phpcodegenie.sourceforge.net/
2
2292
by: iwasinnihon | last post by:
I don't usually like to do this, but I need help. I have gone over this code and cannot figure out why it doesn't work. First of all it doesn't check to see if you have filled in the required fields. Second, it doesn't submit the information (it's supposed to send it to mySql and email it to me.) and lastly, it doesn't bring up the thankyou.php after submitting the form. I don't know enough about PHP to find the problem. If someone could...
7
20926
by: Rui Pestana | last post by:
Hello all, I want to use the POST method to submit the form and then grab the parameters in the asp file with request.form("parm"). The problem is that I am using the _search target to open the asp page. When I use _blank target there is no problem, either I use GET or POST method. But when I use _search target, only GET method works.
5
2456
by: Paxton | last post by:
I created an html email containing a form whose method is POST. The form is posted to an asp page for processing, but no values are retrieved. So I response.write all the Request.Form fields, and nothing appears. I change the form's method to GET, then response.write the Request.QueryString items (which I can see in the URL) and it works fine. I need to use POST, as the quantity of data from the form will often exceed the limits of...
2
338
by: Martin Nadoll | last post by:
Hello, i try to submit a form with textlink like this snippet: <a href="javascript:document.bestellen.submit()">bestellen</a> <form name="bestellen" method="post" action="myPage.cfm?ID=4300&do=action"> <input name="category" type="hidden" value="2"> <input name="Product" type="hidden" value="423"> <input name="Price" type="hidden" value="15">
4
4578
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET forum). I don't use server controls in it (apart from Page). The problem occurs on the page where visitor can post a new messages. Basically, it's a form with couple of
2
1945
by: Cerebral Believer | last post by:
Hi folks, Can anyone help me with this form: http://futurebydesign-music.com/_member/club_fbd_reg.php I have followed to coding instructions aas closely as I can, but I am getting errors about not filling in all the fields on the form correctly when I test it. Is validating a form with radio buttons difficult?
16
2872
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the ass and the app will be used internally so I'm not too worried about users who aren't using javascript. I'm using the following javascript to detect whether or not they've hit enter: if(document.layers) {
10
6849
by: kelvin | last post by:
Hi, A difficult question. I have a form that I used to submit to https://www. paypal.com/cgi-bin/ webscr <form action="https://www. paypal.com/cgi-bin/webscr" method="post"> Now I need to validate some inputs of this form, so I submit it to a PHP page in my own server first.
0
9302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9067
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9007
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7941
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3154
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2101
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.