Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Everything posted by cyberRobot

  1. I think you're getting that confused with the use of "var" in classes. http://www.php.net/manual/en/language.oop5.properties.php $var is the name of the variable.
  2. Ah, it's the comma added by number_format() that's giving you the bad result. <?php print '<br /><br />'; $row['DS'] = number_format(59009.3,0); $row['TC'] = 190.0; print $ConF = $row['TC'] / $row['DS']; //output: 3.2203389830508 ?> If you really need to remove the decimals before the calculation, you could use typecasting as peipst9lker suggested. Note that this won't round like number_format(). You could use sprintf() instead. <?php print '<br /><br />'; $row['DS'] = 59009.6; //<-- note the change to .6 print number_format($row['DS'],0); //output: 59,010 print '<br />'; print (int)$row['DS']; //output: 59009 print '<br />'; print sprintf("%01.0f", $row['DS']); //output: 59010 ?> Or you could just leave the decimal there until all calculations are complete. Then remove the extra decimals at the end.
  3. I was just showing that the calculations seem to work fine either way. Besides, wouldn't it be better to remove the decimals in the end? The result would be more accurate.
  4. The following seems to work for me: <?php print $ConF = 190.0 / 59009; //output: 0.0032198478198241 print '<br />'; print number_format($ConF,2); //output: 0.00 print '<br /><br />'; print $ConF = 190.0 / 59009.3; //output: 0.0032198314502968 print '<br />'; print number_format($ConF,2); //output: 0.00 print '<br /><br />'; print $ConF = 190.0 / 5.2; //output: 36.538461538462 print '<br />'; print number_format($ConF,2); //output: 36.54 ?>
  5. You could try something like this (see reply 5): http://www.sitepoint.com/forums/showthread.php?544582-Is-there-a-PHP-redirect-that-will-open-a-new-window
  6. What does EvaluateHand() look like? For what it's worth, the following code works: <?php $sesscards = array(1,2,3,4,5,6,7,8,9,10,11,12); $dealercards = array(); //if ($playercards>21 || $choice==1) { while(array_sum($dealercards)<17) { $key2 = array_rand($sesscards); $pick9 = $sesscards[$key2]; unset($sesscards[$key2]); array_push($dealercards, $pick9); // $dealercards=EvaluateHand($dealercards); $strd.="$pick9|"; var_dump($dealercards); print '<br />'; } //} ?>
  7. If you remove the maxlength attribute, you can see some XSS in action by entering the following into the name field: "><script>alert('here');</script> Adding htmlentities() around the POST data would help avoid this issue. <input type="text" name="name" value="<?php echo (isset($_POST['name']) ? htmlentities($_POST['name']) : null);?>"/> Plus, the form wouldn't break if someone entered the following for their name: Dan "The Man"
  8. Does this help at all? http://docs.cksource.com/FCKeditor_2.x/Developers_Guide/Configuration/Configuration_Options/ProcessHTMLEntities Assuming that CKEditor is the one converting things to HTML entities, you could try asking their forum: http://cksource.com/forums/
  9. Have you tried adding mysql_error() after the query is executed? http://php.net/manual/en/function.mysql-error.php
  10. What is the code used to display the data? There's probably a function like htmlentities() being used on the data. Removing the function might give you the expected results.
  11. So, what is the question? It kind of sounds like you're asking how to display information from a database. If so, could you explain what you're doing now and what you're looking to do. If you don't like the method you're currently using, what don't you like about it?
  12. Beyond personal preference, what's wrong with single quotes? Note that I prefer double quotes for HTML attributes. However I'll usually use single quotes when those attributes are within a double-quoted PHP string.
  13. You would loop through the array using something like foreach(): http://php.net/manual/en/control-structures.foreach.php Inside the loop, you would run the code to save each entry to the database.
  14. Have you tried going back to your original code for executing the query? <?php $conn->Execute($insert); ?> I would imagine that the Execute() method handles the mysql_query() part.
  15. Is your session variable supposed to be $_SESSION['cart'] or $_SESSION['product_id']?
  16. Did you call session_start() on the page which displays the results? If so, does the session variable contain anything? <?php var_dump($_SESSION['cart']); ?>
  17. Do you have PHP set to display all errors? If so, are you getting any errors or notices? <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> Have you checked if the variables contain what you expect? To see if the session variable contains anything, for example, you could do something like <?php //... $_SESSION['cart'][] = $_POST['product_id']; var_dump($_SESSION['cart']); exit(); //... ?> Have you checked what portions of the script are being executed? For example, to see if the if statements are being evaluated to true, you could try something like <?php if (isset($_POST['submit'])){ print 'here - submit'; if (!isset($_SESSION['cart'])){ print 'here - session not created yet'; //... ?>
  18. That is correct. Since the overall string is within double quotes, the following should work: <?php $insert = "INSERT INTO tblPurchasesHeader (Vendor, InvoiceDate,Invoice,TotalAmount,TaxAmount) VALUES ('$vendor','$date','$invoice','$total','$tax')"; ?>
  19. To get them to display vertically, you could float the <p> tag with CSS. print "<p>$image_html</p>"; For more information, you could search for "creating an image gallery with css". As a side note, I would recommend avoiding PHP_SELF in the form action attribute for security reasons. Instead, you could just list the page name...or leave it blank.
  20. I'm assuming that you want the option to be added without reloading the page. If so, you'll need to use something like JavaScript. Is this what you're looking for? http://forums.phpfreaks.com/index.php?topic=338474.0
  21. It looks like you need to read in the number like you do for the other POST variables. $name = trim($_POST['contactName']); Somewhere near the top, add the following: $number = trim($_POST['number']);
  22. The code works for me. How are you viewing the image? Do the images show up when viewing them directly through the browser? http://[path_to_uploads_folder]/uploads/thumbs/[image_file_name]
  23. That is correct. The link version of the code will show 3 links (or however many links are created).
  24. The code is pretty much the same, you're just dealing with a POST variable versus GET. For a drop down that looks like the following: <form method="post" action="sendMomEmail.php"> <select name="selectDept"> <option value="">Please Choose Dept.</option> <option value="TC OSS RC">TC OSS RC</option> <option value="TC OSS Arch Board">TC OSS Arch Board</option> </select> <input type="submit" value="Send email for approval"> </form> The switch() could be modified to <?php switch($_POST['selectDept']) { case 'TC OSS RC': $toEmail = 'TCOSSRC@test.com'; break; case 'TC OSS Arch Board': $toEmail = 'TCOSSArchBoard@test.com'; break; } // The message $message = "Line 1\nLine 2\nLine 3"; // In case any of our lines are larger than 70 characters, we should use wordwrap() $message = wordwrap($message, 70); mail($toEmail, 'My Subject', $message); ?>
  25. Basically, you would create however many links you would need: <tr><th>Review Forum</th><th>Review ID</th><th>Send E-mail</th></tr> <tr><td>Forum 1</td><td>...</td><td><a href="sendMomEmail.php?sendemail=forum1">Send e-mail to Forum 1</a></td></tr> <tr><td>Forum 2</td><td>...</td><td><a href="sendMomEmail.php?sendemail=forum2">Send e-mail to Forum 2</a></td></tr> <tr><td>Forum 3</td><td>...</td><td><a href="sendMomEmail.php?sendemail=forum3">Send e-mail to Forum 3</a></td></tr> Note that the "Send e-mail to Forum 1" could say anything you want. It could also be an image that looks like a button. Here is one way to process the above links: <?php switch($_GET['sendemail']) { case 'forum1': $toEmail = 'email1@test.com'; break; case 'forum2': $toEmail = 'email2@test.com'; break; case 'forum3': $toEmail = 'email3@test.com'; break; } // The message $message = "Line 1\nLine 2\nLine 3"; // In case any of our lines are larger than 70 characters, we should use wordwrap() $message = wordwrap($message, 70); mail($toEmail, 'My Subject', $message); ?>
×
×
  • 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.