Jump to content
Larry Ullman's Book Forums

Virtual Store Registration - Form_Functions Script


Recommended Posts

I want to add select menus to the registration form within the form_functions script, using data retrieved from the database instead of hard coding them. I tried the code included below after l looked at the form_function script for the coffee site, but get the following errors:

 

Warning: print_r() [function.print-r]: Couldn't fetch mysqli_result in C:\xampp\htdocs\site\includes\config.inc.php on line 69

Warning: print_r() [function.print-r]: Property access is not allowed yet in C:\xampp\htdocs\site\includes\config.inc.php on line 69

 

The "require Config and MySQL" are contained in the header.

 

} elseif ($type == 'select') { // Create a select menu.

if (($name == 'timezone')) { // Create a list of timezones.
// Retrieve the timezones.
$q = "SELECT timezone_id, timezone FROM timezones ORDER BY timezone ASC";
$r = mysqli_query ($dbc, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
 echo "<option value=\"$row[0]\"";
}
$data = $r;
// Free the results:
mysqli_free_result($r);

 

Thank you in advance.

Link to comment
Share on other sites

I have now also included config.inc and MYSQL function, although they are also included in the header as previously mentioned.

 

I still get the following error: An error occurred in script 'C:\xampp\htdocs\site\includes\form_functions.inc.php' on line 75:

Undefined variable: dbc

 

Below the revised code:

 

} elseif ($name == 'timezone') { // Create a list of time zones.

// Retrieve the timezones.
require_once ('includes/config.inc.php');
require_once (MYSQL);

$q = "SELECT timezone_id, timezone FROM timezones ORDER BY timezone ASC";
$r = mysqli_query ($dbc, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
 echo "<option value=\"$row[0]\"";
}
$data = $r;
// Free the results:
mysqli_free_result($r);

Link to comment
Share on other sites

Then the function still doesn't have access to the variable, as you can see by the error message. Including the scripts a second time isn't good or right. You'll need to pass the $dbc variable to the function call or make it global.

 

By the way, this book does assume complete comfort with PHP and MySQL. I worry you're going to struggle with some of the more advance stuff later on.

Link to comment
Share on other sites

Hi Larry. Thank you for your reply. In chapter 11 (Site Administration) you exclude database queries from the the form_function and explain why. I have decided to exclude them too.

 

I will go through PHP & MySQL for Dynamic Websites again to brush up.

 

Kind regards,

 

Jacques

Link to comment
Share on other sites

 Share

×
×
  • Create New...