Jump to content

Yesideez

Members
  • Posts

    2,342
  • Joined

  • Last visited

Everything posted by Yesideez

  1. Whenever I use the CODE and /CODE tags to surround my code I always have to go and edit my post to re-format the code as actual tabs seem to get added in at seemingly random places. I don't have any tabs in my code as I only ever use spaces and two spaces per intent level.
  2. FIXED! Somehow my try...catch section, the die() statement I've passed it two parameters as the . to concatenate strings turned into a comma. No idea how that happened but I've changed it to a . and it's all now working perfectly. Although I have no error message appear telling me there was a problem with it.
  3. I've got XAMPP installed onto two machines. This (my primary machine) is running Manjaro and my laptop behind me is running Mint. I've rebooted my laptop and I can no longer find any application in the launch menu (Start menu on Windows) called LAMPP or XAMPP. Tried typing LA and XA and get nothing returned. How do I launch it please?
  4. I have the following code and yesterday this was working and now I get nothing sent to my browser... <?php ini_set('display_errors','1'); //only during development ini_set('display_startup_errors','1'); //only during development error_reporting(E_ALL); //only during development $options=[ PDO::ATTR_EMULATE_PREPARES => false, // turn off emulation mode for "real" prepared statements PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //turn on errors in the form of exceptions PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, //make the default fetch be an associative array ]; try { $pdo=new PDO("mysql:host=localhost;dbname=polthouse",'root','',$options); } catch (PDOException $e) { die('Connection failed: ',$e->getMessage()); } phpinfo(); ?>
  5. Thanks guys, I've changed it all over to PDO and finding it a lot easier. I decided to use MySQLi as I'd previously used MySQL years ago and thought it would be the natural progression and had no idea about PDO.
  6. Is it possible to get the number of rows returned when using a SELECT query and a statement? $sql="SELECT * FROM users WHERE username=? AND password=? AND active=1"; $stmt=$db->stmt_init(); if ($stmt->prepare($sql)) { $stmt->bind_param("ss",$uname,$pword); $stmt->execute(); $stmt->bind_result($id,$username,$password,$level,$added,$edited,$active); $stmt->fetch(); echo "Matched: ".$stmt->num_rows.'<br>'; echo "id: ".$id."<br>Added: ".$added."<br>"; $stmt->close(); The "Matched" line always gives me 0. I've tried added parenthesis to make it num_rows() and I still get 0 regardless of whether my query returns data from my table or not. I've checked in the PHP manual and it doesn't give an example using a statement.
  7. Correct - Noticed that just after I posted it and couldn't figure out how to delete my post. I missed another later on as well. For some reason it gives me error messages but I don't get error messages when I miss a semi-colon 😕
  8. It's been many years since I did any of this stuff and just getting back into it. I did think of posting this in the mysql section but it's more of a code problem. I have the following... $db=new mysqli(host,username,password,database); $sql="SELECT * FROM users WHERE username=? AND password=?"; $stmt=$db->stmt_init() That last line where I call $db->stmt_init() I get an empty browser - absolutely nothing where I should have a load of HTML appear. I have written the rest (just in case it matters) which is: if ($stmt->prepare($sql)) { $stmt->bind_param("ss",$uname,$pword) $stmt->execute(); $stmt->fetch(); echo "id: ".$id."<br>Added: ".$added."<br>"; $stmt->close(); }
  9. Take a look at PHPMailer. http://phpmailer.worxware.com/ It's free to download and use and is fairly simple to set up, should be what you're looking for.
  10. You can use Javascript to hide the submit button as soon as it is clicked. Just a thought.
  11. Just remembered - some land line numbers in smaller villages are still only 5 digits so where mobile numbers will always be 11 digits, land line (01) numbers can be either 10 or 11 digits. 01xxxxxxxx or 01xxxxxxxxx or 07xxxxxxxxx
  12. I've got a site where users can make posts and I need to check for the presence of phone numbers. Phone numbers can either be 01xxxxxxxxx or 07xxxxxxxxx depending on land line or mobile (total of 11 digits). I think the easiest way to check is to strip out any non-numeric character (can this be done with regex?) which will bring all numbers together, then check with a much simpler regex. I need an if() to check for the presence of either number and return true or false. Big problem is, I've tried to learn this (wasted many hours) and can't get my head around it. Any help would be gratefully appreciated.
  13. A friend has a company on which he currently has a database in MS Access 2007 which is shared on his local network in the office. When he designed and created the database he didn't link two main tables together and now it's grown to over 12,000 records he's asked me to take a look at it. I've successfully converted the data over to MySQL although we're unsure my code has auto linked all the data together that should be so this will require some time in itself. The reason I've emigrated it to MySQL is because there's some things he's asked me to do for him like generate PDF files on the fly of properties when desired and other stuff where PHP is ideal. Ideally he'd like to keep his database running on MS Access because he knows how to edit this (very much still a beginner although he's much better than I am) and he wants to make sure he'll not become unstuck in the future if his database needs attention and I'm not around - him learning PHP/MySQL/HTML is not an option. I've heard PHP can talk to a MS Access database but I've no idea where to start with this - I have dyspraxia so learning how this could be done might take a very long time. He'd also like to give clients a login so they can view/progress info on their properties and logins for his staff so they can view their stuff. All this I can do but the initial problem is his database. It only has two tables, one listing all his customers and the second listing all the work carried out. Although all properties relate to data in the work table not all work can relate back as some work would be a one-off job. What I'd like to know please is how would you tackle this?
  14. I thought this was going to be a pig. The option of only limiting certain words isn't really possible due to the nature of the site. I did think of trying soundex but then, splitting a subject string into separate words then calculating soundex for each and comparing was again a bit off as soundex values aren't unique and, well, soundex values are strings so we're back to square one. Tricky. I think this idea will be binned.
  15. Without any type of help regarding what it is you want to achieve it's pretty difficult but if your "id" field is set to AUTO_INCREMENT then it might not return anythign as AI starts counting at 1 and never 0. If you want to return the total you can use this instead: $total = mysql_query("SELECT COUNT(*) AS total FROM comments WHERE id=0"); $row=mysgl_fetch_assoc($total); echo $row['total']." Clicks\n"; If you're not wanting the SUM() then try TOTAL() but not sure entire what it is you're wanting to do.
  16. I've got a site where people can place posts and I'm wanting to implement a system where users can have up to 5 words in a watch list. When someone makes a post and uses one of these watch words I'd like to fire off an email to whoever has placed a match word in their watch list informing them of the post. Only problem is, I've no idea which is the best way to do this. The database can potentially grow very big and I'm not happy using a LIKE or a stripos() as I'd like to keep the routine optimised as much as possible to help save resources. If there isn't any simple way of doing this then I'll knock it on the head. The watch list will be used on a VARCHAR(40) which is kind of like a subject string.
  17. You're right - well spotted I had no need to access that table in this call and no idea why I tried adding it. EDIT: I also removed GROUP BY as it wasn't needed. What is needed is some sleep ><
  18. I think I'm far too tired. I removed the line joining the users table and it works perfectly.
  19. SELECT i.*,tp.x,tp.y FROM items AS i INNER JOIN users AS u ON u.postcode=sp.outcode INNER JOIN postcodes AS sp ON sp.outcode='EX8' INNER JOIN postcodes AS tp ON tp.outcode=i.outcode WHERE ((tp.x<(sp.x+16093.44) AND tp.x>(sp.x-16093.44)) AND (tp.y<(sp.y+16093.44) AND tp.y>(sp.y-16093.44))) AND i.description LIKE '%apple%' GROUP BY i.id ORDER BY i.added DESC The error I get is "#1054 - Unknown column 'sp.outcode' in 'on clause'" Any idea on how I can get around this please?
  20. I did try this: SELECT u.userid,u.username,z.active,z.idle FROM users AS u LEFT JOIN onlinetime AS t ON u.userid=t.userid LEFT JOIN (SELECT userid,SUM(active) AS active,SUM(idle) AS idle FROM onlinetime) AS z ON u.userid=z.userid Doesn't work Tried this as well to no avail: SELECT u.userid,u.username,z.active,z.idle FROM users AS u LEFT JOIN (SELECT userid,SUM(active) AS active,SUM(idle) AS idle FROM onlinetime) AS z ON u.userid=z.userid ORDER BY z.active DESC LIMIT 20
  21. I've got a couple tables: users; onlinetime The users table contains loads of info including userid, username, activitycount and the onlinetime contains id, userid, date, active, idle. The field userid is what ties both tables together and active and idle are both integers (seconds). Where the users table has one entry per user (as is normal) the onlinetime table can have multiple entries per user. What I need to do is make a query to list all the users who have activity count as 0 and the sum(active) in onlinetime below a certain number, let's say 100. If the onlinetime had only one entry per user I'd be able to write the query but it's the multiple entries in the onlinetime table that's throwing me.
  22. Oh wow is it really that simple? Thank-you for that - really is appreciated!
  23. Hi, I have a page of HTML and inside this page is a TABLE and it's this table I need to extract some data from. <th>Proxy:</th><td><span class="red">Confirmed proxy server.</span> (<a href="/proxy-server">Read about proxy servers</a>)</td> The first TH cell will always have that content but I need to extract everything between the next TD cell including the HTML. I can strip any HTML out myself if present, just needing help with Regex as I have no clue whatsoever about this as I just cannot get my head around it and I've spent hours! Any help with this would be gratefully appreciated.
  24. Sorry query should be: $checkuser=mysql_query("SELECT `id` from `tbl_users` where username = '".$user."' and password='".md5($password)."'");
  25. Oh, and rather than store the username and other info of a successful login inside session variables - store the row ID number instead then just look that up each time. $checkuser=mysql_query("SELECT `id`,`forename`,`usertype` from `tbl_users` where username = '$user' and password='".md5($password)."'");if (mysql_num_rows($checkuser) > 0) { //have we got any results to process? $row=mysql_fetch_assoc($checkuser); $_SESSION['uID']=$row['id']; header("Location: index.php"); exit; } else { //if not display login form with message that says logon details are incorrects echo 'Do something else' ; } Then on other scripts read the user details from the uID session var from the user table each time and validate there.
×
×
  • 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.