Jump to content

Drummin

Members
  • Posts

    1,004
  • Joined

  • Last visited

Everything posted by Drummin

  1. How does it behave when making this change to line 61? $product_name=$row['product_name'];
  2. No Debbie, I don't think you are correct. As far as I know, when making an update, there are no "checks" to see if values are different. You are only going to get a count of the number of records updated. The only why I can think of is passing hidden input fields for each field and then doing a comparison of posted values from hidden input (from DB) and user input.
  3. Probably it's better to check if a checkbox was checked as your primary condition. <?php if(isset($_POST['office'])){ $devices_returned = $_POST['office']; $office = array('desk','computer','whiteboard'); $values = array(); foreach($office as $selection){ if(in_array($selection,$devices_returned)){ $values[ $selection ] = 1; }else{ $values[ $selection ] = 0; } } $insert1 = "INSERT INTO test_location (`desk`, `computer`, `whiteboard`) VALUES ({$values['desk']}, {$values['computer']}, {$values['whiteboard']})"; mysql_query($insert1) or die(mysql_error()); } ?> <form name="checkbox" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="checkbox" name="office[]" value="desk"> Desk <input type="checkbox" name="office[]" value="computer"> Computer <input type="checkbox" name="office[]" value="whiteboard"> whiteboard <br> <input type="submit" value="Submit" name="button"> </form>
  4. if(isset($_POST['button'])){ $devices_returned = $_POST['office']; $office = array('desk','computer','whiteboard'); $values = array(); foreach($office as $selection){ if(in_array($selection,$devices_returned)){ $values[ $selection ] = 1; }else{ $values[ $selection ] = 0; } } }
  5. Would adding fit the need? echo "<dl> <dt>Joined:</dt> <dd>" . (!empty($joinedOn) ? date('M Y' , strtotime($joinedOn)) : ' ') . "</dd> <dt>Location:</dt> <dd>" . (!empty($location) ? str2htmlentities($location) : ' ') . "</dd> <dt>Posts:</dt> <dd>" . (!empty($posts) ? str2htmlentities($posts) : ' ') . "</dd> </dl>";
  6. You could also build this content above <html> then echo where needed. $sidecontent = "<dl>"; if (!empty($joinedOn)){ $sidecontent .= "<dt>Joined:</dt> <dd>" . date('M Y' , strtotime($joinedOn)) . "</dd>"; } if (!empty($location)){ $sidecontent .= "<dt>Location:</dt> <dd>" . str2htmlentities($location) . "</dd>"; } if (!empty($posts)){ $sidecontent .= "<dt>Posts:</dt> <dd>" . str2htmlentities($posts) . "</dd>"; } $sidecontent .= "</dl>";
  7. I know you don't want a bunch of php in your html, but this is an option to not show empty <dd>'s in the first place. echo "<dl>"; if (!empty($joinedOn)){ echo "<dt>Joined:</dt> <dd>" . date('M Y' , strtotime($joinedOn)) . "</dd>"; } if (!empty($location)){ echo "<dt>Location:</dt> <dd>" . str2htmlentities($location) . "</dd>"; } if (!empty($posts)){ echo "<dt>Posts:</dt> <dd>" . str2htmlentities($posts) . "</dd>"; } echo "</dl>";
  8. The principle is the same only you are processing on a different page then using the header to send person back to original page. Let say processing is on processing.php. it would be. <?php include('database.php'); if (isset($_POST['submit']) && isset($_POST['colors'])) { $colors = mysql_real_escape_string(implode(',', $_POST['colors'])); mysql_query("INSERT INTO colors (colors) VALUES('$colors')") or die(mysql_error()); header("Location: box.php"); exit; } ?> As you had the header point to box.php I'll put the form on that page. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Color Selection</title> </head> <body> <form method="post" action="processing.php"> <div> <?php include('database.php'); $aColors = array("Red", "Blue", "Green", "Yellow", "Brown"); $sql = "SELECT colors FROM colors"; $result=mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); $dbcolors= explode(',',$row['colors']); foreach ($aColors as $color) { $checked = (in_array($color,$dbcolors) ? 'checked="checked"' : ''); echo "<input name=\"colors[]\" type=\"checkbox\" value=\"$color\" $checked /> $color "; } ?> <input style="color:purple;" type="submit" name="submit" value="Select My Car" /> </div> </form> </body> </html> This is still a vary basic example and I'm sure you'll be wanting to identify the table row and do updates based on other factors.
  9. Here's a single page example. You listed the table field as "colors" in processing and "color" for your $row field. This example uses "colors" as the field name. I commented out the header in this single page example as it's not needed. <?php include('database.php'); if (isset($_POST['submit']) && isset($_POST['colors'])) { $colors = mysql_real_escape_string(implode(',', $_POST['colors'])); mysql_query("INSERT INTO colors (colors) VALUES('$colors')") or die(mysql_error()); //header("Location: box.php"); //exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Color Selection</title> </head> <body> <form method="post" action=""> <div> <?php $aColors = array("Red", "Blue", "Green", "Yellow", "Brown"); $sql = "SELECT colors FROM colors"; $result=mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($result); $dbcolors= explode(',',$row['colors']); foreach ($aColors as $color) { $checked = (in_array($color,$dbcolors) ? 'checked="checked"' : ''); echo "<input name=\"colors[]\" type=\"checkbox\" value=\"$color\" $checked /> $color "; } ?> <input style="color:purple;" type="submit" name="submit" value="Select My Car" /> </div> </form> </body> </html>
  10. No. Check your file name for capitalization or other typing errors. The name used in the form obviously is contact_lcs.php so make sure the file name matches and is saved as with the php extension. Unrelated to the problem but ALSO, use full php tags within your page. <?php ?> NOT <? ?>
  11. Why not use the error codes as I suggested before? UPLOAD_ERR_OK or 0 is returned on good. function validatePhoto($photoName, $photoApproved){ // Check for Photo. if ($_FILES['file']['error'] == UPLOAD_ERR_OK) { //Continue other checks
  12. The point of echoing $_FILES["file"]["error"]; is so you can find out how the file was handled. It would say 0 if there was not a problem and uploaded to temp.
  13. Do you get an error code when uploading? $_FILES["file"]["error"]; I don't see an error code, for too small... Maybe something else?
  14. Not sure if this will help you, but this is my take on it. <?php error_reporting(E_ALL); function replace_word($string){ $words = array('Test', 'test2'); $ascii = ''; for ($i=0;$i < count($words);$i++){ $ascii .= "&#38;#".ord($words[$i]).";"; $string=str_replace($words[$i], $ascii, $string); } return $string; } $text="This is a Test and this is test2 and this is test."; echo replace_word($text); ?>
  15. You could probably get the sum from the query itself SUM(field_name) or use another variable to add up these sub totals. {//your loop $total += $charge; }
  16. For textareas, echo between tags. <textarea id="element_2" name="comments" class="element textarea medium"><?php if(isset($_POST['comments'])){ echo "{$_POST['comments']}";} ?></textarea>
  17. Yes, any php coding or echo's need to be inside <?php ?> tags.
  18. Just got to watch those semi-colons at the end of lines and echo where you mean to. echo '<div class="productrangeborder">'; echo '<div class="productdetailsborder"><a href="product.php?product_id=' . $query_row['product_id'] . '">' . $query_row['name'] . '</a></div>'; echo '<div class="productimageborder"><a href="product.php?product_id=' . $query_row['product_id'] . '"><img src="' . $query_row['image_link'] . '"/></a></div>'; echo '<div class="priceborder">' . $query_row['rrp'] . '</div>'; echo '<div class="discountborder">' . $query_row['discount'] . '</div>'; echo '</div>';
  19. Well just add price to your query assuming you have a field name price.
  20. echo '<div class="productimageborder"><a href="product.php?price=' . $query_row['name'] . '</div>'; Ahh.. maybe missing a little something here? echo '<div class="productimageborder"><a href="product.php?price=' . $query_row['price'] . '">' . $query_row['name'] . '</a></div>';
  21. Any example how to do that? I did some searching, but didn't find anything I could get my head around to apply to this case. I did come up with another version as follows. <?php $sql="SELECT u.user, u.name, p.pet_id, p.pet "; $sql.="FROM users as u "; $sql.="LEFT JOIN pets as p "; $sql.="ON u.user = p.user_id"; $result=mysql_query($sql) OR DIE .mysql_error(); $data = array(); WHILE ($row=mysql_fetch_assoc($result)){ $data[$row['user']]['name'] = $row['name']; $data[$row['user']]['pets'][$row['pet_id']]=$row['pet']; } echo "<pre>"; print_r($data); echo "</pre>"; ?> Outputs Array ( [1] => Array ( [name] => Debbie [pets] => Array ( [] => ) ) [2] => Array ( [name] => Sally [pets] => Array ( [1] => Snake [2] => Rabbit [3] => Fish ) ) )
  22. If anyone can offer a way to format this array so "Sally" is in the same position as "Debbie" and not in an array, that would be great.
  23. BTW, this resulted in an array that looks like this. Array ( [1] => Debbie [2] => Array ( [sally] => Array ( [1] => Snake [2] => Rabbit ) )
  24. I know your intent (well at least I assume) is to build this array from a query. I am going to also assume you have two tables, and yes, this is old mysql_query, sorry about that. I know you will remake things to your liking anyway. <?php $sql="SELECT u.user, u.name, p.pet_id, p.pet "; $sql.="FROM users as u "; $sql.="LEFT JOIN pets as p "; $sql.="ON u.user = p.user_id"; $result=mysql_query($sql) OR DIE .mysql_error(); $data = array(); WHILE ($row=mysql_fetch_assoc($result)){ if (isset($row['pet_id'])){ $data[$row['user']][$row['name']][$row['pet_id']] = $row['pet']; }else{ $data[$row['user']] = $row['name']; } } echo "<pre>"; print_r($data); echo "</pre>"; ?>
  25. Yes, it all depends on what you'd like to do Debbie. Even using the user's ID as the primary key might be a good option, as I'm sure you're using that anyway to identify users.
×
×
  • 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.