Need help with some php code :)

Posted on 16th Feb 2014 by admin

Hey! I'm quite new to this whole thing, so please don't fire me with shait on this one =D

I'm trying to learn PHP and MySQL, and atm I am trying to make a website which corresponds with a database - a database with customers.

I managed to make the page show all the customers in the database - with first- and surname.

I want each of these customers to be clickable - when you click a customer, it shows all the information about that customer which is stored in the database.

So far I have managed to make them clickable, but I don't know how to make it so that the click posts all the associated information about that customer on the page..

I can post some of the stuff I tried out with, but I'm not good with PHP (yet! =D), and therefore I got stuck quite early... but here's some of the stuff I've done so far..


Code: <?php
// Connect to the database server
$dbcnx = @mysql_connect('localhost', 'root', 'password');
if (!$dbcnx) {
exit('<p>Unable to connect to the database server at this time.</p>');
}

// Select the database
if (!@mysql_select_db('customerdb')) {
exit('<p>Unable to locate the database at this time');
}

?>

<p>Here are all the customers:</p><br />

// Request data from the database
$customers = @mysql_query('SELECT * FROM customers');
if (!$customers) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}

while ($row = mysql_fetch_array($customers)) {
$customerID = $row['kundeID'];
$customer_forename = $row['forename'];
$customer_surname = $row['surname'];
echo '<p>' . $customer_forename .
$customer_surname .
' <a href="' . $_SERVER['PHP_SELF'] .
'?showcustomer=' . $customerID . '">' .
'customer details</a></p>';
}

?>

Thanks!

Other forums