Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. If you do not want visitors to your site accessing cron.php then do not store in your public_html folder (aka your document root). Store it outside of the document root. It doesn't change anything it is telling the server which program to execute, and passing command line option -q to PHP and stating the path the php file to be executed
  2. The code already does upload the original size image. The script removes the original image when it has created all the thumbnails. To prevent it deleting the original image, remove unlink($target_path);
  3. First add $totals = array(); $totals['total'] = 0; before foreach($data as $branch=>$arr){ Add $totals['total'] += $total; after $total = array_sum($arr); Then after $content .= "<td class='text-center' style = 'color:#874b03;font-size:12px;padding-top:20px;'>$value</td>"; Add if(!isset($totals[$date])) $totals[$date] = 0; $totals[$date] += isset($arr[$date]) ? $arr[$date] : 0; Next replace foreach($total as $tot_count) { $count_total = array_sum($tot_count); } $content .= "<tr><td>TOTAL</td>"; $content .= "<td>$currency" .number_format($count_total,2). "</td>"; // display over all total $content .= "<td>TOTAL</td></tr>"; // display per date total $content .= "</table>"; with $content .= "<tr><th>TOTAL</th>"; foreach($totals as $column => $total) { $content .= "<td>" . $currency.number_format($total, 2) . "</td>"; } $content .= "</tr></table>";
  4. Yes, make sure in your php.ini you have error_reporting set to E_ALL and display_errors is set to On. Alternatively add these two line at the top of your script ini_set('display_errors', 1); error_reporting(E_ALL); PHP errors are also logged in your servers error logs.
  5. Apply error checking to your query $result = mysqli_query($conn, $sql); // error check query. mysqli_query returned false on error if($result) { // process query results } else { // get the error from the query trigger_error('Query returned an error: ' . mysqli_error($conn)); }
  6. Remove the </tr> from this line $content .= "<tr><th> $branch </th></tr>";
  7. mysqli_fetch_array by default returns both a numeric indexed array and associative array for each row So you may want to set MYSQLI_NUM as the second argument when calling mysqli_fetch_array (or use mysqli_fetch_row instead) otherwise you will end up with duplicated data.
  8. If you are using mac_gyver code to define the $rows array then you need to assign the data from your query to the branch, date and sales keys, like so while (odbc_fetch_row($rs)) { $rows[] = array( 'branch' => odbc_result($rs,'BRANCH'), 'date' => odbc_result($rs,'Date'), 'sales' => odbc_result($rs,'SumOftotal_inc') ); }
  9. Why? Whats wrong with what scootstah told you to do.
  10. Umm.. What do expect? PHP isn't magic/psychic. You need to tell PHP to execute the query and then fetch the results from the query! mysql_query - executes a query mysql_fetch_assoc - fetches the next row from result set Defining the query in variable does nothing. Also the join query I gave is to replace the two queries you posted earlier.
  11. Durp! I messed up earlier intval($id) should of been intval($_POST['id']) Also $_row should be $row (no underscore)
  12. PHP Coding Help is not a place for asking us to write code for you. It is for helping with errors/problems with your own PHP code. If you want someone to create a website for you then feel free advertise on our freelance forum section.
  13. Why are you executing a CREATE DATABASE query? If you want to get data from your tables your need to use a SELECT query. To have PHP output the results like you index.php template look at the html. Notice every image/product header is contained in a <div class="col-md-2 portfolio-item"> element. This is what you need to output inside the foreach loop containing the data returned by your query, To have the user details displayed in rows of five, you have to contain 5 <div class="col-md-2 portfolio-item"> elements within a <div class="row"> element. To achieve this you could array_chunk to split the array of results return by $con->query into sets of 5. Then you can use two foreach loops to output your results. Example $results = array_chunk($con->query($sql), 5); foreach($results as $rows) { echo '<div class="row">'; foreach($rows as $row) { echo '<div class="col-md-2 portfolio-item">'; // output row data here echo '</div>'; } echo '</div>'; }
  14. Ok so it looks like the query is failing. Apply error checking to your query $toST = $con->query('SELECT first_name FROM users WHERE id = ' . intval($id)); // make sure query did not retun error (FALSE) if($toST) { // make sure a row was return if($toST->num_rows === 1) { $row = $toST->fetch_assoc(); echo "<div class = 'prep_stmt'>Your message to".$_row['first_name']."...</div>"; } else { // record id does not exist. Output error message echo "<div class = 'prep_error'>Sorry, contact could not go through. Try again later.</div>"; } } // get error from query else { trigger_error('Unable to query users table: ' . $con->error); }
  15. Yes you'll want to use a join. Something like SELECT c.id, c.identity, c.desc, d.defect, d.id as defect_id FROM character_defects AS c LEFT JOIN defects AS d USING(id) WHERE c.identity = 'Sailor Moon'
  16. What is the output of this in compose.php var_dump($_POST);
  17. Wheres the hidden input field I suggested that will pass the record id? Currently your form only contains the submit button echo '<form action="list.php" method="POST">'; echo '<input type="submit" name="message" id="message" value="Message">'; echo '</form>'; Also I see you have a bunch of textareas too. If want to retrieve the contents of these textareas when your form is submitted then you then you will need to move opening <form> tag so it comes before them. EDIT: Is your receiving page compose.php? If so then that is where you should be setting your form action to be. The following code is not needed, as you are not using session any more, it will never not work as you intend it to do if (isset($_POST['message'])) { $carry = "SELECT `first_name` FROM `users`"; $carryST = $con->query($carry); if($carryST) { while ($row = $carryST->fetch_assoc()) { $_SESSION['to_name'] = $row["first_name"]; $_SESSION['to_id'] = $row["id"]; } } $carryST->close(); header("location: compose.php"); exit(); } The issue is you are having the form submitted to itself (list.php), you then query the database to retrieve only the first_name with no condition applied to the query. This will result in all the first_name's from the database being returned. You are then looping through the results and setting two session variables, to_name to the value of the first_name column, and to_id to the the id column - which is not returned by your query. Each time the code iterates over the query results you are overwriting the session variables each time. This will result in only the very last row value being written to the session variables. After the code has finished looping over the results of the query you are using a header redirect to compose.php. This will now result in any $_POST data being lost, post data is never sent with a header redirect. Submitting the record id and then retrieving the data from the database where the record id matches the id that was submitted is better solution as I have recommended.
  18. You dont pass the record id via session. What you need to do is output the record id in a hidden input field in your form. echo '<input type="hidden" name="id" value="'.$row['id'].'" />'; On the receiving page you can then query the database to return the data you require where the submitted record if matches a row in your database if(isset($_POST['id']) && is_numeric($_POST['id'])) { // run query to get first_name where the submitted record id matches $result = $con->query('SELECT first_name FROM users WHERE id = ' . intval($id)); // make sure a row was return if($result->num_rows === 1) { $row = $result->fetch_assoc(); echo '<div class = "prep_stmt">Your message to <?php $_row['first_name']; ?>...</div>'; } else { // record id does not exist. Output error message } }
  19. The PHP manual is as clear as it will get. You pass the file path as the first argument. It returns the parent directory name. This is what I meant by apply basename to $parentDir echo "Currently in diretory: $currentDir<br /> Parent Directory is: " . basename($parentDir);
  20. Here is a live example of what cyberRobot means https://jsfiddle.net/k07ymqs4/
  21. You need to be recalculating the monthly percentage inside the for loop. So this line needs to be inside the loop (before you output $Monthly) $Monthly = number_format($Ammount * ($Percent/100)/12,2); You do not add $Monthly together
  22. Use dirname to get the parent directory $currentDir = getcwd(); $parentDir = dirname($currentDir); echo "Currently in diretory: $currentDir<br /> Parent Directory is: $parentDir"; If you only want the parent directory name and not the path then apply basename to $parentDir
  23. Try <?php // webpage you are scraping the javascript code from $page_url = 'http://www.dresslink.com/women-candy-color-handbag-leather-cross-body-shoulder-bag-bucket-bag-p-10908.html'; // load the webpage into DOMDocument libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc->loadHTMLFile($page_url); // use XPath to return the second <script> element inside the <div class="dd1"> element // this is where the javascript code containing the stock array is in the webpage $xpath = new DOMXPath($doc); $result = $xpath->query('//div[@class="dd1"]/script[2]'); // retrieve the node element value $JS_stock_array_code = $result[0]->nodeValue; // use regex to find the qty and sku values preg_match_all("~\[('[\w\d]+')\]\['qty'\]=(\d+);.+\[\\1\]\['sku'\]='([\w\d]+)'~", $JS_stock_array_code, $matches); // loop through the results and define sku array // the sku is used as the array key // the quantity is the assigned to the sku $skus = array(); foreach($matches[3] as $key => $sku) { $qty = $matches[2][$key]; $skus[$sku] = $qty; } // output $sku array printf('<pre>%s</pre>', print_r($skus, 1)); Output for me is Array ( [SV000837_B] => 49 [SV000837_G] => 26 [SV000837_BR] => 11 [SV000837_O] => 35 )
  24. Variables like $value['Stat.xxxx] and $value['Offer.yyyy] need to be written as $value['Stat]['xxxx'] and $value['Offer]['yyyy']
×
×
  • 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.