Jump to content

merylvingien

Members
  • Posts

    267
  • Joined

  • Last visited

Everything posted by merylvingien

  1. I have a bb code setup and did it like this: $simple_search = array( '/\[font\=(.*?)\](.*?)\[\/font\]/is', '/\[size\=(.*?)\](.*?)\[\/size\]/is', '/\[color\=(.*?)\](.*?)\[\/color\]/is', ); $simple_replace = array( '<span style="font-family: $1;">$2</span>', '<span style="font-size: $1;">$2</span>', '<span style="color: $1;">$2</span>', ); $text = preg_replace ($simple_search, $simple_replace, $text); Hope this helps
  2. In answer to all of your questions, bad habits! What i know about php coding is what i have picked up from the internet, never been on courses or read any books, so i have picked up habits and bad coding along the way. But your comments have been taken on board.
  3. Problem 1 sorted, i knew i had overlooked something, but couldnt see the wood for the trees. Problem 2 i am still working on getting the code sorted out, i am researching the max() function at the moment. But i am not the best with arrays. Thanks for your help though, much appreciated.
  4. Hi folks, i have a complex problem (for me anyway) but i am sure with your help this can be sorted. Problem number 1: I have a simple while loop, but its only showing 4 results when i know there are 5 I am missing something very simple i know: $sql = ("SELECT * FROM postcode WHERE unid='1'")or die ('<p>There seems to be a problem, please try again soon.</p>'); $result = mysql_query($sql,$con); $row = @mysql_fetch_array($result); $i=0; while ($row = @mysql_fetch_assoc($result)){ echo "newpoints[". $i++ ."] = new Array({$row['lat']}, {$row['long']}, icon0, '{$row['postcodename']}', '{$row['postcodename']}'); \n"; } What am i missing here? Problem number 2: I have a bunch of latitude and longitude codes stored in the database. On each page there will be a varied amount of these codes used, but with a max of 20. I need to find the highest number and the lowest number of each lat and long then come up with a code that is in the middle, the idea of this is to center a map. So for example there will be an array like this: 50.852293 -1.76088 51.252938 -0.76128 51.259583 -0.727168 51.274 -0.837 51.123106 -0.970657 First i need to find the highest number of the first code (51.274) then the lowest number (50.852293) and then the highest number of the second code (-1.76088) then the lowest number (-0.727168) Then work out an inbetween code using the highest and lowest codes for each. Does anyone have a clue how to go about this? I am not the worlds best array technition or mathematician
  5. Hi fellas, this is really kicking my arse and i know its so simple! I retrieve a date from the database, done! I am manipulating it to display as i want, done! How the hell do i add 365 days to this date? $date= ($row['date']); $subscription = strtotime($date); echo "<p>Subscription renewal date: ". date('l jS F Y', $subscription) . "</p>";
  6. Its always going to include "home.php" becuse you havent declared what $page is from the url.
  7. You need to look into mod rewrite, the apache section has a mod rewrite sub forum
  8. What if the user doesnt have thunderbird? I take it they are writing the message? If so why not just display thier message as you intend it to be displayed on the page below the input form? Easily done with ajax, as they write, the text appears just below the input box, but formatted how you want it...
  9. I recently had someone asked about password storage and retrieval The way i have done things on my site, not one worth hacking by the way! anyway, all passwords are hashed using md5, and also a unique hashed code is also stored in the database. So from the time the user first enters thier password on registration, apart from login, we are always dealing with a hashed password. If they forget thier password, obviously we cannot decrypt thier password, so they enter thier email address into a password reset box This sends them a email with a link, with the unique code as part of the link. Using the get method, you retrieve the code, check against the code in the database, if it matches the user can then reset thier password. A new unique code is then generated and updated in the database, so its a one shot code. Once used cannot be used again! I have run into issues using sessions, cross contimination of session id's etc, be extra carefull when setting session id's and where you use them....
  10. Just reviewing a log in script that i have here and working. Why are you setting the session right away? The way i would do this ( and i am no mean coder by the way ) <?php include('dbconnect.php'); if (isset($_POST['username'])) {$username=$_POST['username'];} $username= mysql_real_escape_string($username); if(isset($_POST['pw'])) {$pw=$_POST['pw'];} $pw= mysql_real_escape_string($pw); $q="SELECT * FROM `users` WHERE ((username='$username') AND (pw='$pw'))"; $result= mysql_query($q) or die ("Could not execute query : $q." . mysql_error()); if (mysql_num_rows($result) == 0) { session_start(); $_SESSION['login_username'] = ""; header ("Location: loginpage"); } else { $r=mysql_fetch_array($result); $login_username=$r["username"]; session_start(); $_SESSION['login_username'] = "$login_username"; Header("location: protected.php"); } ?> Or something along those lines LOL
  11. Hi fellas, having a bit of trouble getting a count from the database where the field is not empty? $count= "SELECT COUNT(unid) FROM table"; $result2 = mysql_query($count) or die("Select Failed!"); $counter = mysql_fetch_array($result2); echo $counter[0]; From what i have read, this should get all the not null results from the field, but it gets all of them. Some are empty, the ones i want have various id numbers in them. Is there a way to get just the numbers where there is an id number present?
  12. Thanks for the replies, i will have a play and see what i can achieve.
  13. Thanks for the replies maybe i should explain more clearly. I have a table which has 4 collumns, name, email, weblink, phone When a new user signs up, i want to check this table to make sure they havent signed up in the past. So i need to run through each collumn to check that the name they entered isnt allready listed, email isnt listed, weblink isnt listed etc. So, does this mean that i need to make a query for each seperate collumn? Or can i not just select all, then run through the various checks? As i said, i have got myself confused with this one.
  14. I think i have muddled myself up here somewhere along the line I am trying to check to see if various things already exists in a database. So for example i have a collumn with names, second collumn is email address, third collumn phone number etc. So i make the usual connection to the database: $sql=("SELECT * FROM table") $result = mysql_query($sql); $row = mysql_fetch_array($result); Now to assign the various collumns is where i have come unstuck. if (in_array("?", $row)) {do something} or is it if (in_array("?", $row['name'])) {do something} ? I have it working by hard coding to a seperate php file, but its bulky and would prefer to use the database.
  15. SELECT email FROM should be either SELECT email, nextcollumn, anothercollumn, etc FROM Or, if you want to pull all the collumns from the database: SELECT * FROM Then just echo each row as you want it: echo "Email: " . $row['email'] . "and" . $row['nextcollumn']; etc
  16. Having just glanced quickly at this post, whats the code of the form you are using to get the user details? Make sure you have named the input boxes correctly!
  17. For what its worth I always quote my echo statements. echo "$exercise"; echo "$duration"; echo "$distance";
  18. FYI incase your interested the fix was this: if (empty($results)) {$output= "No results found!";} elseif ($results > 0){$output = "<p>Your search term: " . $q . " returned:<br><br>" . implode("", $results); } echo "$output";
  19. Hi folks, i am trying to impliment a ajax php search function to my site, but just stuck on how to prevent a undefined variable Here is thee ofending code: <?php $con = mysql_connect("localhost", "root", ""); if (!$con) { die('<p>There seems to be a problem, please try again soon.</p>'); } $db_selected = mysql_select_db("database",$con); //get the q parameter from URL $q=$_GET["q"]; //lookup all links from the xml file if length of q>0 $sql="SELECT * FROM simp_search WHERE `sbody` LIKE '%{$q}%' OR `varia` LIKE '%{$q}%' OR `stitle` LIKE '%{$q}%' ORDER BY `stitle`"; $result = mysql_query($sql); if (mysql_num_rows($result) < 1) { $error[] = "<p>Please try another search..."; }else { $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($result)) { $results[] = "{$i}:<a href=\"http://www.mysite/{$row['url']}\">{$row['stitle']}</a><br />{$row['sbody']}<br /><br />"; $i++; } } function removeEmpty($var) { return (!empty($var)); } if ($results > 0){$output = "<p>Your search term: " . $q . " returned:<br><br>" . implode("", $results); } else {$output= "No results found!";} echo "$output"; ?> At the moment its a mishmash of code from other applications. Works fine if you insert a search term that is in the database, however if you enter something that doesnt match, the output is: Notice: undefined variable: results in C:\www\website\livesearch.php on line 35 No results found! Any ideas on what to change to prevent this? Also i know there is some code in there that is not needed.
×
×
  • 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.