Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. On line 18 you are missing the semi-colon ; at the end of the line $result =odbc_exec($connect,$query); You are running the update query twice on lines 20 and 24. You only need to run it once, so do not execute the query again on line 24. On line 29 you have HTML code which PHP tags. You can not place HTML within PHP tags if you want to output HTML you need to use either echo or print When outputting error messages "Error in SQL" is meaningless. To know why the query failed use odbc_errormsg. This will return the error message from mssql. Also do not use die or exit instead use trigger_error
  2. @font-face only defines fonts. To use the font you need to apply to a HTML element @font-face { font-family: Pixelated; src: local('pixelated.ttf'); } /* apply Pixelated font to body tag */ body { font-family: Pixelated; } If you are using CSS styles in the same file as your HTML then make sure it is wrapped in <style></style> within the <head> tag
  3. You don't store that data in a session. What you do is only store the product id in the session when the user clicks the add to basket button. Basic example code <?php session_start(); // if add to basket button submitted if(isset($_POST['add_to_basket'])) { // make sure product id is numeric value if(is_numeric($_POST['product_id'])) { // add product id to basket session variable $_SESSION['basket'] = intval($_POST['product_id']); } } ?> ... each product has a add to basket button and a hidden input field containing the product id ... <form method="post"> <input type="hidden" name="product_id" value="<?php echo $product_$id ?>" /> <input type="submit" value="Add To Basket" name="add_to_basket" /> </form> On your shopping cart page you will run a query to get the product info that match the product id(s) stored in your session. Very basic example code <?php session_start(); // check to make sure the session basket exists and is not empty if(isset($_SESSION['basket']) && !empty($_SESSION['basket'])) { // query the products table, return the products matching the ids in the session basket $product_ids = implode(',', $_SESSION['basket']); $sql = 'SELECT name, description, price, image FROM products WHERE id IN('.$product_ids.')'; $result = $mysqli->query($sql); while($row = $result->fetch_assoc()) { // output product info } }
  4. Locked. You already have topic asking this
  5. On line 11 at the end you have a stray double quote $Mood_info['Event_Sub_Type'] ="";" ^ | this is causing the error
  6. How do you know the problem is the query? A blank white page can be caused by anything. I would suggest you either enable error reporting/display errors in PHP's config or look at your servers error logs.
  7. In the code you posted for the second page you have malformed HTML ... <strong<?php if(isset($_POST['submit'])) { ^ | missing closing '>' angle bracket This maybe causing the email to not display correctly.
  8. If you want to create fake PSN codes then google "PHP random string generator" you will find many tutorials/code snippets which will show how to generate random strings. To format the random string into a fake PSN code all you do is generate a 12 character string then use use str_split and implode to add the hyphens every 4 characters. To know if the code has been generated before you need to use a database. Every time you generate a code you will need to check the database to see if it has not been generated before. If the code has not been used you will display the code and insert it into your database. If you want to create genuine PSN codes then it will not be possible for to generate these. What you will have to do is (obviously) purchase genuine PSN codes and add them to a database. To get a code from the database you will run a SQL query which will randomly select a code that has not been issued before, example SQL query SELECT code FROM psn_codes WHERE issued = 0 ORDER BY RAND() LIMIT 1 When you got the code you will update the database and mark that code has been used. UPDATE psn_codes WHERE code = '$thePSNCode' SET issed = 1 When issued is set to 1 then code not be used again. To make your page look pretty like your screenshot you'll use HTML/CSS. There are plenty of basic HTML/CSS tutorials available if you google, you should be able to reproduce the screenshot quite easily. Or use a readily available template
  9. Your don't want to use queries within loops. As the data relates, via the review_id in both tables you can use a JOIN to query both tables at the same time. Example $SQL = " SELECT sr.review_id, sr.review_date, sr.review, r.rating_name, r.rating FROM school_reviews sr LEFT JOIN ratings r USING(review_id) WHERE sr.active = 1 AND sr.is_deleted = 0 AND sr.school_id = '" . $school_id . "' ORDER BY sr.review_date DESC"; $q->query($DB,$SQL); // store results of query in array $reviews = array(); while($row = $q->getrow()) { // get the review id $id = $row['review_id']; // group reviews by review id if(!isset($reviews[$id])) { $reviews[$id] = array( 'message' => $row['review'], 'date' => $row['review_date'], 'ratings' => array() ); } // group ratings by review id $reviews[$id]['ratings'][] = array( 'name' => $row['rating_name'], 'value' => $row['rating'] ); } // loop over the reviews foreach($reviews as $review_id => $review) { // output review echo "<p>Review ID: $review_id<br />\n" . "Posted On: " . $review['date'] . "<br />\n" . "Review: " . nl2br($review['message']) . "</p>\n"; // output ratings list for each review echo "<ul>\n"; foreach($review['ratings'] as $rating) { echo "\t<li>" . $rating['name'] . ': ' . $rating['value'] . "</li>\n"; } echo "</ul>\n"; }
  10. You will need to use separate counters if (isset($_GET['id'])) { // initialize counters to zero $SubscribedMembers = 0; $UnSubscribedMembers = 0; $current_user = wp_get_current_user(); $dir = '/home/promoter/public_html/referrals/' . basename($_GET['id']); if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && $entry != "role.txt") { //echo "$entry\n"; $path = "$dir/$entry"; $result = file_get_contents($path); switch(trim($result)) { // increment subscribed couter, if the contents of the file is "subscribed" case 'subscribed': $SubscribedMembers++; break; // increment unsubscribed couter, if the contents of the file is "unsubscribed" case 'unsubscribed': default: $UnSubscribedMembers++; break; } } } closedir($handle); } // calculate total members $totalMembers = $SubscribedMembers + $UnSubscribedMembers; // output results echo " There are $totalMembers members.<br /> $UnSubscribedMembers of the members are not subscried.<br /> $SubscribedMembers of the members are subscribed."; } However storing whether each member is subscribed or not in separate text files is very efficient. It will be better if you used a database of some kind, be it a csv/xml file or SQL database.
  11. Did you not learn anything from your other topic? The process is the same for converting the preg_replace for images as it was for your urls. You should be able to use the same callback function I gave.
  12. All you need to is replace preg_replace to preg_replace_callback and remove the e pattern modifier from the regex. Next replace '\'$1\'.handle_url_tag(\'$2://$3\')' to the callback function I gave earlier, inside the callback function change {$m[1]}.{$m[2]} to {$m[1]}://{$m[2]} lastly only pass $url once, rather than twice when calling the handle_url_tag function
  13. What? I dont understand what you mean. Can you post an example of how you want the array to be filled.
  14. What database api are you using? PDO or MySQLi. I assume PDO, as you are using PDO functions in your code. However here $stmt->bindParam("ss", $username, $password); $stmt->bindParam is a PDO function. But the arguments you are passing to this function is incorrect, ("ss", $username, $password) is MySQLi arguments for binding variables to a query As you only want your query to return the row where the username and password matches you need to apply a where clause. You would use placeholders for the username and password values. $stmt = $conn->prepare("SELECT username, password, rank, active FROM users WHERE username = :usernmae AND password = :password"); For each variable you you call bindParam passing the placeholder (name/index) followed by the variable to be bound to that placeholder $stmt->bindParam(':username', $username); $stmt->bindParam(':password', $password); When fetching the result from the query you dont want to call fetchAll. Your query will only returning one row. So call $fetch = $stmt->fetch(PDO::FETCH_ASSOC); instead. $stmt->rowCount() doesn't return a boolean. It returns the number of rows from your query. So you want to check if i$stmt->rowCount() equals to 1 if($stmt->rowCount() === 1) if you have not output anything then use header('Location: page.php'); to preform the redirect rather than use HTML meta refresh tag. After calling header make sure you use exit;
  15. Try $text = preg_replace_callback('#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#i' , function ($m) { $url = "{$m[1]}.{$m[2]}"; return $m[0] . handle_url_tag($url, $url); } , $text);
  16. Try changing your path to be '../core/init.php';
  17. Then you need to submit the checkbox when it is unchecked/checked. When the checkbox is checked, then run the query which only returns customers that are active. Otherwise run a query which returns all customers Example script <?php // default value, set to 1 to search for active customers $searchActive = 1; // if a POST request is made if($_SERVER['REQUEST_METHOD'] == 'POST') { // override default value. If the checkbox is checked, then set to 1 otherwise set to 0 $searchActive = isset($_POST['isActive']) ? $_POST['isActive'] : 0; } echo 'Searching only active customers: ' . (($searchActive == 1) ? 'YES' : 'NO'); $query = 'SELECT * FROM customers'; if($searchActive) $query .= ' WHERE active = 1'; echo '<br/>Query:<pre>' . $query . '</pre>'; ?> <form method="post"> Active : <input type="checkbox" name="isActive" value="1" <?php echo $searchActive ? ' checked="checked"' : ''; ?> onClick="form.submit();" /> </form>
  18. That code only defines a string which is assigned to a variable. The string is made up of characters , which only us humans will know is JavaScript code. PHP will not know this. The Javascript code will not be ran when that variable is defined. The javascript will only be ran when the browser receives the output from your PHP script PHP only runs server side. JavaScript runs client side (the browser). What loop? What is it are you trying to do.
  19. That is only way in PHP you can get the value of a checkbox (or any other type of form input). PHP only runs when a HTTP request is made to the server, ie when the form is submitted. PHP cannot respond to events happening in the browser.
  20. With images you got not other choice. In order for a browser to display an image it must be stored in a public accessible folder. To validate whether the image you have is valid use getimagesize.
  21. Any where provided the folder you store the images in is publicly accessible by your http server. For example your websites document root folder (the folder where you upload the files for your website).
  22. Its not your function that was causing it. Its to do with floating point arithmetic, see the link in requinix reply.
  23. Umm, number_format is for well formatting numbers not just rounding. Rounding will only occur if are reducing a higher precision number to a lower precision number. There is no need for your RestorDecimal function, when number format will do that for you.
  24. The you should be using $_SESSION['user'] not $_SESSION['user_id'] in your code.
  25. What is the output of var_dump($_SESSION);
×
×
  • 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.