Jump to content

HuggieBear

Members
  • Posts

    1,899
  • Joined

  • Last visited

Everything posted by HuggieBear

  1. The page you keep listing doesn't look like a poll and it also doesn't do anything! Do you mean a rating system?  Where you rate something from say 1 - 5? Regards Huggie
  2. [quote author=redarrow link=topic=109459.msg441397#msg441397 date=1159230061] is $rank set to a while loop i dont see it any where? [/quote] I think that bit's irrelevant at the moment. Regards Huggie
  3. Two things...1) You can't use OR when testing for negativity.  2) Try seperating each section with parenthesis to make it a bit more readable [code] <?php if (($rank == "mod") || ($rank == "admin")){   echo "You're authorized"; } else {   echo "You're not authorized";   exit(); } ?>[/code] Regards Huggie
  4. Surely this is a case for RTFM :) I'd never normally suggest it as I enjoy the challenges too much, but the manual's quite good on this subject. [url=http://uk.php.net/manual/en/language.variables.external.php]Variables from outside PHP[/url] Regards Huggie
  5. It would also be a good idea, as Andy suggested, to out values in your <option> tags, rather than just letting them take the value of the text. Regards Huggie
  6. Have you tried correcting the errors generated? You have formatting in your XML, I don't think that's correct, I think you have to have a seperate stylesheet for formatting. Try making changes as suggested by feed validator. 1. Remove the [code=php:0]<br>[/code] tag. 2. Get rid of the [code=php:0]<b>[/code] tags. 3. Make sure the SQL actually works first by using something like phpMyAdmin. Regards Huggie
  7. Your IF needs two '=' signs and quotes " "... if ($nomtacyn == "No"){ Regards Huggie
  8. Create a page that looks like this: [size=8pt][b]info.php[/b][/size] [code] <?php   phpinfo(); ?> [/code] Upload it to your server in ascii and make sure it has the correct permissions.  Then open it in the browser and see what happens. If you get info about the php installation then it's worked ok, if not you need to contact your host and see if there's something they need to enable, or find out if they can offer you any support. Regards Huggie
  9. Not bad for untested :) The end of line 52 looks like this: [code=php:0]...MYSQL_ASSOC){[/code] Change it to this: [code=php:0]...MYSQL_ASSOC)[/code][color=red][b])[/b][/color][color=green]{[/color] Notice the extra closing parenthesis. Regards Huggie
  10. OK, you have an extra WHERE in there instead, when using AND or OR, they replace WHERE.  Try this: [code=php:0]$query_directory = "SELECT * FROM directory WHERE Name LIKE '%{$_POST['name']}%' OR Keywords LIKE '%{$_POST['keywords']}%' ORDER BY name"; [/code] Regards Huggie
  11. Yes you can, and there's no need to put the ASC bit on the end.  just [color=blue]ORDER BY name[/color] will be fine as the default method is ascending. Regards Huggie
  12. The error's telling you the problem is with the [url=http://uk.php.net/manual/en/function.mysql-query.php]mysql_query()[/url] command. Look a little closer at the error: [quote] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\cms\includes\functions.php on line 41 [/quote] What this means is that where you have [code=php:0]mysql_fetch_array($result)[/code], $result is not a valid resource.  Implying that this didn't work properly: [code=php:0] return mysql_query($query, $this->link) or die(mysql_error()); [/code] Or that it did work correctly, but the line that's calling it is not [code=php:0]$result = dbquery($query);[/code] and last but by no means least, and possibly the cause of the problem :) you have [code=php:0]function $dbquery($query){[/code] this should probably just be [code=php:0]function dbquery($query){[/code] without the [b]$[/b] at the beginning of the function name. Regards Huggie
  13. OK, I've changed the both the HTML in the form and the PHP/SQL in the results page, so give the following a try.  I'd suggest copying and pasting exactly as is, then putting your database password in, it should work for the setup you have as I've kept your table/column names the same: [size=8pt][b]Form:[/b][/size] [code] <html> <head>   <title>Mooring Facilities Search Form</title> </head> <body>   Please select the facilities you would like at a mooring:   <form name="myform" action="search.php" method="GET">   <div align="left"><br>     <input type="checkbox" name="option[]" value="electricity"> Electricity<br>     <input type="checkbox" name="option[]" value="shower"> Shower<br>     <input type="checkbox" name="option[]" value="toilet"> Toilet<br>     <input type="checkbox" name="option[]" value="bin"> Refuse-bin<br><br><br>     <input type="submit" type="Submit">   </div>   </form> </body> </html> [/code] [size=8pt][b]Results Page:[/b][/size] [code]<?php // Your db connection options $user="root"; $host="127.0.0.1"; $password=""; $database = "moor_simple"; $connection = mysql_connect($host,$user,$password) or die ("couldn't connect to server"); $db = mysql_select_db($database, $connection) or die ("couldn't select the database"); // Base SQL statement $sql = "SELECT name FROM moor_facility WHERE id"; // If they've selected options, which ones if (isset($_GET['option'])){   $options = $_GET['option'];   foreach ($options as $opt){       if ($opt == "electricity"){         $sql .= " AND electricity IS NOT NULL";       }       else if ($opt == "shower"){         $sql .= " AND shower IS NOT NULL";       }       else if ($opt == "toilet"){         $sql .= " AND toilet IS NOT NULL";       }       else if ($opt == "bin"){         $sql .= " AND bin IS NOT NULL";       }   } } // Run the query $result = mysql_query($sql) or die ("couldn't run the query $sql" . mysql_error()); // Echo the top html echo <<<HTML <html> <head>   <title>search database for matching records</title> </head> <body>   <table width="300" cellpadding="2" cellspacing="0" border="1">   <tr>     <td>     The Search Results are:     </td>   </tr> HTML; // While there's still rows, loop through them while($row = mysql_fetch_array($result, MYSQL_ASSOC){ echo <<<HTML <tr> <td>   {$row['name']} </td> </tr> HTML; } // Echo your footer echo <<<HTML   </table> </body> </html> HTML; ?> [/code] Here's a few changes I made and the reasons for them, read these to better help yourself understand what I did and why... [size=8pt][color=blue][b]Change:[/b] You had the if statement incorrect, you had normal parenthesis, instead of curly braces, changed to curly's. [b]Reason:[/b] Incorrect syntax. [b]Change:[/b] You had $option[1], $option[2], $option[3] and $option[4], changed these to start at $option[0]. [b]Reason:[/b] Array indices start at 0, not 1. [b]Change:[/b] Did away with the whole of the above options and replaced with a foreach loop. [b]Reason:[/b] If someone only submitted refuse-bin on the form, and none of the others, it would actually become $option[0], not the expected $option[4], which meant your SQL statement would be incorrect. [b]Change:[/b] The values on the form itself. [b]Reason:[/b] To help tidy up code and assist with the above foreach loop. [b]Change:[/b] Moved all the HTML into [url=http://uk.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc]heredoc[/url] syntax. [b]Reason:[/b] I believe that it makes it look tidier and easier to read. [b]Change:[/b] Rather than echo $result which would just print [b]Array()[/b] it now echos the results from the db. [b]Reason:[/b] You had the syntax not quite right.[/color][/size] Well that's it, I hope it helps, if it doesn't work (as I've coded it on the fly and haven't tested it) then please post back the error you get and I'll correct. Regards Huggie
  14. Id try something like: [code] <?php $price = $_GET['price']; if (preg_match("/^\$/", $price)){   echo "Please remove the $ from the price field<br>\n"; } ?> [/code] Regards Huggie
  15. I think this is a job for a Regular expression. Look at the manual for both [url=http://uk.php.net/manual/en/function.preg-match.php]preg_match[/url] and [url=http://uk.php.net/manual/en/function.preg-replace.php]preg_replac[/url]e. Regards Huggie
  16. In that case it would appear something else before hand is falling over. Can you provide me with the whole code for the page that you have. Regards Huggie
  17. I've just broken the code down and tried the following to my hotmail.co.uk address and not only did it arrive ok, but it went into the inbox as opposed to the junk mail. Try copying and pasting this code into a page and seeing if it works, just replace the toAddress. [code] <?php   $message = "<h1>Test HTML email</h1><img src=\"http://www.dizzie.co.uk/myspace/sig.gif\" alt=\"Signature\">";   // Set some parameters   $toAddress = "myemailaddress@hotmail.co.uk";   $subject = "Test Subject";   $headers = "Content-type: text/html\n\n";   // Try to send the message   $success = mail($toAddress,$subject,$message,$headers);   if($success){       print "Newsletter Sent";   }   else{       echo'Newwsletter could not be sent';   }  ?> [/code] Assuming that this works ok then add bits to it gradually. Regards Huggie
  18. [quote author=yartax link=topic=109432.msg441033#msg441033 date=1159200107] I have a problem with IE timeout (or any browser).[/quote] Was replied with this: [quote author=mewhocorrupts link=topic=109432.msg441037#msg441037 date=1159200593] I looked this one up, and PHP had a bug submission for it... They marked it as bogus, since it doesn't happen with any other browser. [/quote] I'd say that you've possibly misunderstood something somewhere mewhocorrupts. yartax, maybe you need to look at why you're code's taking so long to execute as opposed to how to increase the timeout settings.  How long does the query actually take to run when executed in MySQL? Regards Huggie
  19. [quote author=radar link=topic=108666.msg437413#msg437413 date=1158689653] I found the real cause of my problems and the post has been edited acordingly. [/quote] So what's the problem now then? Regards Huggie
  20. Yes, obviously a conditional loop with includes should be fine. I have something similar to this already, are you displaying the results ordered horizontally or vertically? [pre]Horizontal: 1  2  3  4 5  6  7  8 9  10  11  12 Vertical: 1  4  7  10 2  5  8  11 3  6  9  12[/pre] Regards Huggie
  21. Try this: [code] <?php $sql = "SELECT name FROM moor_facility WHERE id"; if (isset($_GET['option'][1]))(   $sql .= " AND electricity IS NOT NULL"; // I have added spaces in front of each of these values and removed the equals '=' } if (isset($_GET['option'][2]))(   $sql .= " AND shower IS NOT NULL"; // added a space, removed = } if (isset($_GET['option'][3]))(   $sql .= " AND toilet IS NOT NULL"; // added a space, removed = } if (isset($_GET['option'][4]))(   $sql .= " AND bin IS NOT NULL"; // added a space, removed = } echo "$sql<br>\n"; // quoted the echo string and added a newline character $result = mysql_query($sql); echo "$result<br>\n"; // quoted the echo string and added a newline character ?> [/code] You don't use = with IS NOT NULL just the column name Regards Huggie
  22. Ken, In this instance would the following work? [code=php:0] $query_directory = "SELECT * FROM directory WHERE Name LIKE '%{$_POST['name']}%' ORDER BY id DESC";[/code] Or does SQL not like the curley braces? Regards Huggie
  23. Why are you using sprintf()? Why not just have... [code=php:0]$query_directory = "SELECT * FROM directory WHERE Name LIKE '%$_POST['name']%' ORDER BY id DESC";[/code] Regards Huggie
  24. My suggestion would be to echo $sql before running the query, that way if it looks wrong you'll know it's the php as opposed to the DB. In this instance you'd have seen your query isn't as you'd expect it, you're not referencing the variables inside the array correctly... change: [code=php:0]$_GET['option[1]'][/code] to: [code=php:0]$_GET['option'][1][/code] Regards Huggie
  25. In addition to Ronald's comments, if you ever have problems with this sort of thing, try going back to basics and adding in additional bits as you go to see what happens. Regards Huggie
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.