473,881 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having trouble or possibly i am just TOO stupid to understand

keyvanrahmadi
57 New Member
I have created a form which is as Follow:

[HTML]

<form action="fleet-of-car.php" method="post">
<br />SELECT A FORM TO SEE :
<select name="FORM">
<option value="ALL CARS"/>All Cars
<Option Value="CARS BY MANUFACTURER"/>CARS BY MANUFACTURER
<Option Value="CARS BY FUEL TYPE"/>CARS BY FUEL TYPE
</select>
<br />
<input type="submit" value="Show INFO" />
</form>
</select>

[/HTML]

Now what i am trying to achieve is as follow:

1: By submitting the first option in this case All cars, the form should connect to DB and run the query, which if i am not wrong is as follow:

[PHP]

<?php

//make a connection

mysql_connect(" server", "user", "password") ;
mysql_select_db ('db', $connection);

//Run the Sql
$results = mysql_query("SE LECT * FROM car
");

?>

[/PHP]

The question i have is, what happens if the user selcets option 2 or even 3? The query will be different since it will read from different Mysql table to get the result, but what is the script required for this type query.

I though by using IF(isset), i might get away with it but i am not too familiar with it and i have no idea even where to start, WHILE statement should do it but i am just getting more confused.

Any help would be great guys, and thx well in advance

keyvan
Feb 16 '07 #1
1 1204
Atli
5,058 Recognized Expert Expert
Hi.

If Im understanding you correctly, you would need to do something like this.

[PHP]
<?php

$option = $_POST['Name'];

// Find the selected option
if($option == "whatever")
{
$query = "SELECT * FROM table1";
}
else if($option == "somethingelse" )
{
$query = "SELECT * FROM table2";
}
// ....
else
{
$query = "";
}

// Run the query
if($query != "")
{
$DB = mysql_connect(" h", "u", "p") or die("omg it didnt work!");
mysql_select_db ("d", $DB) or die("aaah! so close!");

$result = mysql_query($qu ery) or die("<p>MySQL Error: <br />". mysql_error() ."</p>");

// Do something with results
}
else
{
// Error msg if the option is invalid
echo "Invalid option";
}

?>
[/php]

Hope this helps.
Feb 16 '07 #2

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

Similar topics

3
1860
by: Charles Krug | last post by:
List: I'm trying to use the example files from Programming Python, 2nd Ed. I've copied them into c:\Python24\Examples\PP2E. Launching any of the examples programs by themselves seems to work spiffily. Using regedit, I appended "c:\Python24\Examples\PP2E" to Pythonpath
6
1298
by: Jeremy Cowles | last post by:
Hi all, Disclaimer: This app is actually written in a different language, but I have much respect for this group & wanted to get your input so please ignore any minor syntactical errors. I have a program that needs to perform an action: Inventory Adjustment. This action takes several arguments: Data to describe which item to adjust:
14
2984
by: Gregory L. Hansen | last post by:
I can't seem to make a queue of objects, using the STL queue. I'm trying to make a little event manager, and I just want someplace to store events. The method definitions for EventManager have been commented away to nothing during debugging, but the headers look like class Event { private: Object* recipient; int eventID;
4
15633
by: 21novembre | last post by:
Hi all, I got a quite strange problem when I tried to setup a database backup shell. I put it this way: "bin/mysqldump --opt --user=xxx --password=xxx DB > DB.bak" However, error 1045 came to me to say "Access denied for user 'xxx'@'localhost' (using password: YES) when trying to connect". None the less, I'm absolutely full of confidence on my correct username and password, simply because if I do it this way: "bin/mysqldump --opt...
5
2515
by: Krumble Bunk | last post by:
Hello! First things first (but not necessarily in that order), this is a really great group, and has helped me understand more and more C everytime I read the postings, so thanks for a great learning environment! I am having difficulty understanding this bitwise macro (i've recently moved into working on these, using OpenSolaris source code - magnificent learning resource btw!)
16
1789
by: John Rivers | last post by:
http://www.15seconds.com/Issue/030812.htm?voteresult=1 poor guy worked his heart out, just to make a page control and then they published it ha ha ha ha ha to "help" others
18
2507
by: fishwick | last post by:
I haven't really done any css in quite a while, and am banging my head against the wall trying get the rudimentary layout together of a church website home page to display correctly - I don't want to continue work until I understand what I'm doing wrong. http://www.christchurchinfo.net The site displays nicely in Firefox/Mozilla and Safari, but the stained glass windows navigation portion is getting pushed down in IE, and the "news"...
2
2033
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my office computer (under Linux), but I have to write some code for the system simulator for the Cell BE processor (the thing inside the PS3), which is apparently a PPC architecture, and I can't get the clock function to
39
3592
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody out there understands what happens. Essentially, when I subtract the (double) function value GRID_POINT(2) from a variable which has been assigned the same value before this gives a non-zero result and I really do not understand why.
0
9926
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11095
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...
0
10399
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
9552
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
7952
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
5780
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
4597
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
3
3223
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.