Jump to content

PHP and MySQL HELP

Go to solution Solved by santsys,

mysql_query returns a result set, not an individual value... so you have to process the value like you are in the other areas.

$result = mysql_query($query);if (!$result) {    die("No result");}$row = mysql_fetch_assoc($result);$customerId = $row['CustomerID'];

http://php.net/manual/en/function.mysql-query.php

So i am having trouble displaying info from a sql database, i have got the invoice info to work however cant get the customers info to display, below is the code, the parts highlighted in red are the bits of code which i believe to be incorrect. would appreciate any help anyone can give as i need to get this up and running ASAP for my business. Thanks All!

 

EDIT: cant colour the code sorry, basically trying to assign the &customerID variable at the top, and the last function at the bottom to display

<?phpinclude('includes/functions.php');$id = $_POST['id'];$customerID = mysql_query("SELECT CustomerID FROM invoices WHERE ID = '" . mysql_escape_string($_POST['id']) . "';") or die(mysql_error());function getInvoiceInfo()  {	$query = mysql_query("SELECT * FROM invoices WHERE ID = '" . mysql_escape_string($_POST['id']) . "';") or die(mysql_error());	if(mysql_num_rows($query) == 0) {		echo "<tr><td colspan=\"7\"><div class=\"\alert alert-danger\"\ role=\"\alert\"\><center>Invoice could not be found</center></div></tr></tr>";	} else {	while($invoices = mysql_fetch_assoc($query)) {		echo "<p>Invoice ID: " . $invoices['ID'] . "</p><p>Date: " . $invoices['Date'] . "</p><p>Description: " . $invoices['Description'] . "</p><p>Cost: £" . $invoices['Cost'] . "</p>";	}}	}function getCustomerInfo()  {	$query = mysql_query("SELECT * FROM customers WHERE ID = '$customerID';") or die(mysql_error());	if(mysql_num_rows($query) == 0) {		echo "<tr><td colspan=\"7\"><div class=\"\alert alert-danger\"\ role=\"\alert\"\><center>Customer could not be found</center></div></tr></tr>";	} else {	while($customers = mysql_fetch_assoc($query)) {		echo "<tr><td>" . $customers['ID'] . "</td><td>" . $customers['Name'] . "</td><td>" . $customers['Address'] . "</td><td>" . $customers['Phone'] . "</td><td>" . $customers['Email'] . "</td></tr>";	}}	}?>
Link to comment
https://linustechtips.com/topic/439897-php-and-mysql-help/
Share on other sites

Link to post
Share on other sites

mysql_query returns a result set, not an individual value... so you have to process the value like you are in the other areas.

$result = mysql_query($query);if (!$result) {    die("No result");}$row = mysql_fetch_assoc($result);$customerId = $row['CustomerID'];

http://php.net/manual/en/function.mysql-query.php

Link to comment
https://linustechtips.com/topic/439897-php-and-mysql-help/#findComment-5898057
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×