PHP - How To Validate A Specific Hyperlink From Different Links Using Php
can you please tell me how to validate a specific hyperlink from different hyperlinks. eg
i want to fetch these links separately starting with the bolded address from a website using simple html dom 1 http://www.website1.com/1/2/ 2 http://news.website2.com/s/d 3 http://website3.com/news/gds i know we can do it using preg_match ;but i am getting a hardtime understanding preg_match. can anyone give me a preg_match script for these websites validation.. and also if possible please explain.. Similar TutorialsI want to make the form so only people with a specific email address can sign up to the site. So for example their ending email address was.... @something.apple.biz.com .. but to be accepted into the site, the email HAS to end with apple.biz.com. How could you validate it so it matches something specific like this. Here is my code at the moment which just checks that their is at least one . after the @ for it to be an acceptable email. If anyone could say what else to add to do this would be great if($email != '' && $register){ $emailcheck = explode("@", $email); $sql = "SELECT email FROM member WHERE email='$email'"; $query = mysql_query($sql); $emails = mysql_num_rows($query); if($emails != 0 ){ $alert .= '<p class="alert" style="clear:both;">That email address has already been registered</p>'; $register = false; }elseif(count($emailcheck) != 2){ $alert .= '<p class="alert" style="clear:both;">Please enter a valid email address</p>'; $register = false; }elseif(count($emailcheck) == 2){ $emailchecktwo = explode(".", $emailcheck[1]); if(count($emailchecktwo) < 2){ $alert .= '<p class="alert" style="clear:both;">Please enter a valid email address</p>'; $register = false; } } } Hi Everyone..
I am not sure if I should post this question here. I would like to fix this problem using PHP rather than HTML. I am new to PHP. This code is part of an old PHP gallery file. I am trying to validate my site but the site's links have some characters that makes the link throw errors in W3C Validator. So I tried to replace the characters with HTML characters for example ? are now replaced by ?
so my original link before using valid HTML characters looked like
www.awebsite.com/viewgallery.php?cname=Colorado-Fall&pcaption=Lost-In-The-artAnd now it looks like this ... www.awebsite.com/viewgallery.php?cname=Colorado-Fall&pcaption=Lost-In-The-artBut now W3C Validator shows an error like this Line 32, Column 240: an attribute value must be a literal unless it contains only name characters …n class='next'><a href=viewgallery.php?cname=Colorado-Journeys&pca…✉ You have used a character that is not considered a "name character" in an attribute value. Which characters are considered "name characters" varies between the different document types, but a good rule of thumb is that unless the value contains only lower or upper case letters in the range a-z you must put quotation marks around the value. In fact, unless you have extreme file size requirements it is a very very good idea to always put quote marks around your attribute values. It is never wrong to do so, and very often it is absolutely necessary. I have two table in my database combined by using UNION, when it come to searching via search form, all data are retrieved as expected, but the problem come when i click the link that has the data from second table it redirecting to the page with first table details. Assume i have retrieved data using while loop and the UNION. while($search = $query->fetch()) {?> <div> <a href="pageone.php?po=<?php echo $search['pr_id'];?>">Read More...</a> </div> <?php }?> //the result become <a href="pageone.php?po=1">Read More...</a> <a href="pageone.php?pt=3">Read More...</a> //But what if data come from both first and second table in a database, i want the link become to be as <a href="pageone.php?po=1">Read More...</a> <a href="pagetwo.php?pt=3">Read More...</a> // any idea please
Hi, fairly new to PHP over the last couple weeks. Been having a problem with certain queries. I have a database with football results, games, teams etc. I can filter these using drop down and that's all well and good. The problem I'm having is displaying the data via gameweek. I've been asked to display the table like so - Gameweek1 will display week1 teams, results etc. Gameweek2 will display week2... and so on.
I can manage to do this in a drop down. But I've been asked to display this using links like "Previous, 1, 2, 3 Next". I've tried pagination but I couldn't figure it out. Can anyone point me in the right direction? If I need a GET() method, how would I go about coding that so it will be used in a link(s)? Been searching and searching to find an answer but to no avail...
//Database connection etc... $gameweek = "SELECT * FROM games WHERE gameweek= 1"; //if(isset($_GET['gameweek'])) //{ // $gameweek = $_GET['gameweek']; // //} //.... $result=mysqli_query($connection, "select * from games WHERE gameweek= 1"); //Print table and table headings... mysqli_close($connection); ?> <a href="http://weeks.php?gameweek=2">Week 2</a> <a href="http://weeks.phpgameweek=3">Week 3</a> </body> </html> I use the Wholesale Suite Premium Prices plugin with WooCommerce. I have 6 specific wholesale roles out of 15 that I wish to hide two specific shipping methods from being selected for the 6 exceptions. I'm just trying this on my staging server at this time using a code snippet example that I found and modified for my specific conditions. Would the following work for this purpose? /* Hide specific shipping methods for specific wholesale roles */ add_filter( 'woocommerce_package_rates', function( $shipping_rates ) { // User role and shipping method ID to hide for the user role $role_shipping_method_arr = array( 'ws_silvia_silver' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_silver' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_silver_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Premium Standard Shipping (Tracking Service)'), 'ws_silvia_gold' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_pst_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), 'ws_silvia_gold_tax_exempt' => array( 'Silvia Union Standard Shipping (Tracking Service)'), ); // Getting the current user role $curr_user = wp_get_current_user(); $curr_user_data = get_userdata($current_user->ID); // Wholesale Suite Roles if (isset($current_user) && class_exists('WWP_Wholesale_Roles')) { $wwp_wholesale_roles = WWP_Wholesale_Roles::getInstance(); $wwp_wholesale_role = $wwp_wholesale_roles->getUserWholesaleRole(); // Loop through the user role and shipping method pair foreach( $role_shipping_method_arr as $role => $shipping_methods_to_hide ) { // Check if defined role exist in current user role or not if( in_array( $role, $current_user->roles) ) { // Loop through all the shipping rates foreach( $shipping_rates as $shipping_method_key => $shipping_method ) { $shipping_id = $shipping_method->get_id(); // Unset the shipping method if found if( in_array( $shipping_id, $shipping_methods_to_hide) ) { unset($shipping_rates[$shipping_method_key]); } } } } } return $shipping_rates; }); Any insights as to how to accomplish this would be greatly appreciated. Lyse <html> <?php $id = $_GET['id']; $dbusername="web148-matt"; $dbpassword="matt"; $dbdatabase="web148-matt"; mysql_connect(localhost,$dbusername,$dbpassword); @mysql_select_db($dbdatabase) or die( "Unable to select database"); mysql_query("UPDATE count SET clicks=clicks+1 WHERE id='$id'"); $sql = mysql_query("SELECT link FROM count WHERE id='$id'"); $fetch = mysql_fetch_row($sql); $result = mysql_query("SELECT * FROM count"); while($row = mysql_fetch_array($result)) { echo "<a href=" .$row['link']. ">Link</a>"; } ?> <a href='http://www.google.com'>Google</a> <a href='/index.php?id=2'>link2</a> </html> Hey guys Just a quick question: How to embed hyperlink into a database cell? Basically I echo out a table on the user interface of my site and there's an URL in one of the cells I want the user to access it by clicking on it, without copying and pasting the URL into the URL bar of the browser I tried updating the cell in phpmyadmin using <a href = http://www.example.com>http://www.example.com</a> but didn't work out, the resulting cell only had the text format Any help would be appreciated Thanks. I am using xampp. <a href="/">Home Page</a>The above code (when clicked in browser) takes me to the localhost instead of localhost/website How can i clear this issue? Hello Everyone. Im new here, but hopefully you can help me I have designed a CMS using PHP and MySQL. Its fairly basic, I'll talk you thorugh the stages: 1.) The user inputs their product information into a form and the script uploads it to the database giving it a unique ID. 2.) The user is then asked to upload a big image for that product, the image is added to a folder on the server. 3.) Now the user must choose a thumbnail and it uploads in the same manner. My problem is linking the two together... So far I have this: <?php $images = "products/"; $big = "big/"; $cols = 2; if ($handle = opendir($images)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && $file != rtrim($big,"/")) { $files[] = $file; } } closedir($handle); } $colCtr = 0; echo '<table width="212" cellpadding="2"><tr>'; foreach($files as $file) { if($colCtr %$cols == 0) echo '</tr><tr><td colspan="2"></td></tr><tr>'; echo '<td wdith=50% align="center"><a href="' . $images . $big . $file . '"><img border="0" class="gradualfader" src="' . $images . $file . '" /></a></td>'; $colCtr++; } echo '</table>' . "\r\n"; ?> This displays a lovely list of thumbnails, which when clicked opens the larger image. What i would like to do is insert a "ID" for each image so the product data can be grabbed from the database ? I think i've explained this well enough? reply if not and illl try and add more detail. To see it in action you can go to http://design.surreylabs.co.uk/parliament/2/products.php Thanks in Advance! I have searched this forum and haven't found a solution to my question. please don't flame... I am trying to send a table field from one page to another. the field i'm sending is id. I have managed to populate the field updateplayer.php?id=***** now i have a syntax error trying to get the field to show up on the update player form. Parse error: syntax error, unexpected T_VARIABLE in /home/netman13/public_html/bccsl.org/managers/updateplayer.php on line 7 The id field is supposed to get the id variable from the previous page ?id=***** Here is the update player code: Code: [Select] <?php include 'dbc.php'; $qP = "SELECT * FROM players WHERE id = '$_GET['$id']' "; $rsP = mysql_query($qP); $row = mysql_fetch_array($rsP); extract($row); $id = trim($id); $first = trim($first); $last = trim($last); $address = trim($address); $city = trim($city); $postal = trim($postal); $phone = trim($phone); $feet = trim($feet); $inches = trim($inches); $weight = trim($weight); $birth = trim($birth); $status = trim($status); $number = trim($number); mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Update Player</title> <link href="styles.css" rel="stylesheet" type="text/css"> <script language="JavaScript" type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script language="JavaScript" type="text/javascript" src="js/jquery.validate.js"></script> <script> $(document).ready(function(){ $.validator.addMethod("username", function(value, element) { return this.optional(element) || /^[a-z0-9\_]+$/i.test(value); }, "Username must contain only letters, numbers, or underscore."); $("#regForm").validate(); }); </script> </head> <body> <script language="JavaScript"> <!-- /*********************************************** * Required field(s) validation v1.10- By NavSurf * Visit Nav Surf at http://navsurf.com * Visit http://www.dynamicdrive.com/ for full source code ***********************************************/ function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("first", "last", "address", "city", "postal", "phone", "hft", "hinch", "weight", "birthdate", "status"); // Enter field description to appear in the dialog box var fieldDescription = Array("First Name", "Last Name", "Address", "City", "Postal Code", "Phone Number", "Feet", "Inches", "Weight", "Birthdate YYYY/MM/DD", "Player Status"); // dialog message var alertMsg = "Please complete the following fields:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> <table width="100%" border="0" cellpadding="5" cellspacing="0"class="main" > <tr> <td colspan="1"><p></p></td> </tr> <tr> <td width="17%"><? //Call Menu include 'menu.php'; ?></td> <td width="3%"> </td> <td width="80%"><p align="center">Update Player Information</p> <p align="center"><? if (isset($_GET['msg'])) { echo "<div class=\"msg\">$_GET[msg]</div>"; } ?></p> <p align="center"> </p> <form action="playerupdate.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return formCheck(this);"> <table width="653" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="148" height="29">First Name</td> <td width="153"><label> <input name="first" type="text" disabled="disabled" class="required" id="first" value="<?=$first ?>" /> </label></td> <td width="91" height="30">Last Name</td> <td width="261"><label> <input name="last" type="text" class="required" id="last" value="<?=$last ?>" readonly="readonly" /> </label></td> </tr> <tr> <td height="30">Address</td> <td><input name="address" type="text" class="required" id="address" value="<?=$address ?>" /></td> <td>City</td> <td><label> <input name="city" type="text" class="required" id="city" value="<?=$city ?>" /> </label></td> </tr> <tr> <td height="28">Postal Code</td> <td><label> <input name="postal" type="text" class="required" id="postal" value="<?=$postal ?>" size="12" /> </label></td> <td>Phone Number</td> <td><label> <input name="phone" type="text" class="required" id="phone" value="<?=$phone ?>" size="13" /> </label></td> </tr> <tr> <td height="29">Height <strong>(ft / in)</strong></td> <td><label> <input name="feet" type="text" class="required" id="feet" value="<?=$feet ?>" size="3" /> / <input name="inches" type="text" class="required" id="inches" value="<?=$inches ?>" size="3" /> </label></td> <td>Weight (lbs)</td> <td><input name="weight" type="text" class="required" id="weight" value="<?=$weight ?>" size="5" /></td> </tr> <tr> <td height="35">Birthdate <strong>(yyyy/mm/dd)</strong></td> <td><label> <input name="birth" type="text" class="required" id="birth" value="<?=$birth ?>" size="13" readonly="readonly" /> </label></td> <td><label>Player Type:</label></td> <td><p> <label> <input name="status" type="radio" id="type_0" value="1" checked="checked" /> Church</label> <br /> <label> <input type="radio" name="status" value="2" id="type_1" /> Import</label> <br /> <label> <input type="radio" name="status" value="3" id="type_2" /> Witness</label> <br /> </p> <label></label></td> </tr> <tr> <td height="35">Player ID:</td> <td><input name="id" type="text" id="id" value="<?=$id ?>" readonly="readonly" /></td> <td>Player Number:</td> <td><input name="number" type="text" class="required" id="number" value="<?=$number ?>" size="5" /></td> </tr> <tr> <td height="29"> </td> <td><label></label></td> <td><p> <input name="teamid" type="hidden" id="teamid" value="<? echo $_SESSION['teamid'];?>" /> <input name="division" type="hidden" id="division" value="<? echo $_SESSION['divisionid'];?>" /> <input type="hidden" name="currentdate" size=11 > </p> <p> <input name="teamname" type="hidden" id="teamname" value="<? echo $_SESSION['team_name'];?>" /> </p> <p> <script> /*Current date in form credit: JavaScript Kit (www.javascriptkit.com) Over 200+ free scripts here! */ var mydate=new Date() var theyear=mydate.getYear() if (theyear < 1000) theyear+=1900 var theday=mydate.getDay() var themonth=mydate.getMonth()+1 if (themonth<10) themonth="0"+themonth var theday=mydate.getDate() if (theday<10) theday="0"+theday //////EDIT below three variable to customize the format of the date///// var displayfirst=theyear var displaysecond=themonth var displaythird=theday //////////////////////////////////// document.form.currentdate.value=displayfirst+"/"+displaysecond+"/"+displaythird </script> <input name="approved" type="hidden" id="approved" value="0" /> </p></td> <td> </td> </tr> </table> <p align="center"> <label> <input type="submit" name="submit2" id="submit2" value="Submit" /> </label> <label> <input type="reset" name="reset2" id="reset2" value="Clear" /> </label> </p> </form> <p align="center"> </p> <p align="center"> <label></label> </p></td> </tr> <tr> <td colspan="3"> </td> </tr> </table> <p> </p> </body> </html> Thanks for your help. This forum has been an awesome resource for me. I am having problems with a line of code. This is what I have so far. I am missing a "," according to my error message. Im trading in deep water with this line of code. I am trying to use the data from my echo state to be a hyperlink... If that makes sense. Code: [Select] echo "\t" . '<td><a href="' . APP_ROOT . 'onlinebanking/viewtransactions.php">. $account['BankAccountID'] . </a>' '</td>' . "\n"; Hello im wondering how i can make a hyperlinks adress be a set after a variable. this is my php: $result1 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1;"); $result2 = mysql_query("SELECT id, namn, url FROM stuff ORDER BY id desc limit 1,1;"); <html> <a href="???"> <p class="note-general"> The first link </p> <a href="???"> <p class="note-general"> The the second link </p> </html> The important thing is that the url from $result1 will link under "the first link" and url from $result2 link under "the second link". Hi there, im trying to echo a hyperlink and parse a url parameter. Its not quite working as iam getting T-string error. If someone with fresh eyes could quickly glance for me that would be ace. Code: [Select] <?php if ($row_ship['PlayerName'] == '$_SESSION['MM_Username']'){ echo '<a href="ship_edit.php?recordID='.$row_Ship['ShipID'].'">Edit</a>';} ?> Thank You Where should I validate the return value?
In the function should I validate the value before returning it.
Or once the value has been returned, should I check it?
Is it really necessary to validate the return value?
Thank you.
How do I make email, name and phone required fields? thanks in advance <?php $email = $_POST['email']; $name = trim($_POST['name']); $phone = trim($_POST['phone']); $time = trim($_POST['time']); $zipcode = trim($_POST['zipcode']); $date = trim($_POST['date']); $EmailTo = "myemail@somedomain.com"; $Subject = "form"; /// Add a subject $Body = ""; $Body .= "Full name:\n$name\n\n"; $Body .= "Primary phone:\n$phone\n\n"; $Body .= "time:\n$time\n\n"; $Body .= "Zip code:\n$zipcode\n\n"; $Body .= "date:\n$date\n\n"; if($Subject == NULL) {$Subject = "From $EmailFrom";} $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); if ($success){ header ('Location: confirm.html');} else{ echo "Error! Your e-mail was not sent!";} ?> Hey everyone, im building my first newsletter sign up and wanted to add the validation of checking if the email is already in the database. This is the top part of the code that works. <?php switch ($_REQUEST['action']) { default: foreach($_POST as $key=>$value){ $$key = $value; } if ($email == ''){ $error_msg = 'email required'; } elseif (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $error_msg = 'Invalid email address'; } echo ""; if ($error_msg == ''){ foreach($_POST as $key=>$value){ $$key = htmlentities(stripslashes($value)); } $Q = mysql_query("INSERT INTO newsletter (`email`) VALUES ('$email')"); But when i add my attempted validation it doesn't work. $check = mysql_query("SELECT FROM newsletter WHERE email = '$email'") or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 != 1) { $error_msg = 'email exists'; Could someone be so kind to add this code where it should go, iv tried everything. Hello
I have a PHP page that sends text entered by a user to our database which we use to display news. This system supports various languages but occasionally we get issues with odd characters being entered...
For example, the premade glyph for ellipsis which is normally represented by 3 .'s broke our system today
How can I check that each character is valid and within range?
These are our character ranges
ExtendedLatin_c_iLowerAlphaChar = 0x00C0;
ExtendedLatin_c_iUpperAlphaChar = 0x01FF;
Arabic_c_iLowerChar = 0x600;
Arabic_c_iUpperChar = 0x6FF;
Arabic_c_iLowerAlphaChar = 0x621;
Arabic_c_iUpperAlphaChar = 0x64A;
Arabic_c_iLowerNumericChar = 0x660;
Arabic_c_iUpperNumericChar = 0x669;
So each character must fall within one of these ranges... but I have no idea how to get the hex value of a character in PHP
Thanks
I am working on a script for a simple form with only 2 options that are dropdowns. I need to validate these two options that there is a selection made. I have gotten the first one to validate, but I cannot get the second one to validate. Can anyone steer me in the right direciton why only one is working? I get no errors in the script, so I assume I am just missing something. Code: [Select] <?php // options for drop-down menu $choices = array('-- Choose Your Item','Anniversary Jacket', 'Anniversary T-Shirt'); $sizes = array('-- Choose Your Size','L', 'XL'); if($_SERVER['REQUEST_METHOD'] == 'GET'){ // display form when GET showForm(array()); } else{ // process form if POST $errors = validateForm(); if(count($errors)) showForm($errors); // if errors show again else print 'Form submitted succesfully!'; // no errors } // function generating form function showForm($errors){ global $choices,$sizes; // set defaults $defaults = array(); foreach($choices as $key => $choice){ if(isset($_POST['item']) && ($_POST['item'] == $key)) $defaults['item'][$key] = 'selected'; else $defaults['item'][$choice] = ''; } foreach($sizes as $key => $size){ if(isset($_POST['size']) && ($_POST['size'] == $key)) $defaults['size'][$key] = 'selected'; else $defaults['size'][$size] = ''; } // print form print "<form action='{$_SERVER['SCRIPT_NAME']}' method='post'>"; print "<div>"; print "<select name='item'>"; foreach($choices as $key => $choice){ print "<option value='{$key}' {$defaults['item'][$key]}>{$choice}</option>"; } print "</select>"; showError('item', $errors); print "</div>"; print "<div>"; print "<select name='size'>"; foreach($sizes as $key => $size){ print "<option value='{$key}' {$defaults['size'][$key]}>{$size}</option>"; } print "</select>"; showError('size', $errors); print "</div>"; print "<input type='submit'/>"; print "</form>"; } // display error function showError($type, $errors){ if(isset($errors[$type])) print "<b>{$errors[$type]}</b>"; } // validate data function validateForm(){ global $choices,$sizes; // start validation and store errors $error = array(); // validate drop-down if(!(isset($_POST['item']) && (array_key_exists($_POST['item'], $choices)) && $_POST['item'] != 0)) $errors['item'] = 'Select Item'; return $errors; // validate drop-down if(!(isset($_POST['size']) && (array_key_exists($_POST['size'], $choices)) && $_POST['size'] != 0)) $errors['size'] = 'Select Size'; return $errors; } ?> I do not know whats going on. I have tried two different methods of validating and email and it keeps saying invalid email I have even tried to debug it by putting errors and nothing i have tried preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $e) and fliter_var($e, FLITER_VALIDATE_EMAIL); the email i am trying to debug is a valid one. its one I use daily. I have tried different emails and still no luck.... someone help me please! |