Jump to content

spryce

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male

spryce's Achievements

Member

Member (2/5)

0

Reputation

  1. i cant figure out why this doesnt work. I just want to store the time that the user logged in. The other data is pulled from the db. $found_user = mysql_fetch_array($result); $_SESSION['id'] = $found_user['id']; $_SESSION['username'] = $found_user['username']; $_SESSION['user_f_name'] = $found_user['user_f_name']; $_SESSION['access_level'] = $found_user['access_level']; $_SESSION['time'] = date('h:i:a'); // Whats wrong with this ?? Cheers
  2. talk about doing things the hard way.... echo $all_vars['subject'];
  3. I came up with this but it outputs the value 3 times... (because there are 3 variables) ie mathsmathsmaths How do I fix this or do it the correct way? Thanks $subject = "maths"; $phone = "1235"; $colour = "red"; $all_vars = compact("subject", "phone", "colour"); get_value($subject); function get_value($variable){ global $all_vars; foreach($all_vars as $key=>$value){ if ($key = $variable) { echo $key; } } }
  4. This worked! yay me.... <?php echo get_query(); function get_query() { global $query; if (!isset($_POST['query'])) { $query = ' '; } else { $query = $_POST['query']; } } function return_incident_data($query ) { if ($query === ' ') { get_query1(); } if ($query === 'query1') { get_query1(); } if ($query === 'query2') { get_query2(); } if ($query === 'query3') { get_query3(); } } ?> <form name="form1" id="form1" method="post" action="thispage.php"> <p>Order by: <select name="query" id="query" onchange="document.form1.submit()"> <option value="query1" >Sort by A</option> <option value="query2" >Sort by B</option> <option value="query3" >Sort by C</option> <option value="query4" >Sort by D</option> </select></p> <table><?php return_incident_data($query); ?> </table>
  5. get_query_1() just calls a specific sql query on the db. I just tried this. <?php $query = get_query(); function get_query() { global $query; if (!$_POST['query']) { // giving me an undefined index error here $query = ' '; } else { $query = $_POST['query']; } } function return_incident_data($query ) { if ($query === ' ') { get_query1(); } if ($query === 'query1') { get_query1(); } if ($query === 'query2') { get_query2(); } if ($query === 'query3') { get_query3(); } } ?> <form method="post" action="thispage.php"> <p>Order by: <select name="query" id="query" onchange="this.form.submit()"> <option value="query1" >Sort by A</option> <option value="query2" >Sort by B</option> <option value="query3" >Sort by C</option> <option value="query4" >Sort by D</option> </select></p> <table><?php return_incident_data($query); ?> </table> But I get the undefined index error....
  6. I am currently using a javascript to redirect the page using a select tag and the onchange property. Each page calls a different function. I want to be able to pass the <select> value to a variable that I can use within a php condition statement on the same page. This will generate the required output based on the <select> value. This way I dont require a seperate page for each query. So onchange.... $select_value == this.value? Then within my page: if ($select_value == 'alpha') { get_query_alpha(); } if ($select_value == 'bravo') { get_query_bravo(); } This is my current set up... <p>Order by: <select name="query" id="query" onchange="gotourl(this.value)"> <option value="query1.php" >Sort by A</option> <option value="query2.php" >Sort by B</option> <option value="query3.php" >Sort by C</option> <option value="query4.php" >Sort by D</option> </select></p> <table> <?php get_query_1();?> </table> and js... function gotourl(url){ window.location= url; } function selectsubject(){ alert("Please select a subject!"); } Is there a simple way to do this? Thanks.
  7. All of my form POST data (from multiple forms) is managed through a file called formdata.php. Formdata.php and check_input() performs trim/stripslashes/htmlspecialchars etc on the posted variables. (it also indirectly calls relevant database functions such as insert or select). What is the correct way to add all of the variables to an array so that I can so that I can pass the array(ofvariables) to a function. ie the checked variables (only a few of them): $subject = check_input($_POST['subject']); $repphone = check_input($_POST['repphone']); $repfirstname = check_input($_POST['repfirstname']); $replastname = check_input($_POST['replastname']); $streetnum = check_input($_POST['streetnum']); $streetname = check_input($_POST['streetname']); $suburb = check_input($_POST['suburb']); $postcode = check_input($_POST['postcode']); there will be many subjects and many more variables so instead of listing the variables such as: function post_to_table(){ // variables global $subject;, $streetnum, $streetname, $suburb, $postcode; global $repphone, $repfirstname, $replastname; if ($subject === "specifiedsubject"){ post_to_appropriate_table($streetnum, $streetname, $suburb, $postcode, $repphone, $repfirstname, $replastname); } I would rather use an array instead of passing each variable individually: function post_to_appropriate_table ($streetnum, $streetname, $suburb, $postcode $repphone, $repfirstname, $replastname) { global $database; $sql = "INSERT INTO incident ("; $sql .= "streetnum, "; $sql .= "streetname, "; $sql .= "suburb, "; $sql .= "postcode, "; $sql .= "repphone, "; $sql .= "repfirstname, "; $sql .= "replastname"; $sql .= ") "; $sql .= "VALUES ("; $sql .= "'{$streetnum}', "; $sql .= "'{$streetname}', "; $sql .= "'{$suburb}', "; $sql .= "'{$postcode}', "; $sql .= "'{$repfirstname}', "; $sql .= "'{$replastname}'"; $sql .= ") "; // echo $sql; //for debugging if required; return $database->query($sql); } how can I ditch the ever growing list of variables and use an array? Thanks.
  8. Thanks to both of you! saurabhx for sowing me what I needed to do. kney for sorting my dodgy syntax. Thanks again.
  9. I have a web server which contains a public site and a private site. I want to be able to test for public or private using the page title and return the appropriate header which contains a different banner, css etc. Firstly - the syntax below seems to be incorrect because it doesnt work correctly. More importantly how do I add all the values to an array and than iterate through it to check for a matching page title? public function publicSite() { if ($this->getTitle()== 'Home' || 'About Us'||'Registration' || 'Sitemap' || 'Contact Us' || 'Useful Links' || 'Feedback') { return true; } return false; } Then later on I would have: if ($this->publicSite()) { require($ROOT.'interface/pages/publicheader.php'); } else { require($ROOT.'interface/pages/privateheader.php'); } Thanks heaps!
  10. $_SERVER['HTTP_REFERER']; <-- this returns the full path. Can I return the referring page name only? ie) somepage.php Cheers
  11. That sounds exactly like what I need....... But how can I create a hidden field? What code? Thanks
  12. forget that..... thats stupid. Then I would need to reference each form by name. I need a generic reference that I can use on multiple forms. I am a newb btw. Any healp appreciated. Thanks
  13. I want to post some form identifyer when I hit submit, so that I can use this in an SQL query. Previously I used the below code and would retrieve either page1.php or page2.php etc from $_POST['subject']); <td> <select name="subject" id="subject" onchange="gotourl(this.value)"> <option value="" >Please Select</option> <option value="page1.php" >page1</option> <option value="page2.php">page2</option> <option value="page3.php">page3</option> </select> </td> will this work? <form id="form1" name="form1" value="tableName" method="post" action=""> $_POST['form1']) returns tableName...... Thanks
  14. Thanks for the very informative responses guys. Much appreciated.
×
×
  • 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.