Jump to content

Defining a variable in php from MYSQL


bryanosaurus

Recommended Posts

I will preface this by saying I am not very familiar with MYSQL at all, but need it for the current project I am working on.

 

What I want to do is, I have a variable coming into a php page, which is the name of a row in my DB. This variable is specifically defined from the page before, so it's choosing a row based on the link previously clicked. Now what I need is for mysql to read that row, and then define a variable from another column in that row, so that I can use it later -- further down in the script I am using php to send an email.

 

Maybe I can explain it better... example if a user clicks a certain product, i need to look for that product in the db, find the inventory value of it, and then insert that value in a script that is sending out an e-mail.

 

I don't know if this makes any sense, or is even possible, any help would be appreciated.

Link to comment
Share on other sites

I imagine the value is being pass over via url.

 

$name= $_GET['name'];

$result mysql_query("SELECT current_value FROM inventory WHERE name='" . $name . '");
$list = mysql_fetch_array($result);
$value= $list['current_value'];

 

if you are posting it then you simple change it to $_post

 

$name = $_POST['name'];

Link to comment
Share on other sites

to furthur explain, the main difference between GET and POST variables is that a GET variable will be displayed in the address bar i.e.:

http://example.com?var1=xxx&var2=yyy

 

whereas a POST variable is not as public and does not appear in the address bar.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.