-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Once you change the quantity form field to use an array name, your $_POST array will end up looking like the following (the 123,124,23,24 are some made up product id's) - Array ( [quantity] => Array ( [123] => 1 [124] => 3 [23] => 2 [24] => 1 ) [ProceedToCheckout] => Proceed to Checkout ) Your echo statement(s) on the treats.php page would be - echo '<tr><td width="200px"><img src="'.$row['product_pic'].'" /></td><td width="200px"><b>'.$row['product_title'].'</b><br />'.$row['product_Description'].'<br /> Price: $'.$row['price'].$row['pricePer'].'<br /><br />Quantity <input name="quantity['.$row["product_id"].']" type="text" size="2" /></td></tr>'; On your treats.php page, you should have all your products in ONE table with a product category/type column. You retrieve the products in the order that you want them and simply output a new heading when the category/type column changes. You will greatly simplify your code (only one query.)
-
The biggest problem is that you don't have a POST field named 'quantity'. You are making a series of POST fields named 'quantityID', where the ID is each product id. You should instead use an array name for your field - name = 'quantity[ID]' Once you use an array name, you can test if $_POST['quantity'] is set or if it is an array (currently you can do neither.)
-
That's not how functions should produce values and make them available to the code that calls the function. Please read my replies in the following thread - http://www.phpfreaks.com/forums/index.php?topic=358171.0
-
LOL
-
I can think of at least 6 different things that would prevent a class definition from being seen in a file. If you want someone here to help determine why, you would need to post your installer.php file, showing the opening php tag through to the start of that class definition, especially since you implied two different spellings for the class name in your post.
-
Array_unique is not working because you are storing the array that mysql_fetch_assoc returns into your main array, not just the CBSA_Name value out of the array.
-
You can do this all directly in your query - $csaname_sql = "SELECT DISTINCT CBSA_Name FROM ZIPCodes WHERE ZipCode IN ('".implode("','",$invitation_Zipcodes)."')"; There's almost never a time when you should put a SELECT query inside of a loop, due to the performance hit you take. There is always a way to get one query to retrieve all the rows you want at one time.
-
I think it would be best (and quickest) if you posted everything from where your UPDATE query is being formed through to the end of the else {echo "nothing affected";} logic. I suspect you have more than one database connection and you are executing a query using one connection and testing the mysql_affected_rows() on a different connection. And why not simply refer to the query as $query? There's no need to specifically use variable names like $insert_query, especially if you are not going to rename them to what the query actually is to avoid confusion when you don't post all the relevant code at once.
-
GROUP BY consolidates all the rows having the same GROUP BY value into one single row. That's not what you want. You need your query to retrieve the rows you want in the order that you want them. To output a new name/title/heading when it changes value, you simply detect when the column value changes. See the following post - http://www.phpfreaks.com/forums/index.php?topic=348604.msg1644964#msg1644964
-
The line right after that - if (isset($value['/src/'])) { is trying to find first level array keys named '/src/' to distinguish between file entries and directories. You will note that the first level array keys at that point are the file names and that the '/src/' key is one more nested level inside each array. As already stated, it appears that the the name="..." attribute is supposed to be just the name and that the folder="..." attribute is supposed to contain any path information. You need to remove the hacked code that adds the raw path value into the name="..." attribute. Then, when you iterate over the .xml data, you should read the folder="..." attribute and store that into the $items array.
-
You likely have more than one database.php file and the one that is in the folder with your main file is the one that is being included. The one in the include folder where your session.php file is at, is not the one that is being include.
-
Session variables are completely separate for each visitor's browser.
-
You would add columns to your database `user` table to keep track of the count of failed log in attempts and the date/time when the account was locked out.
-
<?php $colors = array('yellow','red','blue','green'); // define enough colors for the number of different tank names $fake[] = array('tank_name'=>'Tank 1'); // some fake data for demo purposes - actual data retrieved from database query $fake[] = array('tank_name'=>'Tank 2'); $fake[] = array('tank_name'=>'Tank 3'); $fake[] = array('tank_name'=>'Tank 2'); $fake[] = array('tank_name'=>'Tank 2'); $fake[] = array('tank_name'=>'Tank 1'); $color = 0; // start at the first available color $used = array(); // remember which colors have been used for each value echo "<table>"; foreach($fake as $row){ // your while loop would replace this line if(!isset($used[$row['tank_name']])){ // no color exists for this tank name, assign it $used[$row['tank_name']] = $colors[$color++]; } $bg = $used[$row['tank_name']]; // get the color assignment for the tank name echo"<tr bgcolor='$bg'><td>{$row['tank_name']}</td></tr>"; } echo "</table>";
-
Here's the operator precedence table, which shows why you have to force the ||'s to be evaluated together before the && (&& has higher precedence than ||) - http://us2.php.net/manual/en/language.operators.precedence.php
-
The person writing that was probably unsure of the operator precedence and wanted to make sure it worked. The only () needed are those around the group of ||'ed values (which itself can be simplified, see below) - <?php if (($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpeg" || $_FILES["file"]["type"] == "image/pjpeg") && $_FILES["file"]["size"] < 20000){ However, there are other problems with that logic (which probably came from the w3schools.com upload example). When validating user supplied input, you should never lump together tests and output a generic 'sorry, you did something wrong' message. You should validate everything about the user supplied input and specifically tell the user what was wrong with his input (provided telling him isn't a security issue.) If it was the wrong mime type, tell him what the mime type was that he submitted and what the valid types are. If there is something wrong with the size of the file, tell him what size he uploaded and what the valid size range is. Also, for that code, when you are testing if a value is one of several possible values, you should make an array of the acceptable values and use an in_array statement - <?php $allowed_types = array("image/gif","image/jpeg","image/pjpeg"); // just add values here instead of modifying the logic in the if() statement if(in_array($_FILES["file"]["type"],$allowed_types){ }
-
The problem is how the $items array is being built and how you iterate over it later. $items is created as nested arrays, one level for each part of the exploded 'name' field. The code you are using later to iterate over the $items array was apparently written to work without a path as part of the name="..." attribute. You would need to write a recursive function to make your current code work. However, considering that there is a folder="..." attribute (and a src attribute), I suspect that the name="..." attribute was intended to ONLY be a 'display' name for the image and the folder="..." attribute should be the path to the actual file. To see why your code is not finding and setting the $files[] elements, add the following echo .....; statement right after your existing foreach(){ statement - foreach ($items as $key => $value) { echo '<pre>Value:',print_r($value,true),'</pre>'; ... }
-
LOL, I just reviewed your previous thread, which I'm assuming is this same problem. There were a lot of references to images/photos in the queries you posted. The advice here is the same as your last thread - "You should get a programmer to go through everything." You don't have the knowledge or skills to find the problem, let along pin down the many possibilities to one specific area or to fix it once it has been identified. In that last thread, a suggestion was given to do an EXPLAIN query on one of the queries. Did you even accomplish that?
-
Populating a table with gaps in the SQL results
PFMaBiSmAd replied to idontkno's topic in PHP Coding Help
No. You will only have one query that retrieves the data you want in the order that you want it. -
Populating a table with gaps in the SQL results
PFMaBiSmAd replied to idontkno's topic in PHP Coding Help
^^^ And the best point of the code kicken kindly posted is the design is now driven by the data and you don't ever have to change the code to add or remove any of the labName values. All you have to do is add or remove data in the database table. If you want or need to change the format or style of the output, you only have to change it in one set of code. -
Did you look at the query statement that was output as part of the error message? What value is missing in it? There's another part to using functions correctly, passing input values into the function as call time parameters. Your function definition needs an $id parameter that you then use in the query statement - <?php function new_test_query($id) { $db =& JFactory::getDBO(); $new_test_query = " SELECT * FROM crt_transactions WHERE user_id = ".$id." AND test_available = '1' ORDER BY test_name, id "; $db->setQuery($new_test_query); $new_test = $db->loadAssocList(); return $new_test; } The reason for call time parameters as inputs into functions is again to simplify code and make the programmer's job easier. You would call the above function using - $new_test=new_test_query($userID); or if you are only using the $userID in one place, you could do away with the $userID variable and just use - $new_test=new_test_query(getuserid()); By writing functions this way - (optionally) supplying inputs as call time parameters, code and local variables inside the function needed to do its processing, and (optionally) returning the output that the function produces, allows them to be used as building blocks and allows you to more easily write code without needing to remember any of the details about the code inside the function (after you have tested it), such as what global variables it uses and, oops, what global variables did I define in all those other functions so that I don't accidentally overwrite anything. $new_test=new_test_query();
-
Populating a table with gaps in the SQL results
PFMaBiSmAd replied to idontkno's topic in PHP Coding Help
Re: Reply #15 in this thread, where you posted some actual information about what you are trying to achieve and how it relates to the data and to the information in the thread. You would need to TEST the `period` value in each row and use that value to determine when to output empty <td></td> tags. You would need to store the last period value (initialize it before the start of the loop) and when each row is fetched, loop while the last period value is less than the row's period value. What is the lowest value for the period column, 1 ? Your output has legends like C101, C104, C106, ...,C109 and in the query you posted you have a table name labc101 that seems to correspond to the C101 data only. If you truly have separate tables for each of the C101, C104, C106, ..., C109 blocks of data, meaning you are executing a separate query for each of those blocks of data, STOP NOW. You need to fix your database design. You should NOT put similar data into separate tables. You will figuratively kill your database server trying to execute all those queries on one page to retrieve the data. It also means you are hard-coding repetitive blocks of code, that only differer in the source name of the data. So, not only will this take the page longer to retrieve the data, it will also take you longer to write the code, copy/paste blocks of code, make changes to each block, test to find the typo's in the code, and make repetitive changes to each block every time you must fix something. You need all the related data in one table with a column that indicates the data source C101, C104, C106, ...,C109. You will then use one query to retrieve the data you want in the order that you want it and then simply loop over that data with one set of code and output the information the way you want (you will simply detect a change in the source column to start a new section. -
Do you have php's error_reporting set to E_ALL and display_errors set to ON in your master php.ini on your development system so that php will help you by reporting and displaying all the errors it detects? You will save a TON of time. Stop and start your web server to get any changes made to the master php.ini to take effect and check the output from a phpinfo statement to make sure that the two settings actually changed in case the php.ini that you are changing is not the one that php is using.
-
Here's another reason to just return values from functions, there's less code to type - <?php function getuserid() { $user =& JFactory::getUser(); return $user->id; }
-
Here's your last posted code, with usable indention. I also moved the query logic inside the else{...} statement so that it will only be executed when your 'validation' passes. I also removed a lot of unneeded statements - <?php session_start(); $con = mysql_connect('localhost','root','abc'); if (!$con){ die ("Could not connect to database" . mysql_error()); } if (isset($_POST['submit'])){ //get data from the form $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $username = $_POST['username']; $password = $_POST['password']; $repeatpassword = $_POST['repeatpassword']; //check for existance if ($firstname&&$lastname&&$username&&$password&&$repeatpassword){ //check passwords match if ($password==$repeatpassword){ //check char length of username and names if (strlen($username)>25||strlen($firstname)>25){ echo "The first name, last name or username fields are too long!"; } else { //check password length if (strlen($password)>25||strlen($password)<6){ echo "Password must be between 6 and 25characters"; } else { //hash password $password = md5($password); //select database table mysql_select_db('theimageworks'); //add data to database $sql="INSERT INTO user (firstname, lastname, username, password) VALUES ('$firstname', '$lastname', '$username', '$password')"; if (!mysql_query($sql,$con)) { die ('Error: ' . mysql_error()); } die ("You have been registered! Return to <a href='loginpage.php'>login page</a>"); } } } else echo "Your passwords do not match!"; } else echo "Please fill in all fields!"; } mysql_close($con); ?>