-
Posts
2,000 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Andy-H
-
Also note the exit statement after the header redirect, you should make sure you do this after a header redirect as a matter of good practice, this will stop script execution. You don't need the parentheses on the exit statement if no argument is given as exit is a language construct, so the following are equivalent: exit(); exit;
-
Does the channel name actually contain a colon?
-
How to find 2 or more words in a string with preg_match?
Andy-H replied to noidea's topic in Regex Help
Yeah but his code allowed a variable number of matches to be made, if the array passed contained say 7 patterns, it would call preg_match dynamically 7 times.- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
Looking at 4.2.1 here, it looks like it should be: fwrite($socket, "JOIN #channel; channelkey\r\n");
-
I assume you're sending text messages, are you sure restrictions on IP addresses are the best way to go? You may be better off restricting on a per-user basis, as multiple users could use the same computer.
-
How to find 2 or more words in a string with preg_match?
Andy-H replied to noidea's topic in Regex Help
You may also want to use word boundaries (\b) to do an exact word match only, given the following string: My name is Andy. Matching /and/i would return true whereas matching /\band\b/i would return false. See http://www.regular-expressions.info/wordboundaries.html I don't know if you use OOP but you would probably be best grouping things like this into a static class, so to start you off: class Regex { public static function test($expressions, $term) { if ( !is_array($expressions) ) { $expressions = array($expressions); } return count(array_filter($expressions, function($expression) use ($term) { return preg_match($expression, $term); })); }} var_dump(Regex::test(array('~and~i'), 'My name is Andy')); // => int 1var_dump(Regex::test(array('~\band\b~i'), 'My name is Andy')); // => int 0var_dump(Regex::test(array('~\bname\b~i', '~\bandy\b~i'), 'My name is Andy')); // => int 2 This uses array_filter to iteratively match the regular expressions against the given string, returning false to the array_filter callback removes the elements from the array, so by returing a count of the remaining arrays elements, we can use the returned integer as a boolean value.- 13 replies
-
- preg_match
- search
-
(and 1 more)
Tagged with:
-
How check an existing record with PHP MySql
Andy-H replied to dadedidhodong's topic in PHP Coding Help
$sql = mysql_query("SELECT * FROM tbl_student WHERE stud_laneme = '".$_POST["lname"]."' AND stud_fname = ".$_POST["fname"]."',"); $result = mysql_query($sql); The single quotes are messed up in your query, also you run mysql_query on the resource returned from mysql_query, and you should use mysql_real_escape_string to prevent SQL injection, it should be: $sql = "SELECT * FROM tbl_student WHERE stud_laneme = '". mysql_real_escape_string($_POST['lname']) ."' AND stud_fname = '". mysql_real_escape_string($_POST['fname']) ."'"; $result = mysql_query($sql); In addition, if you're only looking for one result, appending LIMIT 1 will stop mysql from continuing it's search once it has found a result, and mysql_ functions have been deprecated, you should look into pdo or mysqli As for your original problem, that will be down to the duplicate mysql_query- 4 replies
-
- php
- check existing record
-
(and 1 more)
Tagged with:
-
I think the design of a porn site is the least important aspect, there's one focal point and it's going full-screen. That's why they're covered with bullshit like "Gain 2" in 6 weeks" and "Horny singles ready to...". Content is king in that game.
-
Web design is "the part I can't do", the skill that requires the visual creativity I don't possess, to take a blank canvas and craft a stunningly beautiful webpage in the form of a PSD. Beyond that, I'm your man.
-
I think it would be good if PHPFreaks were integrated with Linkedin, so you would go to your profile, add your link, then people can send a linked in invitation from your PHPFreaks profile, and say if you reply in a PHPFreaks board, you could associate topics, I.e. PHP Help would associate to the PHP skill on your profile, then there could be a link for "Endorse {USER} for skill {SKILL}" i.e. "Endorse Andy-H for PHP" What do you think?
-
The link I posted is pretty much example questions, with multiple choice answers, followed by a short explanation of the question.
-
I passed it recently, didn't find it that difficult to be honest. l bought a prep guide from Lorna Mitchells website (http://www.lornajane.net/posts/2013/become-a-zce-in-2013) but never got round to reading it prop looked pretty comprehensive though. About 15 quid or something.
-
He has a valid point here, the OP posted code that attempts a header redirect after outputting a td tag, without output buffering, this will cause the header call to fail.
-
Quoted wrong post.
-
Nope, that's all you need, it will work for anything: var_dump(str_replace(array('www.', '.mysite.com'), '', ('www.r34l-crazy.u53rn^m3$./john.smith?/i.mysite.com'))); // => r34l-crazy.u53rn^m3$./john.smith?/i
-
var_dump(str_replace(array('www.', '.mysite.com'), '', ('www.john.smith.mysite.com'))); // => "john.smith" var_dump(str_replace(array('www.', '.mysite.com'), '', ('john.smith.mysite.com'))); // => "john.smith"
-
+1 on Linux Mint, really user friendly for a Linux flavour, love MATE desktop for usability but Cinnamon looks nicer. MATE always wins in the end, I'm no Mac owner
-
Please use b1bc30a58b6ac5c9d1852f6bde30710e tags in future; my eyes hurt
-
I don't get what you mean? You only need to "fetch" the data once and store it to a variable, then use the variable to check the value. Also, I am assuming username is unique, so you don't need a loop and can use a LIMIT 1 on your query. Also, do you know that the mysql_ functions are deprecated? You should look into mysqli or PDO You shouldn't really use select * when you're only using one field either. Anyhow, I would rewrite the above like so: // connect to database include 'db/connection.php'; // it would be best to connect to the database in a self contained file for re-use // we will use mysql_real_escape_string to prevent SQL INJECTION $query = "SELECT accesslvl FROM $tbl_name WHERE username = '". mysql_real_escape_string($myusername) . "' LIMIT 1"; $result = mysql_query($query); if ( !mysql_num_rows($result) ) { // login failed, give an error message } else { $user = mysql_fetch_object($result); // we can use a switch statement here rather than if/elseif/else... block, this way we can add a default and it will be easier to add more cases later switch($user->accesslv) { case 1: header('location: adminhome.php'); exit; // we should use exit after header location break; case 2: header('location: managerhome.php'); exit; break; default: header('location: userhome.php'); exit; break; } } See: switch mysql_real_escape_string
-
PDO try{} catch{} error with database information.
Andy-H replied to Zeroi9's topic in PHP Coding Help
The Exception is being thrown from PDO::__construct so you need to wrap ... new PDO(... in the try catch block like so: try { $pdo = new PDO("mysql:host=localhost;dbname=dbdaev", "root", ""); $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); } catch ( PDOException $e ) { echo $e->getMessage(); exit; // no point in continuing without a connection } I also like to use the following when using PDO: $dbh->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, sprintf( 'SET NAMES \'%1$s\' COLLATE \'%2$s\';'. 'SET CHARACTER SET %1$s;', 'utf8', 'utf8_general_ci' ) ); To avoid encoding issues -
$redirect_to = array(1 => 'admin', 'manager'); $query = "SELECT accesslevel FROM users WHERE..."; $sth = $dbh->prepare($query); $sth->execute(array('param', 'param2')); if ( ($access_level = $sth->fetchColumn()) !== false ) { header('Location: '. isset($redirect_to[$access_level]) ? $redirect_to[$access_level] .'.php' : 'user.php'); } else { // login failed } Something like that
-
Damn, how did I even pass lmao Thanks guys =D
-
Second one outputs 1 =P
-
Passed the ZCE on Wednesday =D http://www.zend.com/en/yellow-pages#show-ClientCandidateID=ZEND021199