PHP - Multi-checker
Hello friends,
I've tried to search over the Internet but didn't found any tutorial how to do the following :- let say we have form with input username and input email just 2 field HTML Code Code: [Select] <form> <table> <tr> <td>Username :</td> <td><input id="username" size="20" type="text" name="username"></td> </tr> <tr> <td>Email :</td> <td><input id="email" size="20" type="text" name="email"></td> </tr> </table> </form> As you can see no submit button cause we will only check out if username and/or email is not stored already, by using ajax My problem : i can only check out for username (1 field) but i can not check for 2 fields or more and i want to know how to apply it for 2 fields (username and email) Here is my idea for only one field (username) I'll add in the HTML code this Code: [Select] <td><div id="status"></div></td> and will add this java code Code: [Select] <SCRIPT type="text/javascript"> pic1 = new Image(16, 16); pic1.src = "loader.gif"; $(document).ready(function(){ $("#username").change(function() { var usr = $("#username").val(); if(usr.length >= 4) { $("#status").html('<img src="loader.gif" align="absmiddle"> Checking availability...'); $.ajax({ type: "POST", url: "check.php", data: "username="+ usr, success: function(msg){ $("#status").ajaxComplete(function(event, request, settings){ if(msg == 'OK') { $("#username").removeClass('object_error'); $("#username").addClass("object_ok"); $(this).html(' <img src="tick.gif" align="absmiddle">'); } else { $("#username").removeClass('object_ok'); $("#username").addClass("object_error"); $(this).html(msg); } }); } }); } else { $("#status").html('<font color="red">The username should have at least <strong>4</strong> characters.</font>'); $("#username").removeClass('object_ok'); $("#username").addClass("object_error"); } }); }); </SCRIPT> Explain : it will get the input of username and will send it to check.php Now check.php code (should have all usernames that will compare with it) Code: [Select] <?php if(isSet($_POST['username'])) { $usernames = array('john','michael','terry', 'steve', 'donald'); $username = $_POST['username']; if(in_array($username, $usernames)) { echo '<font color="red">The username<STRONG>'.$username.'</STRONG> is already in use.</font>'; } else { echo 'OK'; } } ?> Now it is very clear , if will automatic check the username now my problem is how to apply it for also email Similar TutorialsAny body here who can help me to make a plagiarism checker in php? that can accurately get the site of the content that is copied from internet. thanks in advance. godbless.
Hi all, I have this script I used on a site hosted on my machine that checked if different servers and applications were running on my machine. Here's the code. Code: [Select] <html> <body> <style> fd{ color: #000000 font-size:100% } </style> <?php function check_port($port) { $conn = @fsockopen("212.233.xxx.xxx", $port, $errno, $errstr, 0.2); if ($conn) { fclose($conn); return true; } } function server_report() { $report = array(); $svcs = array('21'=>'FTP', '22'=>'SSH', '25'=>'SMTP', '80'=>'HTTP', '110'=>'POP3', '143'=>'IMAP', '3306'=>'MySQL', '8080'=>'HFS', '8081'=>'Webcam', '3784'=>'Ventrilo'); foreach ($svcs as $port=>$service) { $report[$service] = check_port($port); } return $report; } $report = server_report(); ?> <center> <table> <tr> <td><font face="Verdana" size="1" color="#000000">Apache:</td> <td><font face="Verdana" size="1" color="#000000"> <?php echo $report['HTTP'] ? "<img src='main/images/on.png' width='16' height='15' border='0'>" : "<img src='main/images/off.png' width='16' height='15' border='0'>"; ?></font></td> </tr> <tr> <td><font face="Verdana" size="1" color="#000000">MySQL:</td> <td><font face="Verdana" size="1" color="#000000"> <?php echo $report['MySQL'] ? "<img src='main/images/on.png' width='16' height='15' border='0'>" : "<img src='main/images/off.png' width='16' height='15' border='0'>"; ?></font></td> </tr> <tr> <td><font face="Verdana" size="1" color="#000000">HFS:</td> <td><font face="Verdana" size="1" color="#000000"> <?php echo $report['HFS'] ? "<img src='main/images/on.png' width='16' height='15' border='0'>" : "<img src='main/images/off.png' width='16' height='15' border='0'>"; ?></font></td> </tr> <tr> <td><font face="Verdana" size="1" color="#000000">FTP:</font></td> <td><font face="Verdana" size="1" color="#000000"> <?php echo $report['FTP'] ? "<img src='main/images/on.png' width='16' height='15' border='0'>" : "<img src='main/images/off.png' width='16' height='15' border='0'>"; ?></font></td> </tr> <tr> <td><font face="Verdana" size="1" color="#000000">Webcam:</font></td> <td><font face="Verdana" size="1" color="#000000"> <?php echo $report['Webcam'] ? "<img src='main/images/on.png' width='16' height='15' border='0'>" : "<img src='main/images/off.png' width='16' height='15' border='0'>"; ?></font></td> </tr> <tr> <td><font face="Verdana" size="1" color="#000000">Ventrilo:</font></td> <td><font face="Verdana" size="1" color="#000000"> <?php echo $report['Ventrilo'] ? "<img src='main/images/on.png' width='16' height='15' border='0'>" : "<img src='main/images/off.png' width='16' height='15' border='0'>"; ?></font></td> </tr> </table> </center> </body> </html> I've added the HTML too. As you can see it checks if the ports are open. It worked perfectly and I didn't have any issues with it at all. Now, for a couple of days, I've been using an awardspace paid hosting, bought a domain name. I use wordpress now, and I pasted this code directly in a PHP/HTML code box (I use a plugin that enables use of PHP) and it shows the HTML formatting how it should be, but unfortunately doesn't work as intended. It shows everything to be down, while apache, mysql and my ftp server are still running on my computer (the IP it checks, 212.233.xxx.xxx). When I set the IP to be 127.0.0.1, the IP of the awardspace server as far as my script is concerned, it shows only that the IP is working. So, any suggestions? Any idea would be greatly appreciated I am trying to make a Server Status checker that uses a image to tell if it is online or not. I also am trying to make it so you can the URL as a image code(EX: http://Http://domain.com/statuscheck.php?ip=google.com&port=80). What I'm trying to say it, that if you do like <img src="http://Http://domain.com/statuscheck.php?ip=google.com&port=80"> it would go to my site, use the php script, and then have the image Online or Offline, were the <img> code was posted. Here's my code Im trying to make it from. <?php $ip="{$_GET['ip']}"; $port="{$_GET['port']}"; if(!$sock=@fsockopen($ip,"$port", $num, $error, 5)) { Header('Content-type: image/png'); echo"<img src='images/offline.png'>"; } else { Header('Content-type: image/png'); echo"<img src='images/online.png'>"; } ?> Hey guys, I have this little script, but it doesn't seem to work properly. <?php mysql_connect("localhost","root",""); mysql_select_db("chat"); $user = strip_tags(trim($_REQUEST['username'])); if(strlen($user) <= 0) { echo json_encode(array('code' => -1,'result' => 'Invalid username, please try again.')); die; } // Query database to check if the username is available $query = "Select * from users where username = '$user' "; $result = mysql_query($query); $avaliable = mysql_num_rows($result); // Execute the above query using your own script and if it return you the // result (row) we should return negative, else a success message. //$available = true; if($available) { echo json_encode(array('code' => 1,'result' => "Success,username $user is still available")); die; } else { echo json_encode(array('code' => 0,'result' => "Sorry but username $user is already taken.")); die; } die; ?> It keeps returning with 'Sorry but username iunsdbsyusaddssd763b373b is already taken'. Even when I type in some random gibberish like 'iunsdbsyusaddssd763b373b' Can anyone show me why it is doing that? Thanks alot friends. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=357042.0 Alright, I have created a hash password checker and here is my code: include("include.php"); // include the mySQL info! $users = mysql_query(" SELECT * FROM User "); // Select all from the users table in the database! while($row = mysql_fetch_array($users)) // While it fetches the users do the following... { if (hash("sha256", $password) == $row["Password"]) echo "Congratulations! The Hash matches the password entered into the database!"; } elseif (hash("sha256", $password) != $row["Password"]) { echo "Your Hash failed to match the password entered!"; } Now for some reason this displays a totally blank page. When I turn error display on I get the error "Unexpected T_ELSEIF" on this line elseif (hash("sha256", $password) != $row["Password"]) Any help is appreciated... Hello, I am trying to get this backlink checker to work i have it working so it checks that the link itself matches and is there but this is the harder part that I don't understand. I want to have it also check the nodeValue to make sure that it matches one of the nodeValue's from a mysql table this is the code I have to make it check the href link Code: [Select] function CheckForTargetUrl($links, $target) { foreach ($links as $link) { if (strpos($link, $target) !== false) { return true; } } return false; } function ExtractHrefLinks($html) { $dom = new DOMDocument; $linkUrls = array(); @$dom->loadHTML($html); $links = $dom->getElementsByTagName('a'); foreach ($links as $link){ $linkUrls[] = $link->getAttribute('href'); } return $linkUrls; } function backlink_check($contenturl){ $url = 'businessinvestingsource.com'; $source = $contenturl; $falseFound = false; $html = file_get_contents ( $source ); $links = ExtractHrefLinks($html); if (CheckForTargetUrl($links, $url) === false) { $falseFound = "true"; $reportArray[$source] = 0; } else { $falseFound = "false"; } return $falseFound; } Now this all works fine, I just need it to check the actual nodeValue (anchor text as well) meaning check this: <a href="http://google.com">Google</a> There is a mysql table called "allowed_anchors" with 2 rows "id" and "anchor" I need it to check if the nodeValue matches 1 of the allowed_anchors from the table. If anyone knows how I can do this that would be very great i have been trying to figure it out for hours with no luck. Thanks very much for any help to come. hello, is there a way to insert something 17 times into a database and change the 3rd field one at a time (from 1-17)? Code: [Select] $sql = "INSERT INTO picks VALUES ( NULL, '" . mysql_real_escape_string($userid) ."', '" . mysql_real_escape_string($weekid) ."', '" . mysql_real_escape_string($pickid) ."' )"; mysql_query($sql) or die('Error, Check you fields and try again.'); Hi guys I got an issue that when a link on the site is loading, the other links does not load until the previous is complete but it will work if i try on 2 different browsers. How can i browse multiple links silmultanously? Thanks common.php Code: [Select] <?php session_start(); header('Cache-control: private'); // IE 6 FIX if(isSet($_GET['lang'])) { $lang = $_GET['lang']; // register the session and set the cookie $_SESSION['lang'] = $lang; setcookie("lang", $lang, time() + (3600 * 24 * 30)); } else if(isSet($_SESSION['lang'])) { $lang = $_SESSION['lang']; } else if(isSet($_COOKIE['lang'])) { $lang = $_COOKIE['lang']; } else { $lang = 'en'; } switch ($lang) { case 'en': $lang_file = 'lang.en.php'; break; case 'de': $lang_file = 'lang.de.php'; break; case 'el': $lang_file = 'lang.el.php'; break; default: $lang_file = 'lang.en.php'; } include_once 'languages/'.$lang_file; ?> ip2locationlite.class.php Code: [Select] <?php final class ip2location_lite{ protected $errors = array(); protected $service = 'api.ipinfodb.com'; protected $version = 'v3'; protected $apiKey = ''; public function __construct(){} public function __destruct(){} public function setKey($key){ if(!empty($key)) $this->apiKey = $key; } public function getError(){ return implode("\n", $this->errors); } public function getCountry($host){ return $this->getResult($host, 'ip-country'); } public function getCity($host){ return $this->getResult($host, 'ip-city'); } private function getResult($host, $name){ $ip = @gethostbyname($host); if(preg_match('/^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:[.](?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/', $ip)){ $xml = @file_get_contents('http://' . $this->service . '/' . $this->version . '/' . $name . '/?key=' . $this->apiKey . '&ip=' . $ip . '&format=xml'); try{ $response = @new SimpleXMLElement($xml); foreach($response as $field=>$value){ $result[(string)$field] = (string)$value; } return $result; } catch(Exception $e){ $this->errors[] = $e->getMessage(); return; } } $this->errors[] = '"' . $host . '" is not a valid IP address or hostname.'; return; } } ?> index.php Code: [Select] <?php include_once('ip2locationlite.class.php'); //Set geolocation cookie if(!$_COOKIE["geolocation"]){ $ipLite = new ip2location_lite; $ipLite->setKey('*****************'); $visitorGeolocation = $ipLite->getCountry($_SERVER['REMOTE_ADDR']); if ($visitorGeolocation['statusCode'] == 'OK') { $data = base64_encode(serialize($visitorGeolocation)); setcookie("geolocation", $data, time()+3600*24*7); //set cookie for 1 week } }else{ $visitorGeolocation = unserialize(base64_decode($_COOKIE["geolocation"])); } var_dump($visitorGeolocation); ?> im using this http://ipinfodb.com/ in index.php i got this message array(5) { ["statusCode"]=> string(2) "OK" ["statusMessage"]=> string(0) "" ["ipAddress"]=> string(13) "94.68.211.211" ["countryCode"]=> string(2) "GR" ["countryName"]=> string(6) "GREECE" } how to switch automatic if GR go to index.php?lang=el if DE go to index.php?lang=de etc... Hi Chaps, I'm trying to put together a Nested Set Model (Hierarchical Data), but I have having problems when it comes to deleting/updating the 'nested' table. I'm using this as a guide: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html But when trying to run a query, such as: SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1 FROM nested_category WHERE name = 'GAME CONSOLES'; DELETE FROM nested_category WHERE lft BETWEEN @myLeft AND @myRight; UPDATE nested_category SET rgt = rgt - @myWidth WHERE rgt > @myRight; UPDATE nested_category SET lft = lft - @myWidth WHERE lft > @myRight; I get a MySQL syntax error. This code works fine in something such as Windows Command Prompt, but not in PHP. Is there a special way to run multiple queries in 1 PHP script? Many thanks hello all, i have been sitting here googleing and googling but i can't seem to find what im looking for. i am tring to create a personal site that lets me note services i do for my cars. I have multiple tables (cars, color, mfg, ...) in the main table cars i insted of putting the color black i put and int(11) of 1 which is suppose to "if statement" to the table colors and produce the correct color. same for mfg. although nothing i have tried has helped i always just have the else of the if echoed out. i have heard of union and join left right i am so unsure of what is need any insite would be useful. thanks in advance. How i can delete record from table `order` and move it to `order2`
the table `order2` structure is exactly like table `order`.here is the code that i made.
<? include("connection.php"); $id_product=$_GET["pid"]; $sql_delete="DELETE FROM `order` WHERE id_product='$id_product'"; $result=mysql_query($sql_delete) or die("Error in sql due to ".mysql_error()); if ($result) header("Location: order_list.php"); ?> hi , i want to make 5 forms with 1 submit button , how i do that? thanks , Mor. Hello friends, how can i combain this codes If i've 3 functions $limited,$refere,$pass all have commen result echo "good"; if($limited){ if($hits >= $limited){ echo "U1"; }else{ echo "Good"; } } else { echo "Good"; } ================================= if($refere){ if($me >= $you){ echo "U2"; }else{ echo "Good"; } } else { echo "Good"; } ================================= if($pass){ if($she >= $he){ echo "U3"; }else{ echo "Good"; } } else { echo "Good"; } thansk, it would really helps me alot I am having a hell of a time getting this to work. I need the keys in an array to be specific, not a sequential number or a row in my database. I need to add to the array through each loop of my while() statement. This code does it, but does not use the keys I specify, after the first entry, it starts assigning numbers to keys. Any guidance would be great. <?php require_once ('includes/config.php'); require_once ('includes/connect.php'); $echoarray = array(); $resultsql = mysql_query("SELECT * FROM clients")or die(mysql_error()); while($row = mysql_fetch_array($resultsql)){ if(empty($echoarray)){ $echoarray = array( 'id' => $row['ID'], 'name' => $row['First_Name'] . " " . $row['Last_Name'], 'price' => $row['Status'], 'number' => $row['Sex'], 'address' => $row['Phys_Street'], 'company' => $row['Agency'], 'desc' => $row['Notes'], 'age' => $row['Date_Birth'], 'title' => $row['Occupation'], 'phone' => $row['Phone'], 'email' => $row['Email'], 'zip' => $row['Phys_Zip'], 'country' => $row['Phys_City'] ); } else { array_push($echoarray, $echoarray['id'] = $row['ID'], $echoarray['name'] = $row['First_Name'] . " " . $row['Last_Name'], $echoarray['price'] = $row['Status'], $echoarray['number'] = $row['Sex'], $echoarray['address'] = $row['Phys_Street'], $echoarray['company'] = $row['Agency'], $echoarray['desc'] = $row['Notes'], $echoarray['age'] = $row['Date_Birth'], $echoarray['title'] = $row['Occupation'], $echoarray['phone'] = $row['Phone'], $echoarray['email'] = $row['Email'], $echoarray['zip'] = $row['Phys_Zip'], $echoarray['country'] = $row['Phys_City'] ); } Any Ideas? Okay, I currently have a query that is like: Code: [Select] $sql = "SELECT SQL_CALC_FOUND_ROWS a.ItemID, a.spec, a.description, a.sport, a.category, a.price, a.unit_qty, a.is_visible, a.AdminID, b.name, b.ItemID as catID, c.Name as nameSport, c.ItemID as sportID FROM purchase_request_category_item as a LEFT JOIN purchase_request_category as b ON b.itemID = a.category LEFT JOIN ro_school_sports as c ON c.ItemID = a.sport WHERE a.AdminID = '".$dist."' GROUP BY a.ItemID, b.name, c.Name ORDER BY a.ItemID DESC LIMIT ". $start.",".$limit; I am building a custom search function which I intend to be able to change the WHERE line to: WHERE a.AdminID = '".$dist."' ".$query $query will be created via if statements for every element in the form which will be called either by the button on the form, or the links in my pagination. The form would have the following: Level(s): dynamic field, Multi Select Status: Both/Enabled/Disabled single select Sports: dynamic field, Multi Select Category: dynamic field, single select. the sport column is a single selected item on the add page, its of type int(11) the levels table, is also a multi select on the add item page, and is of the type set('1','2','3','4','5','12','13') So real question is I guess, how on earth do I work with these 2 multi selects to create this search? Basically what I want to do is create an array of inheritance. so here is the levels Owner->Admin->moderator->User->guest owner has all the abilities of admin, moderator, user and guest.. So I want to be able to sort through them and end with an array like this Code: [Select] $array['Owner'] = array('Admin', 'Moderator', 'User', 'Guest'); Currently my code works sort of. Basically Admin is only set to inherit Moderator. Moderator only inherits User. So this code works but only to 2 levels. I don't want to add a billion foeachs within each other for each level(currently 4) but I might add more roils so then I would have to add more foreachs. There must be a magic way to do this. Any feedback is appreciated! Code: [Select] <?PHP $sql = 'SELECT * FROM '.self::$Config['PERMISSIONS']['Database'].'.permissions_inheritance'; $result = DB::Query($sql); while($row = DB::fetch($result)){ if($row['type'] == '0'){ $group_i[$row['child']][] = $row['parent']; }elseif($row['type'] == '1'){ $user_i[$row['child']][] = $row['parent']; } } //echo count($group_i); print_r($group_i); $groups = array(); foreach($group_i as $Key=>$Value){ foreach($Value as $K=>$V){ $new_array[$Key][] = $V; if(isset($group_i[$V]) && is_array($group_i[$V])){ foreach($group_i[$V] as $Q=>$A){ if(is_array($A)){ foreach($A as $C=>$X){ $new_array[$Key][] = $X; } }else{ $new_array[$Key][] = $A; } } } } } Let me know if you have any questions! I hope you enjoy the challenge lolol Hi I have to multi select tables, the table on the left is field with the contents of an array, I then have it so the user can make there selections from the left box and move them into the right. They then hit submit and it gets stored inmysql table as an array. The problem I am having is keeping the selections in that right box after any sort of page refresh. Any ideas I have pasted the php and html code below, the add/remove function is controlled by javascript, I won't bother pasting that as i don't think it has anything to do with it. PHP ******** Code: [Select] <?php / ------- PARSING PERSONAL TRAINER DETAILS VENUE --------- if ($_POST['parse_var'] == "fromPool"){ $venue = $_POST['venue']; if (is_array($_POST['venue'])) { $venue = explode("\n", $_POST['venue']); } else { $venue = $_POST['venue']; } // Update the database data now here for all fields posted in the form $sqlUpdate = mysql_query("UPDATE ptdata SET venue='$venue' WHERE id='$id' LIMIT 1"); if ($sqlUpdate){ $success_msg = '<img src="images/Form/round_success.png" width="20" height="20" alt="Success" />Your venue information has been updated successfully'; } else { $error_msg = '<img src="images/Form/round_error.png" width="20" height="20" alt="Failure" /> ERROR: Problems arose during the information exchange, please try again later</font>'; } } // ------- END PARSING PERSONAL TRAINER DETAILS VENUE --------- ?> <?php ////////// Venue Array PHP For Multi Selection Boxes //////////// $dbString = ''; // To be pulled from Database $toPool = explode(',', $dbString); $pool = Array('Your Home','My Home','Outside','Private Studio','Your Work','Gym'); if($_SERVER['REQUEST_METHOD'] == 'POST'){ $toPool = (count($_POST['venue']) > 0)? $_POST['venue'] : Array(); $newDbString = implode(',', $toPool); // Store in Database; } $fromPool = array_diff($pool, $toPool); ?> html *********** <form action="ptmemberaccount.php" method="post" enctype="multipart/form-data"onsubmit="multipleSelectOnSubmit()"> <table width="500" align="left"> <tr> <td width="500" height="300" align="center"> <select multiple="multiple" name="fromBox[]" id="fromBox"> <?php foreach($fromPool as $itm){ echo "\t" . '<option value="' . $itm . '">' . $itm . '</option>' . PHP_EOL; } ?> </select> <select multiple="multiple" name="venue[]" id="toBox"> <?php foreach($toPool as $itm){ echo "\t" . '<option value="' . $itm . '">' . $itm . '</option>' . PHP_EOL; } ?> </select> </td> </tr> <tr> <td align="center" height="35"><script type="text/javascript"> createMovableOptions("fromBox","toBox",400,200,'Training Venues','Selected Training Venues'); </script> <p>Use the buttons to Add/Remove selections</p></td></td> </tr> <tr> <td align="center" height="100"> <input type="submit" value="OK"> </tr> </table> </form> If you need anymore info let me know, also if anyone knows a better way of achieving this i am open to suggestions. Many Thanks MOD EDIT: code tags added l have a video site, and each title is generated dynamically on a <li>. The problem is some titles are longer than others and spill on to the next <li> throwing my site all off. What i need to do is designate 2 lines for the titles just in case the title is too long. Code: [Select] <ul> <li><?php echo $title; ?></li> <li>///continue $title or add blank line so it doesn't throw everything off</li> </ul> |