Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Everything posted by Nodral

  1. Not Impossible you just need to put a timed redirect onto page 2. and assign the $_POST variables to a $_SESSION variable <?php //page2 session_start(); //check if prize button has been pressed and assign message to session variable if(isset($_POST['freebie'])){ $_SESSION['message']=$_POST['prize'] } ?> <head> <meta http-equiv="refresh" content="10; url=page1.php"> </head> <?php //Page1 session_start(); //check if session variable is set if(isset($_SESSION['message'])){ // display message echo $_SESSION['message']; //clear variable unset($_SESSION['messge']); } ?> <form method="post" action="page2.php"> <input type="hidden" name="prize" value="You have won a fantastic prize!!!!"> <input type="submit" name="freebie" value="Click to receive prize"></form>
  2. so amend to the following To be honest though, you don't actually need to pass the message through the URL in this instance, you can just change pages and then if the submit butons have been pressed, test for that and then display a message. You shouldn't use die in that context. Very bad practice
  3. <?php //Page1 ?> <form method="post" action="page2.php"> <input type="hidden" name="prize" value="You have won a fantastic prize!!!!"> <input type="submit" name="freebie" value="Click to receive prize"> </form> <?php //page2 //check if prize button has been pressed and display message if(isset($_POST['freebie'])){ echo $_POST['prize']; }
  4. Use a HTML form with a submit button and a hidden field to trigger the link. Then use POST to send the variable to the new page, thus not appearing in the URL.
  5. Just a thought, probably a bit crude for the php purists around Why not explode the row by comma to break off the latter part of the row, then explode the result by open bracket to remove the first bit. Then you'll be left with NAME=........................ You could I suppose then explode again on the = to be left with just the name. Seem more straight forward than trying to preg_match a non standard.
  6. Hi In this line, you are not referencing any variable? $query = "INSERT INTO `profs` (`rating`) VALUES (`rating`)"; Surely it should be $query = "INSERT INTO `profs` (`rating`) VALUES (`$rating`)";
  7. if($where==2){ $and=" AND "; } if($where==3){ $AND=" AND "; }
  8. if(strlen($_POST['model'])>0){ $model=" model='".$_POST['model']."'"; $where++; } if(strlen($_POST['fuel'])>0){ $fuel=" fuel='".$_POST['fuel']."'"; $where++; } if(strlen($_POST['year'])>0){ $year=" year='".$_POST['year']."'"; $where++; } Try this, just moved a few brackets around to make the if test run correctly
  9. $result="SELECT * FROM cars".$where.$model.$and.$fuel.$AND.$year"; echo $result; $result=mysql_query($result); while($row = mysql_fetch_array($result)) { echo $row['Make']; echo $row['Model']; echo $row['Year']; echo $row['Fuel']; } ?> Try this. What is displayed for $result?
  10. Repost your whole code as the error is with the construction of the sql statement. All that $where does, is increment everytime a filter is used so the WHERE or AND's can be put in. You basic SELECT statement is SELECT * FROM CARS if $where is 1 (ie a filter has been set) this will then produce SELECT * FROM CARS WHERE filter = condition. if $where is 2 this adds in the first AND clause SELECT * FROM CARS WHERE filter = condition AND filter=condition if $where is 3 this adds in the second AND clause SELECT * FROM CARS WHERE filter = condition AND filter=condition AND filter=condition Others may offer different ways of acheieving this, but I find this easy to follow through and understand
  11. It will tell you they are undefined as you really should define a vairiable before you use / call it. You'll see that these are only Notices rather than warnings. Not declaring variables doesn't tend to make your script fall over, but some purists will pick fault at it. All you need to do is at the start of the script just list each variable you are going to use and make it ="". eg $model=""; Is it all working apart from that? Do you understand what we have done?
  12. try $model=" model='".$_POST['model']."'";**** You'll probably have to do this with the other varibale in the query too
  13. if(strlen($_POST['model']>0)){ $model=" model='$_POST['model']'"; $where++ } if(strlen($_POST['fuel']>0)){ $fuel=" fuel='$_POST['fuel']'"; $where++ } if(strlen($_POST['year']>0)){ $year=" year='$_POST['year']'"; $where++ } if($where==2){ $and=" AND "; } if($where==3){ $AND=" AND "; } if($where>0){ $where=" WHERE "; } Sorry missed a couple of = signs out too
  14. can you repost all code and highlight which line the error points to
  15. sorry missed a closing quote try amending the following lines, adding a single quote prior to the double quotes at the end of each line. $model=" model='$_POST['model']'"; $fuel=" fuel='$_POST['fuel']'"; $year=" year='$_POST['year']'"; You may want to include an echo statement to show exactly what sql query is running. Try including this for debugging but remove it prior to production $result=mysql_query("SELECT * FROM cars ".$where.$model.$and.$fuel.$AND.$year); echo $result; This will show exactly what sql you are running and if you have any sort of error with it, will show you where you need to amend.
  16. You've missedc a closing bracket from this line should be
  17. Instead of try if(strlen($_POST['fuel']>0)){ $fuel=" fuel='$_POST['fuel']"; $where++ } if(strlen($_POST['model']>0)){ $model=" model='$_POST['model']"; $where++ } if(strlen($_POST['year']>0)){ $year=" year='$_POST['year']"; $where++ } if($where=2){ $and=" AND "; } if($where=3){ $AND=" AND "; } if($where>0){ $where=" WHERE "; } $result=mysql_query("SELECT * FROM cars ".$where.$model.$and.$fuel.$AND.$year); Then make sure the first option of each filter dropdown is blank. If they select a blank then the filter variable will not be set. Whereas if they set the filter it will populate the query with WHERE and AND. If you're putting loads of filters on, it may be worthwhile changing the if($where=........ statements to a switch.
  18. Without writing the code for you, Have each user response return a value to search for and then add it to a variable which you can include in a SQL query eg if $_POST['filter1]=ford $_POST['filter2']=escort create variables which are $filter1=" make = '".$_POST['filter1]"'"; $filter2=" AND model = '".$_POST['filter2]"'"; etc etc Then run a query of $sql="SELECT count(*) WHERE".$filter1.$filter2.etc.etc; hope this helps
  19. Please repost your code so we can see what changes you have made. Have you moved the closing brace as suggested?
  20. Move your closing braces to how I posted above. You come out of your if statement too early, so that the else you set your session variable in, is if $_POST['submit'] is not set. Hope that makes sense
  21. Alternatively try this Your if closing braces were also in the wrong place too. Check how they are now set above
  22. As you manualy declare that $submit = $_POST['submit'];, regardless of whether there is a value in $_POST['submit'] you have set the variable. therefore if($submit) will always return true. You should use if(isset($_POST['submit'])){ This way, it is only true if the submit button has been clicked. A better way to organise your code by the way, is to have all your php processing at the top, then have your output (HTML form) at the end
×
×
  • 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.