MySQL select ID instead Name!

[FONT=Book Antiqua]Hi folks,

I am getting very excellent inofmration from you guys so thank you for greate cooperation

I have a input field that contains drop down menu selected from my db MySQL, when submitting this form it will show url based on entry becomes from input submited as characters.

I need url to be id or digits based on MySQL DB.

MySQL table structure:



CREATE TABLE items (
  id int(11) NOT NULL AUTO_INCREMENT,
  Mainstore varchar(255) DEFAULT NULL,
  company varchar(255) DEFAULT NULL,
  Location varchar(50) DEFAULT NULL,
  Description longtext,
  location longtext,
  `Status` varchar(255) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

Url depending on company column is like this shop.php?company=testcompany

Instead of showing testcompany i need id which is shown in table structure.

SQL query:

$query="SELECT * FROM items where company=\\"$_GET[system]\\"  LIMIT 1";

Thak you so much for greate support.

Regards,[/FONT]

So why don’t you just edit your sql query to extract the information you need. If you wrote all that code then it shouldn’t take you more than a couple of minutes at the most.

hi,

in your select box, you would populate the select “value” with the id of the company not the name.

your url can then be shop.php?company=id

i also suggest you validate your $_GET variable before inserting into your mysql query.

hope i understand your question… cheers.

Thank you for cooperation.

But can you explain by example… please.

Thank you so much.

Would you mind supporting me in validating method.

Thanx.

If you need an example, then it’s highly probably you didn’t write the code you posted and you simply want someone to fix it for you for free.

There are plenty of examples of what you are trying to do on the www. Let :google: be your friend :slight_smile:

[FONT=Century Gothic]In this case mysql_real_escape_string might support me?

I am still learning MySQL and i 'm not expert like you!!!;)[/FONT]

You are trying to sprint before you can jog, let alone walk.

mysql_real_escape_string() has nothing to do with what you asked for in your first post.

My suggestion is to take a couple of steps back. Set up your <form> to prompt the user for the inputs you need. Then when the submit button is clicked to send the form data to your php script, first ensure the form data is being received correctly by the script by echoing the form data at the top of the script…ie…echo $_POST[‘someFormInput’];

When you are sure all the form data is being received correctly by the php script, then worry about validating it and processing it however you need.