Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,372
  • Joined

  • Days Won

    173

Everything posted by mac_gyver

  1. the single-quotes around the 'abcd' value in your first query have significance to the query. they indicate literal string data. you need to use that same syntax in the query for the case where php is supplying the string data value.
  2. when you retrieve the data from a database query, you can do anything you want with the data.
  3. the goal for your code would be to use a data driven design, where you have data defined somewhere (a database table, array) that tells one small set of code what to do and how many times to do it. here's an example of your form code that takes only about 1/10 the number of lines of code (this doesn't retrieve the fan data from the table as that's a trivial task) - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> <html> <head> <title>Ventilation Calculator Input</title> <meta id="meta" name="viewport" content="width=device-width; initial-scale=1.0"> <style type="text/css"> div { font-family: "tahoma"; font-weight: "bold"; font-size: "24pt" } table { text-align: center; } table { border: 1px solid black; border-collapse: collapse; } td { border: 1px solid black; } .right { text-align: right; } .left { text-align: left; } </style> <script language="JavaScript" type="text/javascript"> function validate(evt) { var theEvent = evt || window.event; var key = theEvent.keyCode || theEvent.which; key = String.fromCharCode( key ); var regex = /[0-9]|\./; if( !regex.test(key) ) { theEvent.returnValue = false; if(theEvent.preventDefault) theEvent.preventDefault(); } } </script> </head> <body> <div> <form id="form" name="form" action="http://www.swinevetcenter.com/tools/ventresults.php" method="post"> <b><h1>Ventilation Calculator</h1></b> <b><span >Pig Info:</span></b><br /> Number of pigs in the barn:<br> <input id="pigNumber" name="pigNumber" type="text" size="10" onkeypress='validate(event)'> <br> <br> <?php mysql_connect('db', 'un', 'pw'); mysql_select_db('un'); // stage 1 fans 9" 10" 14" 16" 18" 20" 24" 36" 48" 50" 52" 54" $stage1_fans = array(9,10,14,16,18,20,24,36,48,50,52,54); // this apparently your fan.csv data // barn fans 9" 10" 18" 20" 24" 36" 48" 50" 52" 54" $barn_fans = array(9,10,18,20,24,36,48,50,52,54); $category['stage1'] = array('legend'=>'Stage 1','sizes'=>$stage1_fans); $category['barn'] = array('legend'=>'Barn','sizes'=>$barn_fans); // produce option list 0-10 $num = range(0,10); $options = ''; foreach($num as $val){ $options .= "<option value='$val'>$val</option>\n"; } // pig weight $sql = "SELECT weight FROM cfm ORDER BY weight"; $result = mysql_query($sql); echo "<p><b>Pig Weight</b><br>"; echo "<select weight='weight' name='weight' id='weight'>"; while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['weight'] . "'>" . $row['weight'] . "</option>"; } echo "</select>"; ?> <br> <br> <b>Fan Info</b> <?php foreach($category as $key=>$arr){ ?> <table> <tr> <td colspan="<?php echo count($arr['sizes'])+1;?>" class="left"><b>Select Size and Number of <?php echo $arr['legend']; ?> Fans</b></td> </tr> <tr> <td class="right">Fan Size</td> <?php foreach($arr['sizes'] as $val){ echo "<td >$val\"</td>"; } ?> </tr> <tr> <td class="right">Number of <?php echo $arr['legend']; ?> Fans</td> <?php foreach($arr['sizes'] as $val){ echo "<td ><select name='{$key}[$val]'>"; echo $options; echo "</select></td>"; } ?> </tr> </table> <br /><br /> <?php } ?> <br /> <input id="submit" name="submit" type="submit" value="Submit" method="post"> </form> </div> </body> </html> other than reducing the amount of code, the only significant change in the above is to name the form fields as an array that you can loop over to process the submitted data. the code you posted has two different sets of fan sizes. is this intentional or should the list of 'Barn' fan sizes be the same as the 'Stage 1' fan sizes?
  4. Please use the forum's bbcode tags (the edit form's <> button) around code when posting it in the forum. i modified your post above.
  5. i'm guess that you mean you tried using generated buy now/add to cart/check out buttons and you would like to change this so that the cart is built on your site, with the contents being stored in a database, then when the cart is finalized, you display the complete cart contents in a form that paypal expects, with a check out button that takes the visitor to the paypal site to finalize the order? if so, you would write (or find a script) to implement the cart on your site, then see the paypal cart upload command to submit the cart information and take the visitor to the paypal site - https://developer.paypal.com/webapps/developer/docs/classic/paypal-payments-standard/integration-guide/cart_upload/
  6. it would probably help if you posted the code you tried, using the forum's bbcode tags.
  7. and as mentioned in a previous thread, you are not specifying join conditions fully, which is resulting in every row from the left-hand side of the join being joined to every row on the right-hand side of the join without regard to the relationship between those rows. LEFT JOIN categories c ON ... needs to specify how you want to join the item/sub-category information to the category table. JOIN users u ... needs to specify how you want to join the item/sub-category/category information to the users table. lastly, concat(i.listing_duration) <- that's concatenating one value. why not just use the value itself?
  8. you are likely getting a fatal runtime error. do you have php's error_reporting set to E_ALL and display_errors set to ON in your php.ini on your development system so that php would report and display all the errors it detects?
  9. there's nothing in the posted code that would cause the problem. however, given your class="...." naming in all the html markup, i suspect you have some client-side code, that's likely causing this. what's all the relative code on the page(s) that would be needed to reproduce the problem?
  10. the login_check(){} function definition. the current focus of this thread, is defined in the functions.php file. you should not have any code referencing $login_check == $login_string in your login_success2.php code (as indicated by the last image of php error messages attached.)
  11. i get ~60 execution time for the mysql pdo code as well, for engine type InnoDB. for engine type myisam 0.25 seconds
  12. because the for() loop is what is incrementing the $i variable, you would need to put the if ($i % $imagesPerRow == 0) test before you output the image. this would result in an extra <br> before all the output or you would need to add a condition so that it only does this when $i is greater than zero. what i would do is use a foreach() loop instead of a for() loop and use a separate $i variable that gets incremented inside the loop.
  13. the issue isn't that the second image is entirely missing, it's that the first row of output only has one image in it. the problem is because $i is a zero and - if ($i % $imagesPerRow == 0) is a true value.
  14. is the html that's being produced and output to the browser what you expect? if the problem is always the second image, does the first or second image name contain any html special characters in it that could be breaking the html? what are the file names and what is the html that's being output?
  15. just listing what you want doesn't help us to help you as that doesn't tell us where you got stuck at when you tried to do this. i can only offer two recommendations - 1) for each step, define what your input(s) are or what data you need to get/produce, what processing you want to do on those inputs/data, and what result or output that step needs to produce. 2) "So each fan size would have two variables, its name and its output." your variables should be general purpose. you should not have variables with names like $capacity9, $capacity14, ... in fact, since you have a SET of data that's all going to be processed the same, just with different values, you should use an array to hold the data. storing the rows you retrieve from the fan/product table into an array would be a good first step, as this will decouple the actual database statements from the code using that data.
  16. the goal of your code should be to run as few queries as possible, in this case one will work, to get the data you want in the order that you want it. then, you would simply loop over the rows the query returned and output the data the way you want. to accomplish the ordering, remove the WHERE size=x clause and add an ORDER BY size clause to the query (assuming your table is designed correctly and is storing the size as an integer data type, if you used a character or text type, changed it to an integer data type.)
  17. the two sets of code are not comparable. the mysql code is doing a lot more work, with several more statements being evaluated in each iteration of the loop and of the database engine managing the auto-increment index field. to make a fair comparison, you need to use the same while loop construct in both, remove the static str variable, remove the p_hash assignment, remove the i+1 operation (or add these things to the FB code), and add an auto-increment id field to the FB product table. you would also need a comparable number of starting rows in each table. edit: btw - you should NEVER use the msyql PASSWORD() function in your application code.
  18. in the case of validation errors, you would want to re-populate the form fields with the existing values. in this case, you typically don't redirect, since the form is going to be re-submitted any way.
  19. when you submit to the same page that the form is on, when you have successfully processed the form data, use a header() redirect to the same page to clear the post data. you would need to use an exit; after a header() redirect, unless you have structured the logic in your code so that the remainder of the code on the page isn't executed after the header() statement. so, short-answer, you might as well ALWAYS use an exit; and simplify the logic on the page. whomever stated you are using too many exit's, may have been referring to combining common/repeated parts of your code (i.e. don't repeat yourself - DRY.) in your example code, you are repeating the header()/exit pair. you would move the header()/exit to the common execution point following the conditional logic and just leave the session assignment statement in the conditional logic.
  20. that's some pretty sad code. there's even someone that posted a bug/solution on the cuteflow site that got the reason for the error wrong, which got his solution to prevent the errors but didn't fix what the code is actually doing. the problem is that empty lines in the language file will be an empty string in the php data, producing errors when you try to access specific characters of the string or parts of an explode empty string that won't exist. also, the lines starting with # are apparently (there's no documentation) commented out lines and shouldn't be processed at all. the simplest fix, for just the incorrect logic, is to change the following line - if ( ($strLine[0] != "#") && (strlen($strLine) > 0) && (substr($strLine,0,5)!="_jotl")) to this - if(strlen($strLine) > 0 && $strLine[0] != "#") // not an empty line and not a commented out line if (substr($strLine,0,5)!="_jotl") // for lines not starting with _jotl (the else block is for lines starting with _jotl)
  21. i moved your thread to the php coding help forum section, since the problem is in getting your php code to connect to the database server. your web host has a FAQ section that explains what you must use for the database username and database name in your php code - https://my.bluehost.com/hosting/help/318 it prepends your hosting account's username and to the database username and database name you picked. also, localhost needs to be quoted in the php code, 'localhost', so that it is not treated as a defined constant first. lastly, for learning and development, you should do this on a local pc/laptop as you will waste a bunch of time constantly FTP'ing/uploading code and data to a live server (and needing to conform that the FTP/upload worked in its entirety) just to see the result of each change.
  22. your last code, using mysql_escape_string(), has a number of problems - 1) you should not mix mysql_ functions with PDO functions. this also implies that you have made a second database connection using mysql_connect(), resulting in two database connections. you should be using the PDO ->quote() method on string data. 2) mysql_escape_string() doesn't take into account the character set being used and can allow sql injection. 3) all the mysql_ functions are depreciated and should not be used in new code. 4) as stated, there's no point in using ->prepare() and ->execute() when you are putting values directly into the sql query statement. just use the ->query() method. 5) you must validate/cast/escape all three values being put into each row. what exactly are the data types of val1, val2, and val3? 6) i didn't bother to mention this before, but you should not put the id into the list of fields since it is an auto-increment column. this will eliminate the need to supply a value for that column, which will further speed up the process since the amount of data/length of the sql query statement is reduced. edit: my reference to using array functions, means to take any loop out of your code and use php's array functions to operate on each set of data. you can use array map (typically in a class) to cast/validate/escape all three pieces of data and to build the ('v1','v2','v3') string for each element in your data array. you can then simply implode those resulting values to produce the ('v1a','v2a','v3a'), ('v1b','v2b','v3b'),... portion of the query.
  23. re-read this - without the WHERE clause, you are SEEING the correct datetime values in the SELECT term, because the rows have been unconditionally matched by the query, but when the query with the where clause in it runs, the user variables don't have those values in them and the WHERE clause is false. (edit: when i tested this, there were no query errors, likely because of null values being used for the user variables. had you used alias names for the derived values and use the aliases in the where clause, you would have gotten query errors.) you either need to put the expressions using convert_tz() and date_add(repeating the convert_tz() expression here...) into the WHERE clause OR you need to change the WHERE clause into a HAVING clause. also, your JOIN users u ON username = 'Destramic' isn't complete. you need to relate the users table to the other table(s) in the query, something like JOIN users u ON u.user_id = i.user_id AND u.username='Destramic' (whatever condition ties the users to their data in the other tables.)
  24. for the logic testing if ($Car_Info_All_results) { ... } is true, you need an else { } branch using mysql_error() in it to get php to tell you why it thinks the query is failing.
  25. 1) the maximum length of each line in the message body is 70 characters. you need to add new-lines \n to break up and limit the length of each line in the message body. 2) the separator between headers should be \r\n, unless you have determined for a fact that your sending mail server requires just \n 3) you should only use a function like mysqli_real_escape_string on the values being put into mysql query statements. by using it on the email value, then using that in the mail function, any email addresses that contained any sql special characters will be broken and won't work. 4) your code needs to test the value returned by the mail() function. a false value would indicate an error occurred that would require debugging to find out why the mail server didn't accept the email. a true value would indicate that the mail server at least accepted the email (but may not actually send it, but at least you will know the email made it to the sending mail server.)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.