Jump to content

spryce

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Everything posted by spryce

  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.
  15. PS - i did read the sticky on header errors. I have a stack of $POST calls ie $subject = check_input($_POST['subject']); before my function. I assume this means that data is sent to the browser which is why I cant use the header function. But the reCaptcha stuff doesnt work unless this comes first.
  16. Newbie question. I have a form that uses reCaptcha. If the Captcha is entered correctly it posts the data. Can I redirect the page using php or do I need to use javascript? I was going to throw in header('Location: thankyou.php'); but from my limited understanding this cannot be used anywhere except the very top of the page. if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { echo "Recapture entered correctly!"; // Just for testing purposes postdata($firstname, $lastname, $company, $email, $phone, $comments); // sends data to my databse // this is where I would expect to redirect to a new page } Thanks phpfreaks
  17. Ahhhhhh....... and the penny drops. I will go and change the paths to absolute and see if that fixes my other problem as well. Thanks man
  18. yesss.. excellent. Muah ha ha ha.......... now Igor - "Throw ze switch!"
  19. Awesome thanks. That solves my single dot issue ( and why ive never used it ) but since this is a relative path I still cant see why it works. The path to database.php is: development/classes/database.php - and the path to constants.php is: development/includes/constants.php so we arent in the same directory and I actually need to go up one level and into includes - or I need a week off because my brain has malfunctioned.
  20. My very first post..... please be gentle. Question 1: Why does this work? - include("./includes/constants.php"); Ok here goes - I have a website which was written in php. I did not write it and the person who did was new to php and programming - as am I. I have the job of completing it. It was written trying to follow an OO model. I have a class 'Database.php' which handles the DB connection side of things. Pretty standard stuff. This database class 'includes' a file called 'constants.php' which stores the DB_SERVER, DB_USER, DB_PASS and DB_NAME properties. HERE IS THE CATCH. The includes statement says: include("./includes/constants.php"); I dont understand the single dot and have not yet used it. The site works fine - with the exception that my forms do not work. The site pulls data, images, urls from the database so it obviously connects ok. The constants.php file is located up one level then in the includes folder. ie include("../includes/constants.php"); If I add a second dot ( ../ )it breaks - even though the path is correct with 2 dots. I dont get it. Question 2: So to add insult to injury when I leave it as a single dot (if it aint broke, dont fix it) and try to post a form I get these error messages: Warning: include(./includes/constants.php) [function.include]: failed to open stream: No such file or directory in /home/******/public_html/development/classes/database.php on line 2 Warning: include(./includes/constants.php) [function.include]: failed to open stream: No such file or directory in /home/******/public_html/development/classes/database.php on line 2 Warning: include() [function.include]: Failed opening './includes/constants.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/******/public_html/development/classes/database.php on line 2 I am a total newb at this but my english tells me that all of a sudden it is looking for my constants.php file in a total new path either :/usr/lib/php or usr/local/lib/php. Is there something special about 'includes'? I have used requires and require_once etc for other included files (in this website) without any path drama. I am using cPanel and I dont even see those directories - /usr/lib/php:/usr/local/lib/php. I hope I didnt put anyone to sleep. Both of these seem like simple problems, but I have tried and failed. Thanks for your help.
  21. I have come to suck your brains... or at least as much php as I can from them. I am am 34, new to programming and taking a radical change in my career path. I quit my reasonably successful career and decided to go to university to get a degree and for some silly reason I seem to have chosen software engineering. Most of the past 12 months I have spent learning Java and now I have started on php to finish off a website that I need for another side project. So... im a newb. But I am enjoying this stuff and soaking it up pretty quickly. Usually I dont join forums because I dont talk much and dont usually need too. Someone else has always suffered from whatever problem I may be facing and its usually just quicker to find my solution online. I decided in this case since I may be doing this for the rest of my working life that perhaps I should join the community. Hopefully one day I may even be able to give something back. Cheers.
×
×
  • 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.