PHP - No Matches Problem
I'm trying to come up with some code...and need to echo certain things based on which query failed.
There are several query's and while loops nested together. I'm trying to use this... Code: [Select] <?php $rs = mysql_query($sql,$dbc); if (! $rs) { echo "You aren't scheduled to work in the next seven days...but check back often as the schedule is adjusted often."; } $matches = 0; while ($row = mysql_fetch_assoc($rs)) { $matches++; //rest of code here...which work when there are matches... ?> With no matches, it isn't echoing anything...instead of "You aren't scheduled to work in the next seven days...but check back often as the schedule is adjusted often." If I echo out $rs, I get RESOURCE ID #6 Any ideas? Thanks! Similar TutorialsHello guys. I have the following code and I would like to count the number of times that the word has been replaced. I tried echo count ($replacement) and echo count ($match) but both only show "1". I want to be able to tell if there has been a replacement and send a warning email and/or add a flag in the db. Code: [Select] $search_for_bad_words = mysql_query("SELECT * FROM badwords WHERE 1"); $ad_title2 = $ad_title; $ad_body2 = $ad_body; //$wordlist = "shit:cr*p|dang:d*ng|shoot:sh**t"; $seperate_text = "|"; $entry_seperate_text = ":"; while($row = mysql_fetch_array($search_for_bad_words)) { $wordlist = $wordlist.$seperate_text.$row[word].$entry_seperate_text.$row[r_word]; } $words = explode('|', $wordlist); foreach ($words as $word) { list($match, $replacement) = explode(':', $word); $ad_title2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_title2); $ad_body2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_body2); } Thanks for all your help! Hi there I am beginning to learn regex in php. I was wondering why the following regex pattern wasn't finding the two words in the string and replacing them with welcome? '/(Hello).*?(Hi)/is' Code: [Select] $patterns = array(); $patterns[0] = '/(Hello).*?(Hi)/is'; $replacements = array(); $replacements[0] = 'Welcome'; ksort($patterns); ksort($replacements); echo preg_replace($patterns, $replacements, $string); Any help would be much appreciated. Thanks a million! Im trying to insert a name into my database but I need it to go into the column that matches the sessions user id Code: [Select] "INSERT INTO users SET name = '".$_POST['name']."'"; how do I tell it to put name into name column with id matching Session id. really appreicate if someone could please help me with this. Hello, I am trying to get this backlink checker that checks to make sure another website has my link on their website, so far I can check to make sure the "href" link is there and is correct, but I cant get the textContent to prove valid or not it seems to always be proving true even when the textConent is not in the mysql database. The other persons website will have this: <a href="http://businessinvestingsorce.com">Business Investing Source</a> I need to make sure Business Investing Source (the textContent) matches the anchor in the database. Here is my code: Code: [Select] <?php function CheckForAnchorMatch($anchortext) { $query = mysql_query("SELECT * FROM allowed_anchor WHERE anchor='$anchortext'"); if(mysql_num_rows($query) != 0) { return true; } return false; } 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 ExtractAnchorText($html) { $dom = new DOMDocument; $AnchorTexts = array(); @$dom->loadHTML($html); $links = $dom->getElementsByTagName('a'); foreach ($links as $link){ $AnchorTexts[] = $link->textContent; } return $AnchorTexts; } 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"; } $html = file_get_contents ( $source ); $anchortext = ExtractAnchorText($html); if (CheckForAnchorMatch($anchortext) === false) { $falseFound = true; } else { $falseFound = false; } return $falseFound; } ?> Help greatly appreciated I have this query to show the current class I'm in: Code: [Select] $GetTimeTable = "SELECT * FROM timetable WHERE username='$username' AND Subject_date='$today_date'"; Then I have this to display current class: Code: [Select] if($TimeNow >= $Start_time && $TimeNow <= $End_time){ echo "Current Class: "; echo $Subject;} How would I find next class that day? Hi, I am doing an EDIT user page and would like to check records with a dropdown and then set as selected, please help! <select name="BrokerID" class="small-input"> <option value="Please select an option">Please select a Broker</option> <?php while($row2 = mysql_fetch_array($broker)) { echo '<option name="BrokerID" value="'.$row2['BrokerID'].'">'.$row2['BrokerName'].'</option>'; } ?> </select> First time post, be easy on me...
I'm using preg_match_all to return an array with all the matches. I know I'm missing something fundamental, but I either keep looking past it or am more screwy than I know.
Sample String
CC-BY-ND-NCI'm using the following code preg_match_all("/cc|creative commons|copyright|by|sa|nc|nd/i",$exifmeta['copyright'],$cmeta)I would expect to see Array ( [0] => Array ( [0] => CC [1] => BY [2] => ND [3] => NC ) )What I get is Array ( [0] => Array ( [0] => CC [1] => BY [2] => ND [3] => NC [4] => sa ) ) Hi guys and girls, I am having trouble finding out wether the query made no matches rather than just displaying the matches. So what I would want is for the search term to look at the database, and if there's not matches then say, "No match for your search term" Code: [Select] function search_applications() { global $dbc; echo '<form method="post" action="" id="search">'. "\n"; echo '<label for="search_applications">Search for an application</label>'. "\n"; echo '<input type="text" name="search_applications" />'. "\n"; echo '<input type="submit" name="submit" />'. "\n"; echo '</form>'. "\n"; if(isset($_POST['submit'])){ $search_applications = $_POST['search_applications']; if ($search_applications == "") { echo "<p>You forgot to enter a search term"; } //if (preg_match("/\b$search_applications\b/i")){ if(preg_match("/^[ a-zA-Z]+/", $search_applications)){ //for testing the variables //echo $search_applications; $sql="SELECT title, category, content FROM distributors_content WHERE title LIKE '%" . $search_applications . "%' OR category LIKE '%" . $search_applications ."%' OR content LIKE '%" . $search_applications ."%'"; $result=mysqli_query($dbc, $sql); //-create while loop and loop through result set while($row=mysqli_fetch_array($result)){ $title =$row['title']; $category=$row['category']; $content=$row['content']; //-display the result of the array echo "<ul>\n"; echo '<li> <a href="index.php?article='.$row['title'].'&&page=application" title=""> '.$title . ' ' . $category . '</a></li>'."\n"; echo "</ul>"; } }else{ echo "<p>Enter another search term</p>"; } } } Any pointers would be good Thank you Hi
I want to echo out something when I post the value of a radio button and this value matches the same name of a html file. How can I formulate my code to achieve that?
What I have so far:
<?php if (isset($_POST['submitradio'])) { $selected_dir = $_POST['radio1']; echo substr($selected_dir, 0, -4); echo '<img src="'.$selected_dir.'" />'; } ?>So far I get for example the name of the image(order.gif) and the image order. gif. What I now want is to formulate my code so that I can say if I have an image called "order.gif" and a file called "order.html" that I can then echo out some thing. I don't want to actually name the image or the html file. I just want to say if I have two different file types that start with the same name then I can echo out what ever. How can I do that? I have a website http://www.pbm-biz.com/cricket/ where I am streaming Live Cricket world cup matches. My question is that during the streaming, I would like to keep the code in PHP so that others don't copy it. I can't find any solution. Any suggestions. Thanks, Faisal 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. Folks, I have a dropdown, once values are selcted, these values should be put in a URL structure so that it matches with the one MoD_rewrite rule in my .htaccess. Here is my Mod_Rewrite Rule: RewriteRule ^(.*)/([^/]*)\.html$ search.php?q=$1&sc=$2 [QSA,L] Here is my Dropdown Code: <div id="search" > <form id="searchform" method="get" action="search.php"> <label>Search By Brand/ Manufacturer: </label> <select name="q"> <option value="SelectBrand">Select Brand</option> <?php if(isset($this->search->options)): ?> <?php foreach($mfg as $lolachild): ?> <option value="<?php echo $lolachild; ?>"><?php echo ucwords($lolachild); ?></option> <?php endforeach; ?> <?php endif; ?> </select> <select name="sc"> <option value="All"><?php eprint(LangAll); ?></option> <?php if(isset($this->search->options)): ?> <?php foreach($this->search->options as $cat): ?> <option value="<?php echo $cat->value; ?>"><?php echo $cat->name; ?></option> <?php endforeach; ?> <?php endif; ?> </select> <input type="submit" value="<?php eprint(LangSearch); ?>" /> </form> </div> Problem is, upon Submit, it goes to this link structu http://mydomain.co.uk/search.php?q=fisher&sc=302 It should rather be: http://au2.co.uk/fisher/302.html What am i missing or doing wrong? Cheer Natasha This code works, I am trying to disqualify certain keywords from a website I am scraping. For some reason, the D in the word dishwasher keeps a match from happening so i have to do this without the d. I just dont understand WHY. I tried it where both of them use Clean_String() which has a strtolower and tirm in it. The subject looks right, I tried utf8_encode() to make sure they were both the correct encoding but nothing works. Can anyone explain why the letter D is causing the word 'dishwasher' to not trigger strpos when I have the word 'dishwasher' in my disqualify array? $disqualify = array("ish-washer","ishwasher"); foreach($disqualify as $dis) { if(strpos(Clean_String($subject[0]), $dis)) { $status = 0; $color = "FF0000"; } } Guys thanks for helping me solve the problem i had but now i have another problem and i am lost. i have included the code below for you to have overview.
This is the code:
<table style="width:100%; margin-left:auto; margin-right:auto"> Does any1 know what would cause this problem? Here is the url www.mysite.com/profile.php?id=1447835&state=AL&firstname=TOM&lastname=ANDERSON When I try to echo the id, only 6 numbers appear, the 7th is stripped for some reason <? echo ($_GET["id"]); ?> would print 144783 if I change the $ID to 123456789 it will only echo 123456 I have a simple text file called bio.txt: Code: [Select] wohlersr; Richie Wohlers; Intermediate; Four Aces meyersg; Greg Meyers; Novice; Four Aces I wrote a little script, to return the info for Greg Meyers if the user id is correct, or say "Member not found" if incorrect. For some reason, my output is giving me both. I assume it's a context error, but can't figure it out. Here's my script: Code: [Select] <?php $file=file("bio.txt"); $count=count($file); $i=0; while($i<=$count) { $row = explode(";", $file[$i]); $id = $row[0]; $name = $row[1]; $class = $row[2]; $club = $row[3]; if($id=="meyersg"){ echo $name."</br>"; echo $class."</br>"; echo $club."</br>"; }else{ echo "Member not found."; } $i++; } ?> And here's the output I'm getting: Code: [Select] Member not found. Greg Meyers Novice Four Aces Member not found. Hi. I am from poland. I am 17 old age and like webmastering. I write my social network. I have new server 10 GB VPS and my script no runing In my server. in my server do can not login. No runing function Code: [Select] mb_strtolower();as delete function mb_strtolower() ; this login runing. In my server haven`t installing liberary GD and no runing upload avatars. my code upload is: elseif ($_GET['act'] == "upload") { echo <<< KONIEC <hr> <center> <p> <h2>Dodaj zdjęcie</h2> <ul class="gallery clearfix"> <li class="extra"> KONIEC; error_reporting(E_ALL); // we first include the upload class, as we will need it here to deal with the uploaded file include('include/class.upload.php'); // retrieve eventual CLI parameters $cli = (isset($argc) && $argc > 1); if ($cli) { if (isset($argv[1])) $_GET['file'] = $argv[1]; if (isset($argv[2])) $_GET['dir'] = $argv[2]; if (isset($argv[3])) $_GET['pics'] = $argv[3]; } // set variables $dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : 'test'); $dir_pics = (isset($_GET['pics']) ? $_GET['pics'] : $dir_dest); if (!$cli) { } // we have three forms on the test page, so we redirect accordingly if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'simple') { // ---------- SIMPLE UPLOAD ---------- // we create an instance of the class, giving as argument the PHP object // corresponding to the file field from the form // All the uploads are accessible from the PHP object $_FILES $handle = new Upload($_FILES['my_field']); // then we check if the file has been uploaded properly // in its *temporary* location in the server (often, it is /tmp) if ($handle->uploaded) { // yes, the file is on the server // now, we start the upload 'process'. That is, to copy the uploaded file // from its temporary location to the wanted location // It could be something like $handle->Process('/home/www/my_uploads/'); $handle->Process($dir_dest); function TestProcess(&$handle, $title = 'test', $details='') { global $dir_pics, $dir_dest; $unlink = 'test/'. $handle->file_dst_name; $myid = $_SESSION['id']; $opis = htmlspecialchars(stripslashes(strip_tags(trim($_POST["opis"]))), ENT_QUOTES); $handle->Process($dir_dest); if ($handle->processed) { unlink("$unlink"); $link = ''.$dir_pics.'/' . $handle->file_dst_name .''; $addphoto = mysql_query("INSERT INTO photo VALUES('', '$myid', '$link', '$opis')"); echo <<< KONIEC <br> <center> <img src="$link" > <br> <br /> </center> KONIEC; } else { echo '<fieldset class="classuploadphp">'; echo ' <legend>' . $title . '</legend>'; echo ' Error: ' . $handle->error . ''; if ($details) echo ' <pre class="code php">' . htmlentities($details) . '</pre>'; echo '</fieldset>'; } } if (!file_exists($dir_dest)) mkdir($dir_dest); // ----------- $handle->image_convert = 'jpg'; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = 500; $handle->image_precrop = 15; $handle->image_watermark = "watermark_large.png"; $handle->image_watermark_x = 20; $handle->image_watermark_y = -20; TestProcess($handle, '15px pre-cropping (before resizing 800 wide), large watermark automatically reduced, position 20 -20', "\$foo->image_convert = 'jpg';\n\$foo->image_resize = true;\n\$foo->image_ratio_y = true;\n\$foo->image_x = 800;\n\$foo->image_precrop = 15;\n\$foo->image_watermark = 'watermark_large.png';\n\$foo->image_watermark_x = 20;\n\$foo->image_watermark_y = -20;"); } else { // one error occured echo '<fieldset>'; echo ' <legend>file not uploaded to the wanted location</legend>'; echo ' Error: ' . $handle->error . ''; echo '</fieldset>'; } // we copy the file a second time // we delete the temporary files $handle-> Clean(); } else { // if we are here, the local file failed for some reasons echo '<fieldset>'; echo ' <legend>local file error</legend>'; echo ' Error: ' . $handle->error . ''; echo '</fieldset>'; } echo <<< KONIEC <li> </ul> </p> </center> KONIEC; is it the only problem that isn`t installing GD as i have something off in php.ini ? Plise Help me i'm getting this erro "Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in /***/***/*****.php on line 278 not an active session, starts new" this is the code: if ($phase = mysql_result(mysql_query("SELECT `phase` FROM `as_support` WHERE `mission` = '$var2'"),0,0)) { if ($phase=='5') { // mysql_query("DELETE FROM `as_support` WHERE `mission` = '$var2'"); // header("Location: https://www.**********/*******/*******.php"); } else { echo date('h:i:s') . ": PHASE is $phase<br />"; echo "\$var1=$var1,\$var2=$var2<br />"; } } else { echo "not an active session, starts new<br />"; echo "\$var1=$var1,\$var2=$var2<br />"; mysql_query("INSERT INTO `as_support` (`mission`, `phase`) VALUES ('$var2', '0')") OR DIE(mysql_error()); the first line is line no. 278 can someone please tell me what to do? tnx shirley The problem is whit the var $threadid . It dosent work here(it dosen't display the data from database): $dbh = "SELECT *FROM comments WHERE threadid = '".$threadid."' "; But if I assign a value before the that code the html page show correctly. Code: [Select] include("config.php"); $name = $_POST['name']; $comment = $_POST['comment']; $threadid = $_POST['threadid']; if($name & $comment) { $dbh="INSERT INTO comments (name,comment,threadid) VALUES ('$name','$comment','$threadid') "; mysql_query($dbh); } $dbh = "SELECT *FROM comments WHERE threadid = '".$threadid."' "; $req = mysql_query($dbh); while($row=mysql_fetch_array($req)) { echo "<li>"; echo "<br>"."<b>".$row['name']."</b></br>"."<br>".$row['comment']."</br>"; echo "</li>"; } Code: [Select] $('.submit').click(function(){ location.reload(); var name = $("#name").val(); var comment = $("#comment").val(); var threadid = $("#v").val(); var dat = 'name='+name+'&comment='+comment+'&threadid='+threadid; $.ajax({ type:"post", url:"comment.php", data:dat, success:function(){ console.log("dat"); } }); return false; }); |