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
https://forums.phpfreaks.com/topic/167362-defining-a-variable-in-php-from-mysql/
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'];

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.