Jump to content

Philip

Staff Alumni
  • Posts

    4,665
  • Joined

  • Last visited

  • Days Won

    20

Everything posted by Philip

  1. Because include is looking for the file "bulletin.php?church=1" not "bulletin.php" You could always do : <?php $bar = 'test'; include 'foo.php'; ?> in foo.php: <?php echo $bar; // echo's test ?>
  2. What is , ("text"); supposed to be?
  3. Pretty much right, but for myself I would do a return with an array of the variables instead of using global. <?php function ui($user) { // added limit 1, since you only need one row, yes? $query = "select * from users where username = '".$user."' LIMIT 1"; $result = mysql_query($query) or die ("Could not match data because ".mysql_error()); // if there weren't any rows, return false, otherwise return the array if(mysql_num_rows($result) < 1) return false; else return mysql_fetch_array($result); } // call functions $userInfo = ui('some_username'); // if it was returned as an array, we have data! if(is_array($userInfo)) print_r($userInfo); else echo 'no data for this user!'; ?>
  4. You have it as if(empty($_POST)) { ... but then try to call a value from post $type = $_POST['type']; So you're not getting the $type, and not getting the "FROM tablename" in your query
  5. This works, but really isn't as efficient as just creating a variable $a = 'The text must be exploded'; echo implode(array_slice(explode(' ',$a),2,1));
  6. It is giving you that error because $title wasn't set because you have it being set when !empty($_POST) A workaround is on the fields have something like: <dd><input type="text" name="title" id="title" value="<?php if(isset($title)) echo $title; ?>" /></dd>
  7. Thats fine Just use tags
  8. if ($type = "gallery"){ $sql = "INSERT INTO img_gallery "; } if ($type = "sketches"){ $sql = "INSERT INTO img_sketches "; } should be (notice the ==, not =): if ($type == "gallery"){ $sql = "INSERT INTO img_gallery "; } if ($type == "sketches"){ $sql = "INSERT INTO img_sketches "; } Also, here's how I would design that using a switch (makes it easier to see & add more in options in the future): <?php switch($_GET['type']) { case 'gallery': $sql = "INSERT INTO img_gallery "; break; case 'sketches': $sql = "INSERT INTO img_sketches "; break; case 'another': default: // (in case the url variable doesn't match, what should it do? // this is where default comes in really handy // for an example, we'll use one from above: $sql = "INSERT INTO img_sketches "; break; } ?> edit: fixed a few typos + added switch statement code
  9. You're not getting any POST data, from the user. That's why they are "undefined index" errors. How are you submitting the data to that page?
  10. Above: $topic=$_POST['topic']; $detail=$_POST['detail']; $name=$_POST['name']; $email=$_POST['email']; put this: echo '<pre>'; print_r($_POST); echo '</pre>'; // post fields here... And copy/paste what that outputs
  11. printf is for formatting a string, while print_r will return a human readable variable dump.
  12. It should be: $vars = $_REQUEST; foreach($vars as $key => $var) { echo "Passed Name: ".$key."; Value: ".$var; } I prefer: echo '<pre>'; print_r($_REQUEST); echo '</pre>'; Although use of REQUEST can be iffy and unsecure (as with all user inputs)
  13. You need a period [.] before the $rows $qry="SELECT * FROM `members` WHERE `username`='".$rows['user']."'";
  14. Session register is deprecated, and you aren't using quotes around the index. session_start(); $_SESSION['id'] = "foo"; $hi = $_SESSION['id']; echo $hi; // shows 'foo' @OP, any reason to why you're trying to call the session id? <?php session_start(); $_SESSION['myVar']="hello" ; // don't really need this $sessId=session_id(); echo "<br> sessId: " . $sessId . "<br>" ; print('<iframe name="test" id="test" src="foo/bar.php" marginwidth=0 marginheight=0 onload="this.height=this.contentDocument.height" width="100%" frameborder="0" scrolling="yes"></iframe>'); ?> <?php session_start(); if(!isset($_SESSION['myVar']) || empty($_SESSION['myVar'])) { echo "<pre>" ; print_r($_SESSION); echo '</pre>'; } else { //something } ?>
  15. Change: <?php if(empty($_GET['ID'])) to: <?php print_r($_GET); if(empty($_GET['ID'])) And double check to make sure that get index is correct. Just as a reminder, ID is not the same as id. It is case sensitive
  16. Take a look at natsort() It'll sort numbers by what you think is correct, 1,3,5,20,41 instead of 1,20,3,41,5
  17. Change: $result = mysql_query("SELECT * FROM properties WHERE bedrooms >= '$bedrooms' $type $maxprice $area ORDER BY maxprice"); to: $result = mysql_query("SELECT * FROM properties WHERE bedrooms >= '$bedrooms' $type $maxprice $area ORDER BY maxprice") or die(mysql_error());
  18. read my edit, and update the code to that
  19. Because on the end of $area you have ORDER BY, instead of in your query. If you change your original script to this: $type=($_POST['type']=="") ? "" : "AND type = '{$_POST['type']}'"; $bedrooms=$_POST['bedrooms']; $maxprice=($_POST['maxprice']=="") ? "" : "AND maxprice < '{$_POST['maxprice']}' AND"; $area=($_POST['area']=="") ? "" : "AND area = '{$_POST['area']} "; //connect to mysql //change user and password to your mySQL name and password mysql_connect("*****","*****","*****"); //select which database you want to edit mysql_select_db("****"); //POST the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM properties WHERE bedrooms >= '$bedrooms' $type $maxprice $area ORDER BY maxprice"); Does it fix it? By the way, you still need to fix the way it is setup with regards to the AND's. I might have maxprice, but not area, and it'll show: "maxprice < 500000 AND ORDER BY maxprice" which is incorrect syntax. EDIT: fixed the AND problem, moving the and's to the font of the variables will allow it to work properly.
  20. Well, there are a few things wrong with that query. first of all, it's always a bad idea to have direct user input into a database. $type=($_POST['type']=="") ? "" : "type = '{$_POST['type']}' AND"; $bedrooms=$_POST['bedrooms']; $maxprice=($_POST['maxprice']=="") ? "" : "maxprice < '{$_POST['maxprice']}' AND"; $area=($_POST['area']=="") ? "" : "area = '{$_POST['area']}' ORDER BY"; //connect to mysql //change user and password to your mySQL name and password mysql_connect("*****","*****","*****"); //select which database you want to edit mysql_select_db("****"); //POST the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM properties WHERE $type bedrooms >= '$bedrooms' AND $maxprice $area maxprice"); Change that to: $type=($_POST['type']=="") ? "" : "type = '{$_POST['type']}' AND"; $bedrooms=$_POST['bedrooms']; $maxprice=($_POST['maxprice']=="") ? "" : "maxprice < '{$_POST['maxprice']}' AND"; $area=($_POST['area']=="") ? "" : "area = '{$_POST['area']}' ORDER BY"; //connect to mysql //change user and password to your mySQL name and password mysql_connect("*****","*****","*****"); //select which database you want to edit mysql_select_db("****"); //POST the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $Query = "SELECT * FROM properties WHERE $type bedrooms >= '$bedrooms' AND $maxprice $area maxprice"; echo $Query; $result = mysql_query($Query) or die(mysql_error()); Maybe then you'll see the problem - especially when maxprice isn't empty, but area is.... You'd get something like "maxprice < 500000 AND maxprice"
  21. Read the error, it tells you what is wrong - You did not supply any parameters in the setcookie() function call.
  22. I don't know why you created a new topic when you had this one Just the same as a while, <?php $i = 1; foreach($array as $key=>$value){ $i++ //echo table if($i == 5){ //echo banner $i = 1; } }
  23. <?php function random_float ($min,$max) { return ($min+lcg_value()*(abs($max-$min))); } echo round(random_float(1,7),2); ?> There is probably a better way, but that's just one way
  24. As taken from a php.net comment: <?php function random_float ($min,$max) { return ($min+lcg_value()*(abs($max-$min))); } echo random_float(1,7); ?> You could then take it to whatever decimal you wanted.
×
×
  • 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.