[PHP] Object Undefinded index
I am just learning to use objects. I am messing around with a shopping cart object, but am having confusing problems. I am getting an undefined index error when trying to assign a key value pair to an array variable within an object. I am confused becuase I believe this is how you assign array variables outside an object. It acts like the variable is undefined. Thanks for the help. Steve Turner //-- class Cart { var $items; // Items in shopping cart // Add $quantity articles of $product_id to the cart function add_item ($product_id, $quantity = 1) { $this->items[$product_id] += $quantity; } // Take $quantity articles of $product_id out of the cart function remove_item ($product_id, $quantity) { if ($this->items[$product_id] > $quantity) { $this->items[$product_id] -= $quantity; return true; } else { return false; } } } //I am interacting with the object with the following code $cart = new Cart; $cart->add_item("10", 1); foreach ($cart as $product_id => $quantity) { echo $product_id . "" . $quantity; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] scalar value as array problem
I have a frustrating problem. I have a shopping cart class that creates session variable arrays to store the product_id and quantity. My development machine is running windows 2000 with PHP 4.3.3 and my script is working perfectly on my machine. When I upload to the remote host running FreeBSD and PHP 4.3.2 I am getting errors. I believe I am having problems with assigning the array values, and this is causing other problems. I am using this statment to assign $_SESSION['cart']['product_id'] with the quantity using a class with the add_item property. $cart->add_item($_GET['product_id'], $_GET['quantity']); I am getting this error. Warning: Cannot use a scalar value as an array in /home/designor/public_html/class.php on line 14 Warning: Cannot use a scalar value as an array in /home/designor/public_html/class.php on line 16 I have no idea what a scalar value even is. I did verify that my form was passing the values by using echo $_GET['product_id'] . $_GET['quantity']; Your help is much appreciated, as I am still a beginner. Steve Turner -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] function array problems
Hi, Having some problems with multi-dimentional arrays. I am creatng an array using some database data, and adding stuff like an image tag, and hyperlink. Then passing this to another function that creates an Html table from an array. Here is the function to create the table from an array, seems to work fine. //- // Builds transparent table from array function trans_table_array ($array, $bodyfontcolor = "", $headerfontcolor = "") { global $theme_bodyfontcolor, $theme_headerfontcolor;// Defined in a theme file // Poputlate with theme colors if called without specifying if ($bodyfontcolor == "") $bodyfontcolor = $theme_bodyfontcolor; if ($headerfontcolor == "") $headerfontcolor = $theme_headerfontcolor; $content = "\n"; foreach ($array as $rowkey => $colkey) { $content .= ""; foreach ($colkey as $value) { if ($rowkey=="0") // Treat first row as column names { $content .= "" . $value . "\n"; } else { $content .= ""; if (!isset($value)) //test for null value {$content .= "NULL";} else {$content .= "" . $value . "";} $content .= "\n"; } } $content .= "\n"; } $content .= ""; return $content; } // I use this function to get the whole database results into an array, passing the result of a query //- function mysql_fetch_array_r($result, $fetch = MYSQL_BOTH) { $row_counter = 0; while ($row = mysql_fetch_array($result,$fetch)) { $whole_result[$row_counter] = $row; $row_counter++; } return $whole_result; } //-- Then I am trying to build a table with 3 pictures per row. $query = "Select * from picture"; $result = mysql_query($query) or die (mysql_error()); // Returns array with entire contents of query $whole_result = mysql_fetch_array_r($result); $col_key = 0; foreach ($whole_result as $rowkey => $colkey) { $table_string = " {$whole_result[$rowkey]['path']}"; $table_array[$rowkey][$col_key] = $table_string; // 3 $table_string per row in table if ($col_key< 2) { $col_key++; } else { $col_key=0; } } echo trans_table_array($table_array); The above is not populating the array correctly. It results in one $table_string per row instead of column. Am I just simply making a logic error. This multi-dimentional array stuff is confusing, been struggling with this for hours. Does anyone else have a simpler way of seperating logic, and html? Thanks for any help.
[PHP] Uploaded Picture Name
I am having a slight problem with a picture upload script. I seems to work just fine except when the picture name has an apostrphe in the name. How do all of you deal with this problem. Do you just rename the file to something else when you upload it. Here is the script that I am using. It is called from a form using multipart/form-data. Thanks for the help. displayHeader("File Uploaded"); printf("Uploaded File Details"); printf("Name: %s ", $_FILES["photo"]["name"]); printf("Temporary Name: %s ", $_FILES["photo"]["tmp_name"]); printf("Size: %s ", $_FILES["photo"]["size"]); printf("Type: %s ", $_FILES["photo"]["type"]); if (copy($_FILES["photo"]["tmp_name"],"{$GLOBALS['IMAGE_DIR']}/{$_FILES['photo' ]['name']}")) {printf("File successfully copied");} else {printf("Error: failed to copy file");} // Put picture path into database and assosiate with a product $query = "insert into picture (product_id, path) values ( {$_POST['product_id']}, '{$GLOBALS['IMAGE_DIR']}/{$_FILES['photo']['name']}' )"; mysql_query($query) or die (mysql_error()); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Session Link Problems
Hi, I am having a problem with sessions. On my testing machine my script works perfectly. However on the remote server it tries to pass the session id in the url even though I am accepting cookies. It is messing up all my links since it puts PHPSESSID=6a4626fc1cde0fb228fcb3ebe5587ffd in front of my hrefs without an & after. If I click the link then it registers the session as a cookie and everything works fine from there on out. Don't understand what is happening as everyting used to work fine, and I don't think I changed anyting. Don't know how well I described this. Take a look if you are confused. The link to the site is http://www.designoriginalsbykim.com. Thanks for any help you may be able to give. Steve Turner Fort Collins, CO http://www.SteveOnWeb.com The session part of phpinfo() is session Session Support enabled Registered save handlers files user Directive Local Value Master Value session.auto_start Off Off session.bug_compat_42 On On session.bug_compat_warn On On session.cache_expire 180 180 session.cache_limiter nocache nocache session.cookie_domain no value no value session.cookie_lifetime 0 0 session.cookie_path / / session.cookie_secure Off Off session.entropy_file no value no value session.entropy_length 0 0 session.gc_divisor 100 100 session.gc_maxlifetime 1440 1440 session.gc_probability 1 1 session.name PHPSESSID PHPSESSID session.referer_check no value no value session.save_handler files files session.save_path /tmp /tmp session.serialize_handler php php session.use_cookies On On session.use_only_cookies Off Off session.use_trans_sid On On -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php