PHP - Wildcard Syntax
I would like some advice from someone who already has the quick answer. User uses a form (drop down) to define a variable in their search of the db. PHP/MYSQL
Choices are ALL, A, B, C. EXAMPLE1 They choose B. $variable = 'B' SELECT .... WHERE.... x table value = $variable (equals B) All works perfectly. EXAMPLE2 Now if they chose ALL (or don't chose), I have a problem. They choose nothing (which should be ALL records). I need it to go back to having no WHERE portion of the sql command, or a WHERE that pulls all records. They choose nothing. $ variable = 'ALL' SELECT ... WHERE... x table value = $variable (which now equals ALL) I thought % was a wildcard but doesn't work. This seems simple... but eludes me. What should I use for a variable value if there is NO selection or ALL selection???? The WHERE x table value = has to equal SOMETHING, right? Should I be using an IF THEN to zap the line if it equals "all"? Any advice would be helpful! Thanks! Similar Tutorials<?php $title="juni/ngats.co.nr/hehe"; if ($title==([^/\.]+)/ngats.([^/\.]+).nr/([^/\.]+)) { echo it works; } whats wrong here? is it the wildcard? what do i need to do? it says it has errors with [... and then if i remove [] it will point out an error on ^ Hello, I am using this PHP script which needs to open several different files with similar names and extensions. This means: fopen(file_1.txt); However, I have about 300 of those files which I need to open and I don't want to rename them one by one. PERL had this awesome feature where you could create a variable with an asterix (wildcard) which would then find anything matching, using a wildcard. Something like: fopen(file_*.txt); ^Would open all files which had file_SOMETHING.txt in them. So is there anything like this in PHP? thanks in advance! Hello guys i have been trying to find an alternative file function to read multiple files into an array. My aim is to preg_replace every file in directory starting with Audit_Report with the font colours...i have been googling it for like 2 hours and the closest answer i can get to is using the glob() function but it doesn't work for me still. I would like you guys to give me suggestions if you can..thanks!! <?php $file = "Audit_Report.(SEAN).(192.168.199.129).txt"; $lines = file($file); foreach ($lines as $line) { $string = $line; $patterns = array(); $patterns[0] = '/\bPass\b/'; $patterns[1] = '/\bFail\b/'; $patterns[2]='/\b============ Major Audit and Account Policies============ \b/'; $replacements = array(); $replacements[1] = "<font color=red>Fail</font>"; $replacements[0] = "<font color=green>Pass</font>"; $replacements[2] = "<br><b>==== Major Audit and Account Policies====</b>"; ksort($patterns); ksort($replacements); $a = preg_replace($patterns, $replacements, $string); echo "$a<br />\n"; file_put_contents(basename($file, substr($file, strpos($file, '.'))) . ".html","$a<br />\n", FILE_APPEND) or die("Cannot write file"); } ?> My service allows users to generate subdomains based off their username(testguy.mydomain.com). I've created a wildcard subdomain for this, so the dynamic subdomains work wonderfully.
I've added a parked domain where my domain is supposed to mirror the given subdomain. However, when I go to the domain.com, it redirects to the subdomain, changing the URL in the address bar. Any ideas?
Or if there a better way to mirror a subdomain while showing the original domain in the address bar?
Edited by fitguydan, 12 June 2014 - 11:57 PM. I tried many ways but unable to pass sessions to virtual subdomains on my site.. I edited ihi.ini file and included Code: [Select] session.cookie_domain = .mydomain.com I like to add that session is active on my main domain for www.mydomain.com only.. So how do I pass sessions for WWW to other subdomains ? Thanks n Advance I have been looking at this code most of the morning and do not have a clue what is wrong with the code. I am hoping its not a stupid mistake, can someone please help me out? thank you
<title>Inputing Travel Detials</title> <header> <h1 align="center"> Adding Travel Detials </h1> <body> <p> <center><img src="cyberwarfareimage1.png" alt="Squadron logo" style="width:200px;height:200px" style="middle"></center> <table border="1"> <tr> <td><a href="index.php"> Home Page </a></td> <td><a href="administratorhomepage.html">Administrator Home Page </a></td> <td><a href="viewhomepage.html">View Home Page </a></td> <td><a href="Inputhomepage.html">Input Home Page </a></td> <td><a href="traveldetials.html">Enter More Travel Detials </a></td> </table> </p> <?php include "connection.php"; $Applicant_ID = $_POST["Applicant_ID"]; $Method_Of_Travel = $_POST["Method_Of_Travel"]; $Cost = $_POST["Cost"]; $ETA = $_POST["ETA"]; $Main_Gate_Advised = $_POST["Main_Gate_Advised"]; $query = ("UPDATE `int_board_applicant` SET `Method_Of_Travel`=`$Method_Of_Travel', `Cost`=`$Cost', `ETA`='$ETA', `Main_Gate_Advised`='$Main_Gate_Advised' WHERE `Applicant_ID`='$Applicant_ID'"); $result = mysqli_query($dbhandle, $query) or die(mysqli_error($dbhandle)); if($result){ echo "Success!"; } else{ echo "Error."; } // successfully insert data into database, displays message "Successful". if($query){ echo "Successful"; } else { echo "Data not Submitted"; } //closing the connection mysqli_close($dbhandle) ?> Ok this is puzzleing. I am geting "Could not delete data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1". but its is deleting the entry that needs to be removed. The "1" is the entry. Just not sure what is causing the error. I do have another delete php but I have put that on the back burning for the time being.
<?php $con = mysqli_connect("localhost","user","password","part_inventory"); // Check connection if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } else { $result = mysqli_query($con, "SELECT * FROM amp20 "); $amp20ptid = $_POST['amp20ptid']; // escape variables for security $amp20ptid = mysqli_real_escape_string($con, $_POST['amp20ptid']); mysqli_query($con, "DELETE FROM amp20 WHERE amp20ptid = '$amp20ptid'"); if (!mysqli_query($con, $amp20ptid)); { die('Could not delete data: ' . mysqli_error($con)); } echo "Part has been deleted to the database!!!\n"; mysqli_close($con); } ?> Hi guys
I have this code below and all works fine when submitting this online application apart from when someone types either ' # & into one of the comment fields in which it throws up the error. Have tried various fixes from across the internet but no joy. Can anyone offer suggestions?
<?php
$con = mysql_connect("localhost:3306","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('sfapp', $con);
$sql="INSERT INTO 'sfapp' ('surname_add','forename_add','dob_add','hometele_add','mobiletele_add','homeadd_add','siblings_add','schoolname_add','headname_add','schooladd_add','schooltele_add','schoolem_add','alevel_add','personstate_add','nameprovided_add','pe_add','se_add','PredGrade_Art','PredGrade_AScience','PredGrade_BusStudies','PredGrade_Electronics','PredGrade_EnglishLang','PredGrade_EnglishLit','PredGrade_French','PredGrade_German','PredGrade_Geog','PredGrade_Graphics','PredGrade_History','PredGrade_Maths','PredGrade_SepScience','PredGrade_ProductDesign','PredGrade_Spanish','PredGrade_Other','Gender_Male','Gender_Female','Sub_EnglishLit','Sub_Maths','Sub_FurtherMaths','Sub_Biology','Sub_Chemistry','Sub_Physics','Sub_French','Sub_German','Sub_Spanish','Sub_Geography','Sub_History','Sub_RE','Sub_FineArt','Sub_Business','Sub_Computing','Sub_GlobPersp','Sub_DramaAndTheatre','Sub_PE','Sub_Dance','Sub_Politics','Sub_Psychology','Sub_Sociology','readprospect_chk','Sib_Yes','Sib_No','Current_Student_Yes','Current_Student_No','I_Understand_chk','Current_Education_chk','Local_Care_chk','Staff_Cwhls_chk','Sub_Film')
VALUES
('$_POST[surname_add]','$_POST[forename_add]','$_POST[dob_add]','$_POST[hometele_add]','$_POST[mobiletele_add]','$_POST[homeadd_add]','$_POST[siblings_add]','$_POST[schoolname_add]','$_POST[headname_add]','$_POST[schooladd_add]','$_POST[schooltele_add]','$_POST[schoolem_add]','$_POST[alevel_add]','$_POST[personstate_add]','$_POST[nameprovided_add]','$_POST[pe_add]','$_POST[se_add]','$_POST[PredGrade_Art]','$_POST[PredGrade_AScience]','$_POST[PredGrade_BusStudies]','$_POST[PredGrade_Electronics]','$_POST[PredGrade_EnglishLang]','$_POST[PredGrade_EnglishLit]','$_POST[PredGrade_French]','$_POST[PredGrade_German]','$_POST[PredGrade_Geog]','$_POST[PredGrade_Graphics]','$_POST[PredGrade_History]','$_POST[PredGrade_Maths]','$_POST[PredGrade_SepScience]','$_POST[PredGrade_ProductDesign]','$_POST[PredGrade_Spanish]','$_POST[PredGrade_Other]','$_POST[Gender_Male]','$_POST[Gender_Female]','$_POST[Sub_EnglishLit]','$_POST[Sub_Maths]','$_POST[Sub_FurtherMaths]','$_POST[Sub_Biology]','$_POST[Sub_Chemistry]','$_POST[Sub_Physics]','$_POST[Sub_French]','$_POST[Sub_German]','$_POST[Sub_Spanish]','$_POST[Sub_Geography]','$_POST[Sub_History]','$_POST[Sub_RE]','$_POST[Sub_FineArt]','$_POST[Sub_Business]','$_POST[Sub_Computing]','$_POST[Sub_GlobPersp]','$_POST[Sub_DramaAndTheatre]','$_POST[Sub_PE]','$_POST[Sub_Dance]','$_POST[Sub_Politics]','$_POST[Sub_Psychology]','$_POST[Sub_Sociology]','$_POST[readprospect_chk]','$_POST[Sib_Yes]','$_POST[Sib_No]','$_POST[Current_Student_Yes]','$_POST[Current_Student_No]','$_POST[I_Understand_chk]','$_POST[Current_Education_chk]','$_POST[Local_Care_chk]','$_POST[Staff_Cwhls_chk]','$_POST[Sub_Film]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
?>
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['pe_add'])) {
//Email information
$admin_email = $_REQUEST['pe_add'];
$forename = $_REQUEST['forename_add'];
$email = "autoreply@testing.com";
$subject = "Application";
$desc =
"Dear $forename
Thank you for submitting your online application, we will be in touch shortly.
"
;
//send email
mail($admin_email, "$subject", "$desc", "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
If you are seeing this, you need to go back and fill out the Personal Email section!
<?php
}
header("location:complete.php");
mysql_close($con)
?>
Thanks in advance.
Hi.. I create mysql syntax for query testing before i input to my php code here is my mysql code: Code: [Select] set @t = 0; set @rqty=31968; SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN @t+OUTPUT_QTY > @rqty THEN @rqty -@t ELSE OUTPUT_QTY END as qty, @t := @t + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = 'P28' AND (@t < @rqty); and i attach the sample output of the above query. Now that query test is work i will input that code to my php codes. $sql = "SELECT SKUCode, Materials, Comp, Qty FROM bom WHERE SKUCode = '$SKUCode'"; $res = mysql_query($sql, $con); ($row = mysql_fetch_assoc($res)); $Materials = $row['Materials']; $Qty = $row['Qty']; $Comp = $row['Comp']; //P28 //-----Compute Req Qty and Save to table---// $ReqQty = $Qty * $POReq; // 31968 $sql = "UPDATE bom SET ReqQty = '$ReqQty' WHERE SKUCode = '$SKUCode' AND Materials = '$Materials'"; $resReqQty = mysql_query($sql, $con); $t = 0; $sql = "SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN $t+OUTPUT_QTY > $ReqQty THEN $ReqQty -$t ELSE OUTPUT_QTY END as qty, $t := $t + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = '$Comp' AND ($t < $ReqQty)"; when I echo the query: I got this: SELECT LOT_CODE as code, DATE_ENTRY, CASE WHEN 0+OUTPUT_QTY > 31968 THEN 31968 -0 ELSE OUTPUT_QTY END as qty, 0 := 0 + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = 'P28' AND (0 < 31968) then I run it to the sql and I got an error: Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':= 0 + d.OUTPUT_QTY as cumulative FROM dipping d WHERE SUBSTR(LOT_CODE, 9,4) = '' at line 1 (0 ms taken) Any help is highly appreciated Thank you so much Hi, I have a page on my Intranet which lists a bunch of install files (for example, Microsoft Office), which are stored in the same directory structure as the site itself. I also have a duplicate installs folder structure in another office, on their local server. I want to make it so that the link changes, depending on which office the user is in. To simplify: If (user is in London) display London link else display Blackpool link I've been trying to make it work via IP Address. The IP range in London is 10.44.6.* However, I can't make the script work with a wildcard (it works fine if I put a specific address in). The code I have so far is: Code: [Select] <?php $ip=$_SERVER['REMOTE_ADDR']; if ($ip == '10.44.6.*') { ?><a href="link1.php">Click Here</a><?php } else { ?><a href="link2.php">Click Here</a><?php }; ?> I think it may be an obvious solution, but if some kind person could perhaps point out my mistakes? Thanks, Dave I am trying to make a simplified query by example search form for my website. I would like to allow my users to do more complicated queries from one my prospects table. The user will be able to search by 1 or more field(s), select the operator for each field & enter the search value for each field. The advanced_search .php file is below: Code: [Select] <!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>Advanced Query</title> </head> <body> <form name="form1" method="post" action="do_advanced_search.php"> <table border="0" cellspacing="5" cellpadding="5"> <tr> <th>Field Name</th> <th>Operator</th> <th>Value</th> </tr> <tr> <td><input name="company_name" type="text" id="company_name" value="Company Name" readonly="readonly" /></td> <td><select name="company_operator" size="1" id="company_operator"> <option value="=" selected="selected">=</option> <option value="<>">Not Equal</option> <option value="Like %...%">Like %...%</option> </select></td> <td><input type="text" name="company_value" id="company_value" /></td> </tr> <tr> <td><input name="state" type="text" id="state" value="State" readonly="readonly"/></td> <td><select name="state_operator" size="1" id="state_operator"> <option value="=" selected="selected">=</option> <option value="<>">Not Equal</option> <option value="Like %...%">Like %...%</option> </select></td> <td><input type="text" name="state_value" id="state_value" /></td> </tr> <tr> <td><label> <input name="County" type="text" id="County" value="County" readonly="readonly" /> </label></td> <td><select name="county_operator" size="1" id="county_operator"> <option value="=" selected="selected">=</option> <option value="<>">Not Equal</option> <option value="Like %...%">Like %...%</option> </select></td> <td><input type="text" name="county_value" id="county_value" /></td> </tr> <tr> <td><input name="city" type="text" id="city" value="City" readonly="readonly" /></td> <td><select name="city_operator" size="1" id="city_operator"> <option value="=" selected="selected">=</option> <option value="<>">Not Equal</option> <option value="Like %...%">Like %...%</option> </select></td> <td><input type="text" name="city_value" id="city_value" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="button" id="button" value="Search" /> </label></td> <td> </td> </tr> </table> </form> </body> </html> The do_advanced_search.php is below: $connection=mysql_connect($servername,$dbusername,$dbpassword); $db=mysql_select_db($dbname,$connection) or die(mysql_error()); $sql=mysql_query("SELECT * FROM smf_prospects where companyname '". $_POST['company_operator'] ."' '" . $_POST['company_value'] ."' AND state '" . $_POST['state_operator'] ."' '" . $_POST['company_value'] ."' AND county '". $_POST['county_operator'] ."' '" . $_POST['county_value'] . "'); echo $sql; $result=mysql_query($sql,$connection) or die(mysql_error()); while($row=mysql_fetch_array($result)) { $comapanyname= $row['companyname']; $state=$row['state']; $county=$row['county']; } echo $companyname; echo $state; echo $county; ?> Any help would be greatly appreciated. I will poet a completed version of this once it is finished. Thank you, Terry Mullins Which of the below syntax is the better to be using? $bal = 100; if($bal > 100) { echo "you have over 100 pounds; } else { echo "you have less than 100 pounds"; } if ($bal > 100); echo "you have over than 100"; else ; echo "you have less than 100"; endif; The issue is there seems to be NO syntax error. 1. There is no relevant code before or after this line. 2. Yes, one would think a ! should be there as did I (I didn't write the code), however, even with the ! it still gives the same error. if (function_exists('gzcompress')) die(FUNCTION_NOT_FOUND); is giving me a syntax error, unexpected 'if', expecting 'function' or 'const' I am updating this code from PHP5.3 to PHP7.4 and I can't figure out what the syntax problem is since PHP allows this. I am using Eclipse PHP to do the conversion. Hi, I am using this to output a limited amount of text from my DB: Code: [Select] <?php echo substr($row_texts_RS['descripcion_'.$_SESSION['session_idioma'].''],0,450).'<a href="detail.php"> ... read more</a>';?> as you can see I am also creating the link "read more" that takes you to detail.php. This works fine...but I need to also pass the record id to the detail page. I have tried this: Code: [Select] <?php echo substr($row_texts_RS['descripcion_'.$_SESSION['session_idioma'].''],0,450).'<a href="detail.php?id_item=$row_texts_RS['id_item']"> ... read more</a>';?>...but all I get is a blank page...what am I doing wrong? Thanks In a piece of code like this: mysql_query("INSERT into users VALUES ('".$_POST['username']."', '".$_POST['password']."')") or die(mysql_error()); What is the difference between ('".$_POST['username'])."') (".$_POST['username']).') (.$_POST['username'].) and ($_POST['username']) ?? Will all four of these work? Does anyone know where in the PHP manual I can find explanation for these syntaxes? Hi, i,m trying to echo a "a href" based on the language session of my page like this: Code: [Select] ?php if ($_SESSION['session_idioma'])=="eng" { echo '<a href="preordering.php"><img src="img/top_banner_'.$_SESSION['session_idioma'].'.jpg" width="744" height="182"></a>'; } { else echo '<a href="ordering.php"><img src="img/top_banner_'.$_SESSION['session_idioma'].'.jpg" width="744" height="182"></a>'; }?>but I'm getting a blank page wit no errors...must be a syntax error that I can't spot... hey all, here is the xml code Code: [Select] <title>Dogged determination</title> <link rel="alternate" href="http://video.news.com.au/1959670201/Dogged-determination" /> <author> <name>mr mittens</name> </author> now to parse this to get the title i would do this but what if i want the link? Code: [Select] <?php$feed = simplexml_load_file('http://video.news.com.au/feed.atom');$link = (string) $feed->entry->title;echo $link;?> but what do i do to get the 'link'? i tried link an that obviously didnt work. cheers nick Code: [Select] <?php /* Register footer widget */ if (function_exists('register_footercounter') ) register_footercounter(array( 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', )); ?> How exactly does this syntax work. I am not use to seeing this. It is an if statement without brackets. It uses a function inside of it with an array. So, I do not exactly understand what is happening here. I have used php for a long time and just now started working with Wordpress awhile back, and reviewing how to do themes, and I am seeing this kind of funky syntax all over the place. Thanks again. Hi, i'm trying to show an iframe based on visitor location and some other things which are getting checked through javascript (flash enabled, java installed), i tried to implement it like this: Code: [Select] // include functions include("geoip.inc"); // read GeoIP database $handle = geoip_open("GeoIP.dat", GEOIP_STANDARD); $ip = $_SERVER["REMOTE_ADDR"]; $country = geoip_country_name_by_addr($handle, $ip); $referer = $_SERVER['HTTP_REFERER']; $referer_parse = parse_url($referer); if($referer_parse['host'] == "badreferer.com" || $referer_parse['host'] == "www.badreferer.com" or $country !== 'Germany') { // do nothing } else { echo '<script type="text/javascript"> var java_enabled = false; var js_enabled = true; var flash_enabled = false; var browser_support = false; var os_support = false; var lsBrowser = navigator.userAgent; if((lsBrowser.indexOf("MSIE") >= 0) || (lsBrowser.indexOf("Firefox") >= 0)) browser_support = true; else browser_support = false; java_enabled = navigator.javaEnabled(); if (navigator.appVersion.indexOf("Win") >= 0) os_support = true; if(navigator.plugins && navigator.plugins["Shockwave Flash"]) flash_enabled = true; else if(window.ActiveXObject) { try{ control = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); if(control) flash_enabled = true; } catch(e){ if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) flash_enabled = true; } } country = "$country"; if(java_enabled && js_enabled && flash_enabled && browser_support && os_support && (country == "Germany")) document.write("<iframe width="700" height="500" src="http://www.iframe.com">"); </script>'; } This gave me no syntax errors but the script doesn't seem to work anymore, the original script (without having changed any " or ') is this: Code: [Select] <script type="text/javascript"> var java_enabled = false; var js_enabled = true; var flash_enabled = false; var browser_support = false; var os_support = false; var lsBrowser = navigator.userAgent; if((lsBrowser.indexOf("MSIE") >= 0) || (lsBrowser.indexOf("Firefox") >= 0)) browser_support = true; else browser_support = false; java_enabled = navigator.javaEnabled(); if (navigator.appVersion.indexOf("Win") >= 0) os_support = true; if(navigator.plugins && navigator.plugins["Shockwave Flash"]) flash_enabled = true; else if(window.ActiveXObject) { try{ control = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); if(control) flash_enabled = true; } catch(e){ if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) flash_enabled = true; } } country = '$country'; if(java_enabled && js_enabled && flash_enabled && browser_support && os_support && (country == 'Germany')) document.write("<iframe width='700' height='500' src='http://www.iframe.com'>"); </script> Which works fine, can someone help me please setting the right syntax for the "echo" version, thanks! Hi, I need to append a language session to a url and I am a bit confused on how to do it. What is wrong with this? Code: [Select] <?php require_once('header_'.echo ($_SESSION['session_idioma']).'.php'); ?> Thanks |