PHP - Dumb Question
I have a script and for some reason I can't get to echo "No results" when nothing matches. I know it is something simple but I can't see it. Can anyone help?
Code: [Select] <?php mysql_connect ("localhost", "","") or die (mysql_error()); mysql_select_db (""); $search = mysql_real_escape_string(preg_replace('/[^\w\'\"\@\-\.\,\(\) ]/i', '', $_POST['search'])); if(strlen($search) < 3){ echo "<br /><input type='image' value='Back' src='images/min.png' alt='Back' onClick='history.go(-1);return true;'></FORM>"; } else{ $sql = mysql_query("SELECT * FROM apartments WHERE contact LIKE '%$search%' OR phone LIKE '%$search%' OR office LIKE '%$search%' OR town LIKE '%$search%' OR cross_streets LIKE '%$search%' OR description LIKE '%$search%' OR email LIKE '%$search%' OR rent LIKE '%$search%' order by `date_created`"); if ( mysql_num_rows($sql) > 0 ) { echo "<strong style='color: #6EBEFB'>Click Headers to Sort</strong>"; echo "<br/><strong style='color: #6EBEFB'>Your Results for: </strong>"; echo htmlentities($_POST['search']); echo "<table border='0' align='center' bgcolor='#6EBEFB' cellpadding='2' bordercolor='#000000' table class='sortable' table id='results'> <tr> <th style='color: #FFF'> Title </th> <th style='color: #FFF'> Rent </th> <th style='color: #FFF'> Bed </th> <th style='color: #FFF'> Bath </th> <th style='color: #FFF'> Contact </th> <th style='color: #FFF'> Office </th> <th style='color: #FFF'> Phone </th> <th style='color: #FFF'> Image </th> </tr>"; while ($row = mysql_fetch_array($sql)) { $image = (!empty($row['imageurl1'])) ? "<img src=\"../user/{$row['imageurl1']}\" width='50'>" : 'No Images'; echo "<tr> <td bgcolor='#FFFFFF' style='color: #000' align='center'> <a href='searchapts/index.php?id=".$row['id']."'>" . $row['title'] . "</a></td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['rent'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['rooms'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['bath'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['contact'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['office'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['phone'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>{$image}</td> </tr>"; } } echo "</table>";} { echo "No Results";} ?> Similar TutorialsI have been reading (here and on the internet) about login security, and I have now formulated a dumb question to ask. Not having a secure connection is there any way to NOT send plain text over the internet. In other words, when you have a login form plain text is entered. It is then passed to some type of encryption (hash, md5, sha1) BUT is the password always vulnerable between these two? And just for the record I am asking this because McAfee Secure is giving me a rash of (insert your favorite word here) about my login form which encrypts using sha1. How do i go about the tags in this, with the elseifs really lost in the past ive done it different and included exits and such but i want it to display at the top of the page and not go onto a whole new page to say the error, sorry if im making little sense just kinda baffled Code: [Select] <?php if($playerdata['is_admin'] == 1){ $result = mysql_fetch_array($query); if($_POST){ $price = mysql_real_escape_string($_POST['price']); $creditprice = mysql_real_escape_string($_POST['creditprice']); $ItemType = mysql_real_escape_string(isset($_POST['ItemType'])); $description = mysql_real_escape_string($_POST['description']); $image = mysql_real_escape_string($_POST['image']); $name = mysql_real_escape_string($_POST['name']); if($name == ""){ echo "You must enter an item name.<br><br>"; elseif ($description == ""){ echo "You must enter a description for this item.<br><br>"; elseif ($description2 == ""){ echo "You must enter a Character Req for this item.<br><br>"; elseif ($description3 == ""){ echo "You must enter a What item does for this item.<br><br>"; elseif ($ItemType == ""){ echo "You must select a item type.<br><br>"; elseif ($price == ""){ echo "You must select a price for this item.<br><br>"; elseif ($creditprice == ""){ echo "You must select a game credit price.<br><br>"; }else{ $sql = "INSERT INTO items(name,image,description,ItemType) VALUES ('$name', $image', '$description', '$ItemType')"; mysql_query($sql); echo "You have created $name<br /><br />"; ?> would anyone please help me work out why this is not working and even if I use the || operators it still wont work <?php $referer = $_SERVER['HTTP_REFERER']; if ($referer != 'http://digitalpixels.co.uk/portfolio' ) header('Location: http://digitalpixels.co.uk/404/') ; if ($referer != 'http://digitalpixels.co.uk/windscreen-repair-company' ) header('Location: http://digitalpixels.co.uk/404/') ?> thank you This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=357731.0 im not getting anything to display. any ideas? Code: [Select] <? include "config.php"; $groups=mysql_query("SELECT ID,company,address FROM company"); while(list($cid,$ccompany,$caddress)=mysql_fetch_row($groups)){ echo "<left><br />headlogo <table width='96%' cellpadding='1' cellspacing='1' border='1'> <tr> <td width='37%' colspan='4'><b>gname</b></td> </tr> <tr> <td width='25%'>Ladder</td> <td width='25%'>Game</td> <td width='25%'>Join</td> <td width='25%'>Rules</td> </tr>"; $ladders=mysql_query("SELECT id,jobNO,companyID FROM jobno WHERE grid='$gid' ORDER BY name"); while(list($jid,$jjobNO,$jcompanyID)=mysql_fetch_row($ladders)){ echo " <tr> <td width='25%'>$link</td> <td width='25%''>$glink</td> <td width='25%'>d</td> <td width='25%'>d</td> </tr>"; } echo "</table></left>"; } echo "<br /><br />"; ?> when in a form, I wish to build a conditional that if the response to a radio button is a value of 2 (female), it will display an input requesting for users maiden name. If not 2 goes to the next input statement. Here is code I was experimenting with: <html> <body> <form action="" name="test" method='POST'> <input type="radio" id="sex" value=1 checked><label>Male</label> <input type="radio" id="sex" value=2><label>Femaleale</label> <?php $result = "value"; if ($result == 2) echo "<input type='int' id='gradYear' size='3' required>"; else echo "Not a female!" ?> <input type="submit" value="GO"> </form> </body> </html> The code passes debug, however, Not a Female is displayed. My question is - Can I do this and if so, what value do I test against id='sex' or value. I tried each one but gave the same results. I realize that $_POST[sex] would be used after the submit button is clicked. But this has me stumped. Thanks for the assis in advance. Hello. I'm trying to pull information out of an xml file. However I'm a bit lost in getting the actual value. Code: [Select] $url="http://ws.audioscrobbler.com/2.0/?method=artist.getimages&artist=Dr%20Feelgood&limit=1&autocorrect=1&api_key=c107c9b5c09cb5693b6c19409dd984c1"; $xml = simpleXML_load_file($url,"SimpleXMLElement",LIBXML_NOCDATA); $largesquare=$xml->images->sizes->size[2]; Is what I have but its not pulling the information. The above url will give you the link to a set xml file for this example. And I want to get the info for the Code: [Select] <size name="largesquare" width="126" height="126">http://userserve-ak.last.fm/serve/126s/43173899.jpg</size> I'm sure I'm doing something wrong that's a simple fix but I am lost here. In the sizes there are 6 different size options each with different names and I have no idea how to pull the one with the correct name that I need. Thank you to who ever can help me sort this out. Hi, I am looking into a way of adding addons to a class I made.. I thought something like this would work, but not sure how to implement it: Code: [Select] <?php class foo { function foobar($text) { $text = $text . 'b'; return $text; } } class bar extends foo { function foobar($text) { $text = $text . 'c'; return $text; } } $var = new bar(); $var->foobar('a'); // this would then return abc ?> Now i want to be able to call up foo, and it calls the foobar of foo, and the foobar of bar. is that possible? hosh If the colde for $sql2 fetch's a value that is larger than what $sql3 fetch's, output the value of $query2, otherwise output the value of $query3.
<?php $sql2 = ";WITH TOTAL_FULL_ENERGY_SUM_BASE_WEEKEND_SUMMER AS ( SELECT cdate, datepart(hh, cdate) as trans_hour, datepart(mi, cdate) as trans_minute, comm_id, max(cast(total_full_energy_b AS FLOAT)/1000) * meter_multiplier AS totalUsage, meter_multiplier FROM [radiogates].[dbo].[purge_data] LEFT OUTER JOIN [radiogates].[dbo].[ops_invoice] on [radiogates].[dbo].[purge_data].[comm_id] = [radiogates].[dbo].[ops_invoice].[meter_id] where comm_id='$comm_id' and meter_multiplier is not null group by comm_id, cdate, meter_multiplier ) SELECT top 1 *, datepart(weekday, cdate) as trans_date_day, datepart(month, cdate) as trans_date_month, datepart(hour, cdate) as trans_date_hour, DATEPART(minute, cdate) as trans_date_minute FROM TOTAL_FULL_ENERGY_SUM_BASE_WEEKEND_SUMMER where datepart(weekday, cdate) IN ('1', '7') AND DATEPART(MONTH, cdate) IN ('5','6','7','8','9','10') and cdate between '$base_date $base_start_time' and '$base_date $base_end_time' ORDER BY totalUsage desc"; $query2 = sqlsrv_query($conn, $sql2);if ($query2 === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row2 = sqlsrv_fetch_array($query2)){ $sumUsageWEW += $row2[totalUsage];}sqlsrv_free_stmt($query2);?> <?php $sql3 = ";WITH TOTAL_FULL_ENERGY_SUM_INTERMEDIATE_WEEKDAY_SUMMER AS ( SELECT cdate, datepart(hh, cdate) as trans_hour, datepart(mi, cdate) as trans_minute, comm_id, max(cast(total_full_energy_b AS FLOAT)/1000) * meter_multiplier AS totalUsage, meter_multiplier FROM [radiogates].[dbo].[purge_data] LEFT OUTER JOIN [radiogates].[dbo].[ops_invoice] on [radiogates].[dbo].[purge_data].[comm_id] = [radiogates].[dbo].[ops_invoice].[meter_id] where comm_id='$comm_id' and meter_multiplier is not null group by comm_id, cdate, meter_multiplier ) SELECT top 1 *, datepart(weekday, cdate) as trans_date_day, datepart(month, cdate) as trans_date_month, datepart(hour, cdate) as trans_date_hour, DATEPART(minute, cdate) as trans_date_minute FROM TOTAL_FULL_ENERGY_SUM_INTERMEDIATE_WEEKDAY_SUMMER where datepart(weekday, cdate) IN ('2', '3','4', '5', '6') AND DATEPART(MONTH, cdate) IN ('5','6','7','8','9','10') and trans_hour in ('10','11','12','13','14','15','16','17','18','19','20','21','22') and cdate between '$int_date $int_start_time' and '$int_date $int_end_time' ORDER BY totalUsage desc"; $query3 = sqlsrv_query($conn, $sql3);if ($query3 === false){ exit("<pre>".print_r(sqlsrv_errors(), true));}while ($row3 = sqlsrv_fetch_array($query3)){ $sumUsageWKWi += $row3[totalUsage];}sqlsrv_free_stmt($query3);?> Edited by Butterbean, 22 October 2014 - 11:10 AM. say i have a mysql table with the following fileds user_id picture_category picture_title picture_description picture_thumb //small image size picture_normal //large image size. ok what I'm trying to do is this. if( user_id && picture_category == the same name show all the pictures in that category as one section) //show this category and all the images from this user_id and picture_category so if this user_id has a new category name and new images uploaded it would show the images in the right category. my php xml script is in the works and is looking like this so far. <?php include "../../connect.php"; Header('Cache-Control: no-cache'); Header('Pragma: no-cache'); $username = mysql_real_escape_string($_GET['username']); $user_folder = mysql_real_escape_string($_GET['user_folder']); //$password = mysql_real_escape_string($_GET['password']); $friend = (isset($_GET['friend'])) ? ' AND b.friend = \'' . mysql_real_escape_string($_GET['friend']) . '\' ' : NULL; $query = "SELECT * FROM accounts WHERE username = '$username'"; $results = mysql_query($query) or die("Data not found."); //Get the number of results from the query. $rows = mysql_num_rows($results); //If their is a match for the username, echo the the users xml data. if($rows == 1) { $query1 = "SELECT * FROM user_photo_gallery WHERE username = '$username'"; $query2 = "SELECT * FROM user_photo_gallery WHERE username = '$username' AND user_folder = '$user_folder'"; $results1 = mysql_query($query1) or die("Data not found."); $results2 = mysql_query($query2) or die("Data not found."); //$row = mysql_fetch_assoc($results1); $user_xml = "<?xml version=\"1.0\"?>\n"; $user_xml .= "<settings>\n"; $user_xml .= "<sceneHeight>600</sceneHeight>\n"; $user_xml .= "<sceneWidth>1000</sceneWidth>\n"; $user_xml .= "<titleColor>#000000</titleColor>\n"; $user_xml .= "<descriptionBgAlpha>70</descriptionBgAlpha>\n"; $user_xml .= "<showFullscreenBtn>no</showFullscreenBtn>\n"; $user_xml .= "<waterMark useImage=\"no\"><![CDATA[THIS]]></waterMark>\n"; $user_xml .= "</settings>\n"; $user_xml .="<galleries>\n"; //$sql = "SELECT a.username,a.user_folder,a.large_pic,a.small_pic,a.pic_title,a.pic_discription,b.username FROM (user_photo_gallery as a )JOIN `user_friends_list` as b ON (b.friend = a.username)WHERE (b.username = '$username' $friend AND b.status = 1) ORDER BY a.user_folder DESC"; //$result2 = mysql_query($sql); //if(mysql_num_rows($result2) > 0) //{ while ($row = mysql_fetch_assoc($results1)) { $user_xml .="<gallery theName=\"". $row['user_folder'] ."\" itemsPerRow=\"3\" autoStart=\"no\" playTime=\"5\" autoResize=\"yes\" xOffset=\"5\" yOffset=\"10\" showTitleOnThumbs=\"yes\" allowDownload=\"yes\">\n"; if($row['user_folder'] =="Demo_Photos") { //select all pictures where this folder name and username maybe? while ($row1 = mysql_fetch_assoc($results2)) { $user_xml .="<picture largePicture=\"". $row1['large_pic'] ."\" smallPicture=\"". $row1['small_pic'] ."\" theTitle=\"". $row1['pic_title'] ."\"><![CDATA[". $row1['pic_discription'] ."]]>\n"; $user_xml .="</picture>\n"; } } else { } $user_xml .="</gallery>\n"; } //} //else //{ //echo "Wiistream Eorror!\n"; //}; $user_xml .="</galleries>\n"; echo $user_xml; } else { echo "Wiistream Eorror!\n"; } ?> the real xml file should look like this. Code: [Select] <?xml version="1.0" encoding="utf-8"?> <settings> <sceneHeight>600</sceneHeight> <sceneWidth>1000</sceneWidth> <titleColor>#000000</titleColor> <descriptionBgAlpha>70</descriptionBgAlpha> <showFullscreenBtn>no</showFullscreenBtn> <waterMark useImage="yes"><![CDATA[<font size="20">Copyright (c) 2010</font> <font color="#000000"><Strong>WiiStream</Strong></font>]]></waterMark> </settings> <galleries> <gallery theName="USERS PERSONAL GALLERY TITLE" itemsPerRow="3" autoStart="no" playTime="5" autoResize="yes" xOffset="5" yOffset="10" showTitleOnThumbs="yes" allowDownload="yes"> <picture largePicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" smallPicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" theTitle="USERS TITLE OF PICTURE"><![CDATA[USERS DISCRIPTION OF PICTURE CAN USE TAGS]]></picture> </gallery> <gallery theName="USERS PERSONAL GALLERY TITLE1" itemsPerRow="3" autoStart="no" playTime="5" autoResize="yes" xOffset="5" yOffset="10" showTitleOnThumbs="yes" allowDownload="yes"> <picture largePicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" smallPicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" theTitle="USERS TITLE OF PICTURE"><![CDATA[USERS DISCRIPTION OF PICTURE CAN USE TAGS]]></picture> <picture largePicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" smallPicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" theTitle="USERS TITLE OF PICTURE"><![CDATA[USERS DISCRIPTION OF PICTURE CAN USE TAGS]]></picture> </gallery> <gallery theName="USERS PERSONAL GALLERY TITLE2" itemsPerRow="3" autoStart="no" playTime="5" autoResize="yes" xOffset="5" yOffset="10" showTitleOnThumbs="yes" allowDownload="yes"> <picture largePicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" smallPicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" theTitle="USERS TITLE OF PICTURE"><![CDATA[USERS DISCRIPTION OF PICTURE CAN USE TAGS]]></picture> <picture largePicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" smallPicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" theTitle="USERS TITLE OF PICTURE"><![CDATA[USERS DISCRIPTION OF PICTURE CAN USE TAGS]]></picture> <picture largePicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" smallPicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" theTitle="USERS TITLE OF PICTURE"><![CDATA[USERS DISCRIPTION OF PICTURE CAN USE TAGS]]></picture> <picture largePicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" smallPicture="http://acadianfury.files.wordpress.com/2007/01/mazda.jpeg" theTitle="USERS TITLE OF PICTURE"><![CDATA[USERS DISCRIPTION OF PICTURE CAN USE TAGS]]></picture> </gallery> </galleries> but using it with mysql it only gets the user_id and the picture_category for this user and pulls back that users data only. I also have a join table included to join if this user has friendship with that user. and then you would see all your pictures upload and category's. and all your friends pictures and category's. Hey, I have a while that shows the rows(duh). What i want to do is: show 3 rows then echo float left or clear both. So basically 3 at a time, but it shows all the rows in a nice order. Can someone do this? Cheers. On my login page i have a set a session when the user logs in called loggedIn and it = true
if($count == 1) { $_SESSION['username']; $_SESSION['password']; $_SESSION['loggedIn'] = true; header("Location: index.php");and on my index page i have session_start(); if(!isset($_SESSION['loggedIn'])) { echo "You are not currently logged in and to view this page you must be logged in to have access."; die(); }but when the user logs in it comes up with the message above echo "You are not currently logged in and to view this page you must be logged in to have access."; which obviously it should not do. Does anyone know how i can fix this? Hello, I have a 'strange' situtation. I have this string "Who Am I" that will be used as an header (site for a client) but the design shows that the word "Who" and the words "Am I" are in 2 different colors, in HTML this is a quick fix, but in PHP? What I was thinking was explode the string and fetch the first element put it in a var en then concat the 2 others. But what if the title is more then 3 elements after exploding? It needs to be more dynamic, but I don't know how to do it. Does anyone have an idea? U guys know in forums how at the top or bottom there links to the "1 2 3 4 5 next" and stuff? and how it loads a database? how would i do that exactly? or explain to me what it could be called. cause me i have no idea :/ I am trying to make it so that it will load if the site if the site is online(EG. $siteonline = 1), and so on. I can't seem to think of how I could do this so it will work from the very top of the page's html, to the very bottom. Like the following code is meant to list all of the stuff in that database. <?php $list_q = mysql_query("SELECT * FROM settings") or die (mysql_error()); while($list_f = mysql_fetch_assoc($list_q)) { } ?> I have my page laid out like this.. <?php include "includes/connect.php"; include "includes/config.php"; ?> <?php $list_q = mysql_query("SELECT * FROM settings") or die (mysql_error()); while($list_f = mysql_fetch_assoc($list_q)) { ?> Html content etc.. <?php } include 'includes/footer.php'; ?> But if I do it that way, It only displays what is in footer.php. I'm considering getting a VPS, but I'm not entirely sure what this would be able the handle. The specs doesn't look that good to me, but my friend swears it will handle running apache/php/mysql handling large websites and databases without a problem. I want to run multiple databases that just store statistics and I'm a bit worried about the RAM and the company doesn't even mention a cpu. Here's the specs: 256MB RAM 300GB HDD 10Mbps unmetered 1 IP Address My friend runs two counter-strike: source servers off his VPS (same stats).. so I'm actually considering this, but it just seems like it's not powerful enough. Oh.. forgot the most important part.. it's only $9. Hi to all people, I just want to know if there a php script I can use using DRM. The scenario, once the user download the song from a website, he/she can't forward into other using bluetooth or file transfer. It is possible to do that scenario? Thanks in advance hi php people, I am wondering will if the code below will work when I call $C->getafoo() will I get foo; I keep getting an error at this point return $this->A->a(); saying the method is not there Code: [Select] class A{ public function a(){ return "foo"; } } class B { public $A; function __construct($A) { $this->A = $A; } public function geta(){ return $this->A->a(); } } class C extends B{ public function getafoo(){ return geta(); } } $C = new C(new A()); echo $C->getafoo(); i have took a test that i think it has some errors: can you please confirm or infirm that A is the right answer? Question: The default value for __FILE__ is _______________________________. A. the complete path of the currently executing script B. the relative path of the currently executing script C. a magical constant; it does not have a default value D. the complete path of the previous executed script E. the relative path of the previous executed script Correct Answer: C User Answer: A Explanation: The PHP engine stores the full path and filename of the currently executing script within the __FILE__ constant. I have been away from PHP for a long time and I was looking over my old scripts. I did PHP OOP at one time and I used a paticular method to connect all my methods up and load them. I have been looking at other peoples code and when I look at my code it does not even feel like OOP, I want to know how to you link all the methods (or is it called functions?) in a class up and return them? I use to do this: Code: [Select] <?php class quickFUNC { function note_pad() { // code for notepad } function quickAdminFunc() { // code for admin func $this->note_pad(); } } $quickFUNC = new quickFUNC; if(isset($_GET['id'])) { $act = $_GET['id']; } else { $act = NULL; } switch ($act) { case 1: //some random code to launch case 1 break; default: $quickFUNC ->quickAdminFunc(); ?> This was my code back in the days, as you can see the notepad was called in the admin function then made the admin function default in the case switch. I looked at all my script and the all are layed out like this :S.. Can I get some help please, thank you. |