Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. To do that you'll have to get the news article title before you output the <title></title> tags.
  2. So you're wanting to append the title of the news article to your existing title in the <title></title> tags?
  3. Two second search on php.net for the word count results in count count($object->GetMediaListResult->string);
  4. To understand this better. you'll want to look at the MVC design pattern.
  5. Ch0cu3r

    ID to GUID

    kicken meant in your SQL query <?php if (isset($_REQUEST["guid"])) { $guid = mysql_real_escape_string($_REQUEST["guid"]); // sanitize the guid $query = "SELECT * FROM news WHERE news_guid='".$guid."'"; $result = mysql_query($query); $row = mysql_fetch_array($result); ?>
  6. Sorry I don't understand that. You saying you don't want the user to be redirected from profile.php if the id doesn't exist?
  7. On way would be to check that $_GET['id'] exists before calling the checkUser() method in profile.php. If no id found in _GET then display error. Example if(isset($_GET['id']) && is_numeric($_GET['id'])) { //call checkUser } else { echo 'Sorry, requested user profile requested doesn\'t exist'; } Or in checkUser method, save an error message to $_SESSION before header(); if($rows == 0) { $_SESSION['error'] = 'Sorry user profile was not found'; session_write_close(); // may need to call this before redirect header("location: events.php"); } Then in event.php check to see if the error exists and display the error message if(isset($_SESSION['error'])) { echo '<div class="error">' . $_SESSION['error'] . '</div>'; unset($_SESSION['error']); // remove error from session to stop it being shown again }
  8. Not sure but maybe $source = ''; if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/') $source = '?source=' . $_SERVER['REQUEST_URI']; header("Location:http://www.mobiledomain.com/$source"); Now $_GET['source'] will contain the request url before being redirected to your mobile site.
  9. @igen121 how is that helping? @Pradeep_Chinna Post delete.php here. How are you implanting my code example? if mysql_affected_rows() returned -1 then the SQL query is failing, probably due to an error. You can see what the error is using mysql_error When posting code, please paste code into the code tags by clicking the <> button.
  10. Heredocs can easily lead to errors like this. You need to be extra careful with them. A better approach to heredoc would be to dump your html into seperate files and then just include them as templates.
  11. I think I see the problem. The functions you posted is retrieving the results from the database and putting them into the $this->rows and $this->row variable and then trying to use the latter variable in other methods. You should no do this, as each query is overwriting the $this->row variable when you get the results. What should do is pass the values that the method (countTotalattendents, and isAttending) needs as arguments. Do not store the database results in $this->row variable unless your class needs to remember the results, which it doesn't. Each method needs separate results from the queries you're running. So save the results from your queries to local variables and pass the data to the countTotalattendents, and isAttending methods as arguments I have modified your methods so it saves results to local variables and not to $this, and passes the event_id to countTotalattendents, and isAttending methods as arguments public function participateEvent() { $query = "INSERT INTO user_events (eventID, userID) VALUES (:event_id, :user_id)"; $stmt = $this->connect->prepare($query); $stmt->execute(array( ':event_id' => $_POST['event_id'], ':user_id' => $_SESSION['user_id'] )); if($stmt->rowCount() == 1) { return true; } else { $this->error[] = "Emme pystyneet lisäämään sinua tähän tapahtumaan"; } } public function countTotalattendents($event_id) { $query = "SELECT COUNT(userID) AS total_attendents FROM user_events WHERE eventID = :event_id"; $stmt = $this->connect->prepare($query); $stmt->execute(array( ':event_id' => $event_id )); if($stmt->rowCount() == 0) { $count = 0; } else { while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $count = $row['total_attendents']; } } return $count; } public function isAttending($event_id) { $query = "SELECT eventID, userID FROM user_events WHERE eventID = :event_id AND userID = :user_id"; $stmt = $this->connect->prepare($query); $stmt->execute(array( ':event_id' => $event_id, ':user_id' => $_SESSION['user_id'] )); $isAttending = $stmt->rowCount(); return $isAttending; } public function showAllEvents() { $query = "SELECT * FROM events LEFT JOIN users ON users.user_id = events.creatoruserid WHERE events.creatoruserid != :user_id AND CURDATE() <= events.event_date ORDER BY events.event_creation_date DESC"; $stmt = $this->connect->prepare($query); $stmt->execute(array( ':user_id' => $_SESSION['user_id'] )); $rows = $stmt->rowCount(); if($rows >= 1) { $i = 1; while($i <= $rows) { $row = $stmt->fetch(PDO::FETCH_ASSOC); $today = strtotime(date('Y-m-d')); $event_date = strtotime($row['event_date']); $days = (abs($event_date - $today) / 86400); if ($days == 0) { $days = " Tänään"; } else if ($days == 1) { $days = $days. " päivä"; } else { $days = $days. " päivää"; } // Echo the user-event div part echo "<div class='black-show-name'> <a href='profile.php?id=".$row['user_id']."'>".$row['name']."</a> <div class='tri_angle'></div></div> <div class='user-event-header' > <input type='hidden' value='".$row['event_id']."' /> <img src='images/thumbnails/".$row['profilepic']."' class='profilesmall'/> <h2><ul class='event-heading'> <li class='event_city' title='Paikkakunta'>".ucfirst($row['event_city']). '</li> <li class="event_name" title="Tapahtuma">' .ucfirst($row['event_name']). ' </li> <li class="event-date" title="Päivämäärä">'. date("d.m.Y", strtotime($row[ 'event_date'])). ' '. date("G:i", strtotime($row['event_time'])). ' <small>('.$days .')</small></li> <li class="event-created" title="Alkuun"> Osallistujia: '. $this->countTotalattendents($row['event_id']). " </li> <li class='event-attend' title='Näytä lisää'> <button id='show-more' class='medium-button-new'>+</button></li> </ul></h2> </div> // Echo out the event div <div class='event'><p>Osoite: " .ucfirst($row['event_address']). "</p> <p>Tapahtuman päivämäärä -ja kellonaika: " .date('d.m.Y', strtotime($row['event_date']))." " .$row['event_time']. " <p>Tapahtuman osoite - ja kaupunki: " .ucfirst($row['event_address']). ", " .ucfirst($row['event_city'])."</p> <p>Tapahtuman kuvaus: " .ucfirst($row['event_description']). "</p> // If is attending, echo the remove attend button <div class='right_area'>"; if($this->isAttending($row['event_id']) == 1) { echo "<form action='".$_SERVER['PHP_SELF']."' method='post'> <input type='hidden' name='event_id' value='".$row['event_id']."'/> <input type='submit' name='remove_attend' value='Peru osallistuminen' class='medium-button-remind' /> </form>"; } else { echo "<form action='".$_SERVER['PHP_SELF']."' method='post'> <input type='hidden' name='event_id' value='".$row['event_id']."'/> <input type='submit' name='attend_event' value='Osallistu' class='medium-button-attend' /> </form>"; } echo "</div></div>"; $i++; } // No events } else { echo "<p>Ei näytettäviä tapahtumia</p>"; }
  12. On line 703 remove the spaces after INTERNATIONAL_LIST_CAT; the closing heredoc delimiter cannot have anything directly after it other than a newline. You have about about 32 spaces after it, this is what is causing the erro
  13. Sorry meant to say spend.php But where is spend.php is it in the same folder as bombcutting.php?
  14. The form is submitting to submit.php. The code you posted is fine and is outputting the form. Something somewhere else is causing this, most likely with your .htaccess. Disable the htaccess and see what spend.php is doing.
  15. Can you post the error messages(s) in full here, and can you explain your problem with more info. Such as what was you doing, what should the script do etc?
  16. PHP can't do that, it doesn't know what javascript is. You can only get PHP to output the necessary javascript code that loads the chat rooms. You can do a for loop loop that outputs the javascript code needed for the chatrooms eg for($i = 1; $i <= 6; $i++) { // target chatroom echo "var dc_chatroom_id = document.getElementById('$i');"; // load the chatroom echo "javascript_function_that_loads_chatroom(dc_chatroom_id);" } But If you're doing that then you may as well handle this with javascript and not PHP. The above PHP code will output the following javascript code var dc_chatroom_id = document.getElementById('1'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('2'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('3'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('4'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('5'); javascript_function_that_loads_chatroom(dc_chatroom_id); var dc_chatroom_id = document.getElementById('6'); javascript_function_that_loads_chatroom(dc_chatroom_id);
  17. PHP cannot call javascript functions. PHP is ran on the server and Javascript in the browser. PHP can only output javascript. I think this line var dc_chatroom_id = <?php echo $chatroom_id = document.getElementById('id'); ?>; needs to be var dc_chatroom_id = document.getElementById('<?php echo $chatroom_id; ?>'); Example output of above line would be like the following if $chatroom_id is set to 1 var dc_chatroom_id = document.getElementById('1');
  18. Lines that start with a # are ignored in the hosts file and httpd.conf file. Each domain that maps to an ipaddress needs to be on its own line. This is how your host file should look like 127.0.0.1 localhost 127.0.0.1 www.mytestingwebsites.com Now localhost and mytestingwebsites.com will map back to the local loop back address 127.0.0.1 In the httpd.conf file you set up the ServerName using (lines that start with a # are ignored) ServerName www.mytestingwebsites.com:80 If you want to access both http://localhost/ and http://mytestingwebste.com/ but to serve files from different locations you'll need to set-up name based virtual hosts. Otherwise leave the above line commented out and set the Listen directive to Listen 127.0.0.1:80
  19. Please when posting code, paste it into tags (click the <> button before posting message). How you should log in a user is to query the database with the user/password credentials they provided. The query should retrieve all their data you need when the username/password matches. Example query would be SELECT user_id, password, email, time_of_last_login, access_lvl, etc.. FROM users_table WHERE username=$username AND password=$password When the username/password matches it'll return all the info in the SELECT clause. You store this information to the $_SESSION variable. You should not be having to re-query the database to get more information about them. To see if they are logged in you just checked the $_SESSION variable validates to your requirements. The basic way to do this is to set a $_SESSION['is_logged_in'] variable to true when the user successfully logs in. For any page that requires the user to be logged in you check this variable is true eg <?php session_start(); if(isset($_SESSION['is_logged_in']) && $_SESSION['is_logged_in'] === true) { // user is logged in display page } else { // user is not logged in // display error and login form } When logging users out you just clear the $_SESSION variable with unset. To completly remove the session you'd use session_destroy.
  20. Ch0cu3r

    ID to GUID

    If the GUID is already in the database, then you just got to change the part in your PHP code that fetches/receives the id and change it to guid. For example you'll have code like this to output links echo '<a href="site.com/?id=' . $row['id'] . '">link text</a>'; needs to be changed to echo '<a href="site.com/?guid=' . $row['guid'] . '">link text</a>'; Any references to $_GET['id'] needs to be changed to $_GET['guid']. And change your queries to fetch records that matches the guid and not id, eg SELECT * FROM your_table WHERE guid = $guid All you're doing is renaming variables
  21. insta_deals needs to be wrapped in quotes. otherwise mysql will treat it is a column name, not a column value
  22. What does the PHP code currently output? any errors/messages etc. What is it doing now? What should it be doing? Your form code should work with the changes I suggested earlier. I have tested the form code and php code and it is uploading files. However this line if (($_FILES['file']['size'][$x] > 1048576) && (in_array($file_ext, $allowed_ext) == false)) had to be changed to if ($_FILES['file']['size'][$x] > 1048576 || !in_array($file_ext, $allowed_ext) To stop non .doc, docx and .pdf files from uploading.
  23. Did my reply help? http://forums.phpfreaks.com/topic/282688-del/?do=findComment&comment=1452473
  24. Make sure the date.timezone directive is set to your timezone within the php.ini file. List of supported timezones
  25. Fixed code. <?php $start_weight = 180; $start_body_fat = 27; $start_body_fat_percent = $start_body_fat/$start_weight * 100; $pounds_lost = 15; echo "Starting weight is: ".$start_weight." Starting body fat is: ".$start_body_fat_percent."%<br />"; for($i = 1; $i <= $pounds_lost; $i++) { //work out new body weight, take $i from $body_weight*/ $new_weight = $start_weight - $i; //recalculate body fat percentage, take $i from $start_body_fat and divide by new body weight and times by 100 $new_body_fat_percent = ($start_body_fat - $i)/$new_weight *100; // clean up $new_body_fat_percent; $new_body_fat_percent = number_format($new_body_fat_percent, 2, '.', ','); // output how many pounds lost ($i), new weight and body fat percentage echo "After losing $i pounds of fat weight is now: $new_weight, body fat is: $new_body_fat_percent%<br />"; } ?>
×
×
  • 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.