I'm trying to extract data from a mysql database, but can't seem to get it to work. I've read tons of books on how to do it, researched online, read through tons of forums, and even watched about 20 YouTube videos all using the same example where a user Selects all the information from a table. In more ideal projects developers WONT want to only select all the information in a given table using a while loop. It's driving me crazy. This is what I have so far.
$query = "SELECT SUM( product_quantity )
FROM confirmed_orders WHERE product_id ='$custom[3]'
AND order_status = 'S'";
$result = mysql_query($query);
$value = mysql_result($result);
echo $value;
$custom[3] is an object of an array that a user inputs. I'm not sure if that's how you insert a variable into a MySQL query or not though. I come from a Visual Basic world. In short I'm just trying to add up the values of a column and retrieve the answer from MySQL using PHP to echo out to the user. When I visit my webpage I get a blank page. When I run the query in PHPAdmin everything works so fine so I'm left to believe the issue is retrieving the data. And I dont want to retrieve it as an array since there's only one answer, so loops shouldn't be necessary.
Well actually I'm using Joomla! so when I started my code I started it just by referencing the already existent connection to the database. I then copied and pasted your code and the webpage returns nothing where the value is supposed to be displayed. The entire sites loads, but where the PHP code and query is there's nothing.
I copied the database to my local machine. I'm using WAMP Server for Windows 7. I used the username: ROOT, database name is DATABASE, NO PASSWORD , and host name is LOCALHOST. The error message I get is from the MySQL parser: Unable to select database: Access denied for user ''@database to database 'usonomics'. I also made sure everything was lowercase. I then made a small script to connect to the database and perform the same query and still nothing. Here's the query I'm running from a script on my local machine.
$db_hostname = 'localhost';
$db_database = database;
$db_username = 'root';
$db_password = '';
$db_server = mysql_connect($db_database);
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
//add the total products order
$query = "SELECT SUM( product_quantity )
FROM confirmed_orders WHERE product_id ='$custom[3]'
AND order_status = 'S'";
$result = mysql_query($query);
if( $result === false )
die('Invalid query: ' . mysql_error());
else
$
$query = "SELECT SUM( product_quantity )
FROM confirmed_orders WHERE product_id ='$custom[3]'
AND order_status = 'S'";
$result = mysql_query($query);
$value = mysql_result($result);
echo $value;
$custom[3] is an object of an array that a user inputs. I'm not sure if that's how you insert a variable into a MySQL query or not though. I come from a Visual Basic world. In short I'm just trying to add up the values of a column and retrieve the answer from MySQL using PHP to echo out to the user. When I visit my webpage I get a blank page. When I run the query in PHPAdmin everything works so fine so I'm left to believe the issue is retrieving the data. And I dont want to retrieve it as an array since there's only one answer, so loops shouldn't be necessary.
Well actually I'm using Joomla! so when I started my code I started it just by referencing the already existent connection to the database. I then copied and pasted your code and the webpage returns nothing where the value is supposed to be displayed. The entire sites loads, but where the PHP code and query is there's nothing.
I copied the database to my local machine. I'm using WAMP Server for Windows 7. I used the username: ROOT, database name is DATABASE, NO PASSWORD , and host name is LOCALHOST. The error message I get is from the MySQL parser: Unable to select database: Access denied for user ''@database to database 'usonomics'. I also made sure everything was lowercase. I then made a small script to connect to the database and perform the same query and still nothing. Here's the query I'm running from a script on my local machine.
$db_hostname = 'localhost';
$db_database = database;
$db_username = 'root';
$db_password = '';
$db_server = mysql_connect($db_database);
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
//add the total products order
$query = "SELECT SUM( product_quantity )
FROM confirmed_orders WHERE product_id ='$custom[3]'
AND order_status = 'S'";
$result = mysql_query($query);
if( $result === false )
die('Invalid query: ' . mysql_error());
else
$