Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. make $_SESSION["odd"] and $_SESSION["even"] arrays. You can then use array_sum to add up the odd/even numbers together. To list the numbers you can use implode <?php // reset session if(isset($_POST['reset'])) { session_destroy(); unset($_SESSION); } session_start(); $_SESSION["number"] = rand(1,10); // set odd and even sessions to array if(!isset($_SESSION["odd"]) || !isset($_SESSION["even"])) { $_SESSION["odd"] = array(); $_SESSION["even"] = array(); } if(isset($_GET["check"])) { if ($_SESSION["number"] %2 == 0) { $_SESSION["even"][] = $_SESSION["number"]; // even number to array } else { $_SESSION["odd"][] = $_SESSION["number"]; // odd number to array } } $_SESSION["sum"] = array_sum($_SESSION["odd"]) + array_sum($_SESSION["even"]); // add up the odd and even number array's ?> <body> <form action="" method="post"> ODD number: <?php echo implode(',', $_SESSION["odd"]); /* list odd numbers */ ?> <br /> EVEN number: <?php echo implode(',', $_SESSION["even"]); /* list even numbers */ ?><br /> SUM of all the numbers that have appeared:<?php echo $_SESSION["sum"];?><br /> <input type="submit" name="check" value="submit" /> <input type="reset" name="reset" value="Reset" /> </form> </body>
  2. Where is the dropdown menu for interest? Also these lines need to be swapped around $intrest = (isset($_POST['intrest']) && $_POST['intrest'] != '') ? $_POST['intrest'] : $serviceLine; $serviceLine = $this->serviceLine; // this should be before the line above
  3. mysql_query() does not return any data from the query. it only returns a result resource. To get the data from the query you need to use a function like mysql_fetch_assoc So change echo $run2; $query2 = "insert into complaint(complain,d_name,complainant_id) values ('$complain_det','$comp_name','$run2')"; to $row = mysql_fetch_assoc($run2); // get the data from the query $query2 = "insert into complaint(complain,d_name,complainant_id) values ('$complain_det','$comp_name','{$row['complainant_id']}')";
  4. You have to change table_name to the actual name of the table you want to run the query on. I only gave table_name as a guide. I cannot tell what the table would be as I dont know what your database structure is What are you trying to do?
  5. Then shouldn't you be using $_SERVER["HTTP_USER"] instead of $_SERVER["REMOTE_USER"]?
  6. Your can create a dropdown using <select> the populate the menu with choices using <option>. Example html <select name="intrest"> <!-- name attribute defines the name of the input --> <option value="">Choose Intrest</option> <option value="value1">Option 1</option> <option value="value2">Option 2</option> <option value="value3">Option 3</option> .. etc </select> If you include that html into your form you should be able to get the selected options value using $_POST['interest']; $intrest = $_POST['intrest']; Using the example code above you could do $intrest = (isset($_POST['intrest']) && $_POST['intrest'] != '') ? $_POST['intrest'] : $serviceLine; // default to $serviceLine if no interest was selected
  7. Probably. I see Dreamweaber as a WYSIWYG editor for HTML/CSS with a premium price tag, not a IDE for programming. Take notice of what PHP says not your editor.
  8. Either hard code the table name into the query $q = "select * from table_name"; Or define the $src variable with the table name $src = "table_name"; $q = "select * from " . $src;
  9. No the the extra ) belonged to the mysql_fetch_object function. All I did was separate the mysql_query() on to its own line and then checked to make sure the query returned any results before using mysql_fetch_object. The problem was the query was not returning any results. When mysql_fetch_* functions are given an empty result set then you will get this type of error
  10. You are getting that error due to your query not returning any results. Change <?php $row = mysql_fetch_object(mysql_query("select * from wp_posts where ID=".$_GET['id'])); if($row->evtdate=="") { wp_redirect(home_url()); exit; } to <?php $result = mysql_query("select * from wp_posts where ID=".$_GET['id']); if(mysql_num_rows($result)) { $row = mysql_fetch_object($result); if($row->evtdate=="") { wp_redirect(home_url()); exit; } }
  11. Can you post the PHP error messages in full here. Ignore what your editor says.
  12. The query before you call mysql_fetch_assoc has failed. When a query fails mysql_query() returns false. The query you have is this $q = "select * from " . $src; $r = mysql_query($q); The variable $src does not appear to be set.
  13. Yes I assume that what it means
  14. Edit oops.... To make a dropdown you need to output a <select> field with <options>'s. $sql = 'SELECT tbl_typesofbusiness.id, tbl_typesofbusiness.Agent FROM tbl_typesofbusiness'; if ($result = mysqli_query($con, $sql)) { echo '<form action="addeadstemplate.php" method="post">'; // start the form echo '<select name="businessAgents">'; // start a dropdown menu while($row = mysqli_fetch_array($result)) { echo '<option value="' . $row['id'] . '>' . $row['testcollumn'] . '</option>'; // add options to the menu } echo '</select>'; // close the dropdown menu echo '<input type="submit" />'; // submit button echo '</form>'; // close the form }
  15. If this is all on the same page then there is no need to use explode again. Just use $explode[1] to get the town. $ad = $_GET['ad1']; $explode = explode(',', $ad); $street = $explode[0]; $town = $explode[1];
  16. These options are explained here http://httpd.apache.org/docs/current/mod/core.html#options
  17. Do the regex for code tags first, replacing anything within these tags into htmlentities. That way the bbcode within these tags will not be parseable. // replace code tags first $text = preg_replace_callback("/\[code\](.+?)\[\/code\]/is", function($matches) { return str_replace(array('[', ']'), array('[', ']'), htmlentities($matches[1])); }, $text);
  18. This a forum for PHP Help not Javascript
  19. Try adding the Date and Range column in backticks `Date`, `Range` These are reserved keywords.
  20. Your query values need to be in quotes mysqli_query($con,"INSERT INTO battery (Date, Range, Percent, Sleep) VALUES ('$date', '$miles', $battery_level, 1)");
  21. Ch0cu3r

    New to PHP

    More of a MySQL question than a PHP one. You set all fields to be varchar with a 255 character limit. Which is lazy database design. The data type you set the field to should represent the type of data you are storing in that field. Such as the zipcode, bedrooms and sqft would be numbers so an int datatype would be more suitable. price should be float or decimal datatype. You should rethink how you are setting the table up. http://dev.mysql.com/doc/refman/5.0/en/data-types.html
  22. Try customer_information[field] = value;
  23. That script you linked to also requires Node.js aswell as PHP. The steps listed in the link tells you how to install it. head over to php.net/manual to learn PHP. You add PHP code between tags (<?php ?>) to add php to a webpage. Make sure the file has a .php extension and that the server is configured with PHP.
  24. What do you mean by this? Is this addtocart($pid,1); supposed to add the product to the database? What is the code for this php function
  25. Check your browsers JavaScript development console (press F12 and then click console tab). What errors are shown?
×
×
  • 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.