Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2005, 10:05 AM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting Array Error message with Begin PHP4 Ch 13

Getting:

Warning: array_push(): First argument should be an array in c:\inetpub\wwwroot\enum_options.php on line 16
ENUM options with the default value:


Warning: array_pop(): The argument should be an array in c:\inetpub\wwwroot\enum_options.php on line 23
ENUM options without the default value:

Anyone have ideas?


 
Old April 14th, 2005, 06:25 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Perhpas if you show us a bit of the code...

 
Old April 15th, 2005, 01:54 PM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<?php
//enum_options.php
include "./common_db.inc";
$link_id = db_connect();
mysql_select_db("sample_db");

$query = "SHOW COLUMNS FROM user LIKE 'usercountry'";
$result = mysql_query($query);
$query_data = mysql_fetch_array($result);

if(eregi("('.*')", $query_data["Type"], $match)) {
   $enum_str = ereg_replace("'", "", $match[1]);
   $enum_options = explode(',', $enum_str);
}

array_push($enum_options, $query_data["Default"]);

echo "ENUM options with the default value:<BR>";
foreach($enum_options as $value) echo "-$value<BR>";

echo "<P>";

array_pop($enum_options);

echo "ENUM options without the default value:<BR>";
foreach($enum_options as $value) echo "-$value<BR>";
?>


 
Old April 15th, 2005, 01:55 PM
Registered User
 
Join Date: Apr 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

<?php
$dbhost = 'localhost';
$dbusername = 'phpuser';
$dbuserpassword = 'phppass';
$default_dbname = 'sample_db';
$default_sort_order = 'ASC';
$default_order_by = 'usernumber';
$records_per_page = 5;
$user_tablename = 'user';
$access_log_tablename = 'access_log';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
$new_win_width = 600;
$new_win_height = 400;


function html_header() {
   global $new_win_width, $new_win_height;
   ?>
   <HTML>
   <HEAD>
   <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
   <!--
   function open_window(url) {
      var NEW_WIN = null;
      NEW_WIN = window.open ("", "RecordViewer", "toolbar=no,width="+<?php echo $new_win_width ?>+",height="+<?php echo $new_win_height?>+",directories=no,status=no,scrol lbars=yes,resize=no,menubar=no");
      NEW_WIN.location.href = url;
   }
   //-->
   </SCRIPT>
   <TITLE>User Record Viewer</TITLE>
   </HEAD>
   <BODY>
   <?php
}

function html_footer() {
?>
</BODY>
</HTML>
<?php
}

function db_connect($dbname='') {
   global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
   global $MYSQL_ERRNO, $MYSQL_ERROR;

   $link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
   if(!$link_id) {
      $MYSQL_ERRNO = 0;
      $MYSQL_ERROR = "Connection failed to the host $dbhost.";
      return 0;
   }
   else if(empty($dbname) && !mysql_select_db($default_dbname)) {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
      return 0;
   }
   else if(!empty($dbname) && !mysql_select_db($dbname)) {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
      return 0;
   }
   else return $link_id;
}

function sql_error() {
   global $MYSQL_ERRNO, $MYSQL_ERROR;

   if(empty($MYSQL_ERROR)) {
      $MYSQL_ERRNO = mysql_errno();
      $MYSQL_ERROR = mysql_error();
   }
   return "$MYSQL_ERRNO: $MYSQL_ERROR";
}

function error_message($msg) {
   html_header();
   echo "<SCRIPT>alert(\"Error: $msg\");history.go(-1)</SCRIPT>";
   html_footer();
   exit;
}

function enum_options($field, $link_id) {
   $query = "SHOW COLUMNS FROM user LIKE '$field'";
   $result = mysql_query($query, $link_id);
   $query_data = mysql_fetch_array($result);
   if(eregi("('.*')", $query_data["Type"], $match)) {
   $enum_str = ereg_replace("'", "", $match[1]);
   $enum_options = explode(',', $enum_str);
   return $enum_options;
} else return 0;
}
?>

 
Old April 17th, 2005, 04:37 PM
Authorized User
 
Join Date: Apr 2005
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

print_r($enum_options) before the call to array_push() and end the script. Ensure that $enum_options is indead an array.

Everything is temporary, some things are just more temporary than others... except for death, that seems to be pretty permanent





Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 13 of php4, user_auth.php Exitus BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 3 August 5th, 2004 09:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.