-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
Baffled about Line 2 Error Message in simple script
mac_gyver replied to FreakingOUT's topic in MySQL Help
notepad and certainly wordpad are NOT programming editors. there are a number of free programming editors, such as notepad++ - http://notepad-plus-plus.org/ the duplicate entry error is because you are inserting a duplicate value in a column that's defined as the primary key for your table. you shouldn't be providing a value at all for a primary index, it should be an autoincrement value supplied by the database itself. -
Baffled about Line 2 Error Message in simple script
mac_gyver replied to FreakingOUT's topic in MySQL Help
does the posted code start at line one of the file or is there any sort of html/xml markup before that point? are you using a dedicated programming editor or some other means of creating/editing files? are you FTP'ing this file to your server or what? i would create a new empty file with just an opening php tag and see if it produces any errors when you request it (this could be a broken php installation.) -
because the error is occurring at the mysql_query statement, it means that your actual database connection code isn't making a connection or isn't running at all or your code has closed the connection at some point and php is trying to make a connection for you using default database credentials (which are rarely setup at all.) you will need to determine what's happening with your actual database connection/code.
-
posting the actual error message (and where it is occurring at - php code, database log files...), what limit you changed, what the limit was, and what you changed it to, would help.
-
Baffled about Line 2 Error Message in simple script
mac_gyver replied to FreakingOUT's topic in MySQL Help
errors like this are typically caused by copy/pasting code that was 'published' using a non-ascii character set and the characters may display correctly on a web page, but in the actual .php source code they aren't what they appear to be. i would delete and RETYPE the first two lines in your file. also, the posted code contains a php syntax error starting at about line 17. are you sure that's the actual file being saved/put onto your server that the first error is occurring in? -
Please use the forum's bbcode tags (the edit form's <> button) around your code when posting it. i edited your post above, but you have nearly 50 posts and should know how to use the features specific to a coding forum.
-
i recommend that you read all of the relevant php version migration sections in the php documentation so that you are aware of what has changed in php over time that will affect your code - http://us3.php.net/manual/en/appendices.php
-
it sounds like you know the table name and column name. you can use php to dynamically provide the database name in the update query - $database = .... value gotten by looping over the result from the SHOW DATABASES query $query = "UPDATE `$database`.table_name SET pass = 'XXXXX' WHERE pass = 'YYYYY'";
-
using an aggregate function in a where clause produces a query error (Invalid use of group function) because the function operates on values that are in the result set, but the where clause is what is selecting which rows are in the result set.
-
there are no wild-card/ALL database/table/column commands. you would need to use a SHOW DATABASES query to get a list of all the databases on the server. you could then loop through that list and use each database name to get the list of tables in each database using a SHOW TABLES query. then use a SHOW COLUMNS query to get a list of all columns within each table within each database.
-
Making a variable name with partial use of another variable
mac_gyver replied to Phaelon's topic in PHP Coding Help
no one here really wants to see code you got at another help site. btw - that code is three times slower than the method i suggested, which is just one of the problems with using variable variables. -
the most straightforward method would be to use usort() - http://us3.php.net/usort and write a function that compares the 'Number' elements of the arrays. another method would be to use array_multisort()
-
Making a variable name with partial use of another variable
mac_gyver replied to Phaelon's topic in PHP Coding Help
making a series of numbered variables creates a nightmare of extra code. you need to use a simple array - $option[1], $option[2], ... -
your data should have a unique identifier (id) assigned to them in your database table (using a autoincrement index column.) when you display the data, each item you display would carry it's unique id (not sure if you are using links or a form.) when the data is submitted you would use that id to record the vote, so two songs with the same title and different artists would have two different id's, but the id that the visitor picked and submitted, based on the song/artist they see, would tell you which one they voted for.
-
Simple shopping cart not working - undefined index
mac_gyver replied to CherryLips's topic in PHP Coding Help
your form field is named qty. you must use the same exact name (capitalization) in your php code - $_POST['qty'] -
Properly closing a PDO connection in a function
mac_gyver replied to Strahan's topic in PHP Coding Help
better, yes, but don't use the global keyword. pass the connection in as a runtime parameter - function dosomething($pdo) { stuff } -
Properly closing a PDO connection in a function
mac_gyver replied to Strahan's topic in PHP Coding Help
you should NOT open a database connection, run one query, then close the database connection. you should open one database connection in your main application code and pass it into any function/class that needs it, then close it after you are finished using it or let php close it automatically when your script ends. to answer your question though, the return statement ends execution of the function code. this causes all variables that are local to the function to be destroyed (unless you defined them as static.) this destroying of the local $pdo variable should cause the connection to be closed regardless of if your $pdo=null; statement gets executed (your second code example) or not (your first code example.) -
start by looking at line 10 and work your way backwards - $stmt = $con->prepare($query); the error means that $con isn't an object. where is $con defined and are you sure it is defined and contains what you expect?
-
i'm not sure if there's a question or problem, but the definition of your session cart variable needs to be both simplified and expanded. 1) you need to use the item_id as an index for the cart array, so that finding or modifying the contents of the cart can be done directly using the item_id. this will eliminate the need to loop through all the cart contents when adding/removing items. this also makes it possible to get all the item_id's at once (see array_keys()) when displaying the cart so that you don't need to run a database query inside of a loop. 2) since it would be possible to have more than one instance of an item_id in the cart (different genders, sizes, colors), you should use those values to create an addition composite array index (see example code below.) 3) you need to filter/validate all external data before using it. 4) unless you are planning on shipping each item separately, the shipping choice should be after the items have been added to the cart, not for each item. 5) the html of your product page is all over the place. the only hidden field should be the pid/item_id. the other hidden fields don't belong. the field names for the gender, size, color.. should be meaningful names. your <option> lists all need closing </option> tags. you need to assign meaningful and distinct values for each option. an example of what the 'add to cart' code would look like using items #1 and #2 in my list (this assumes your select menus have full names for the data they submit) - if (isset($_POST['pid'])){ // you need to filter/validate all external data before using it (the following is just copying data for demo purposes) $pid = $_POST['pid']; $gender = $_POST['gender']; $size = $_POST['size']; $color = $_POST['color']; $composite_key = "$gender|$size|$color"; if(!isset($_SESSION['cart'])) { $_SESSION['cart'] = array(); // create cart if needed } if(!isset($_SESSION['cart'][$pid])) { $_SESSION['cart'][$pid] = array(); // create item if needed } if(!isset($_SESSION['cart'][$pid][$composite_key])) { $_SESSION['cart'][$pid][$composite_key] = 0; // create options if needed, qty zero } $_SESSION['cart'][$pid][$composite_key]++; // add to quantity header("location: cart.php"); exit(); }
-
yes. i would just submit all the final select option values and update the 'RowOrder' values to match the order in which they are in the submitted data.
-
the example i give was so that the small image could be clicked on and displays the larger image. your code already has a link to the product.php?id=' . $id . ' page around the smaller image. so, the question becomes, what issue are you having in the product.php code that you need help with?
-
any image files you previously uploaded before you changed the line in the code are already named xx.jpg. you will need to physically rename them to xx.png or delete them and start over. to LINK to a second larger image, you would use the smaller .png image as the content in a LINK - <a href='xx.jpg'><img src='xx.png' alt=''><a>
-
Reflecting Database Info on the Members Page
mac_gyver replied to gordonp's topic in PHP Coding Help
lol, this is an older thread that Azerex bumped and the OP never returned to this site after the moment he started/edited the first post in the thread. -
that's what your code is naming the file when you upload it - $newname = "$pid.jpg"; if the file is always going to be .png, change that line of code to use .png. if the file can be any image type, your code will need to get the file extension from the uploaded image information and use it when naming the image file.
-
it would help if you posted your actual query and your complete code (something tells me based on the changing where clause in one of the other php help sites where you have also posted this, that you actually have code that's running a query and then running another query inside of a loop.)