Jump to content

Suchy

Members
  • Posts

    140
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Suchy's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Hi guys I am having a problem with jQuery + Ajax. When a user tries to registers (a new account) + enters a username that is in MySQL + a wrong password (associated with that username), he gets this message $('#pass-reminder').click(function() { alert('Password reminder'); return false; }); ... $.ajax ({ type: "POST", url: "register.php", data: input_data, success: function(return_data) ... if(return_data == 0) { $("#submited .message").html('Our record indicate that you already have an account.<br> If you forgotten your password<span class="link"><a id="pass-reminder" href="#"> click here</a></span>'); } ... } }); For some reason the function does not get called when I click on the link, but when I place the link (<a id="pass-reminder" href="#"> click here</a></span>) anywhere on the page it works. Any workaround this ?
  2. Im having problem extending a class. <?php // Parent class class Profile { protected $id, $result, $info; protected function get_id() { return $_GET['id']; } protected get_info() { $id = $this->get_id(); $result = mysql_query("SELECT * FROM profiles WHERE id = '$id' "); return mysql_fetch_array($result); } public get_fname() { $info = $this->get_info(); return $info['fname']; } public get_lname() { $info = $this->get_info(); return $info['lname']; } } // Child class class Profile_new extends Profile { protected get_info() { $id = $this->get_id(); $result = mysql_query("SELECT * FROM new_profiles WHERE id = '$id' "); return mysql_fetch_array($result); } } // Webpage $profile = new Profile_new; $first_name = $profile->get_fname(); $last_name = $profile->get_lname(); ?> For some reason I still getting first + last names of people from the profiles table, and not from the new_profiles table. How can I fix this ?
  3. I have 2 tables, friends: and posts: anyway Im trying to get all the posts that a certain user and all of his friends have made. My query is: SELECT post, user , time FROM posts WHERE user = ( SELECT friend FROM friends WHERE user = 1 UNION SELECT user FROM friends WHERE friend = 1 ) But its not working, im getting: "Too many sub queries" error
  4. I have a people rating site and once in a while I get an email either from the cops or lawyers asking for ip address and MAC address of a someone who wrote an inappropriate comment. Collecting the ip address is no problem, but is it possible to get the mac address via php? I been searching for this and so far no luck.
  5. Instead of an url like this: places.php?state=tx&city=dallas i want a url like this: places.php/texas/dallas How can this be done? Some links to any tutorials will be very nice. Thanks
  6. I'm havving troubles filling in a dropdown list with values passed back via AJAX. function city_list (form_id, list_id) { if(httpObject.readyState == 4) { var cities = httpObject.responseText; for (i=0; i<cities.length-1; i++) { var city = cities[i].split(":"); document.form_id.list_id.options[document.form_id.list_id.options.length] = new Option (city[1] , city[0]); } } } This does not work, however when I manualy type in the form_id and the list_id it works. So if the form_id = city_form, list_id = city_names changing the line document.form_id.list_id.options[document.form_id.list_id.options.length] = new Option (city[1] , city[0]); to document.city_form.city_names.options[document.city_form.city_names.options.length] = new Option (city[1] , city[0]); it works. How can I get the first example to work, I want to pass the form and list info to the function.
  7. Suchy

    Teaching PHP

    Dont know exactly what their background is. But based on the program guide, they will have courses in CSS, intro to SQL, XML and Javascript. Plus my PHP class
  8. Hi Guys. I was asked to teach a intro to PHP course for continuing education at work. I work in IT at a college. The course will be broken down into 2hour class a week for 6 weeks. I never did this before. Any tips for me? Thanks
  9. Does not work for me, but thanks for the hint !
  10. Thats it, Thanks ! But the problem that I had was with newlines and returns. Ex. To keep the query looking clean I had something like this SELECT name.employes, birhtdate.employes, building.room, nr.room, name.dept, manager.dept, id.dept, ... FROM ... Instead of writing it in a single line. This is how I solved the problem <?php $query = str_replace("\r" , "" , $query); $query = str_replace("\n" , "" , $query); $query = str_replace("\t" , "" , $query); $regex = "/^SELECT .* FROM/i"; // $regex = "/^SELECT (.|\n|\s|\t|\r)* FROM/i"; <--- this did not work for me ?> Once again, thanks for the shorter regex.
  11. I'm having troubles with a regular expressions. What I want is to replace the begining of a SQL query. ex. SELECT * FROM employes ... SELECT name.employes, id.employes FROM employes ... SELECT name.employes, id.dept, nr.room FROM ... .... I need to replace anything between SELECT and FROM with SELECT COUNT(*) AS num_of_rows FROM <?php echo "old query -> " . $query . "<br><br>"; $regex = "/^(SELECT|Select|select)([\s]|[a-zA-Z0-9\.\*-_,]|[\s])+[(FROM|From|from)]/"; if (preg_match($regex , $query )) echo "YES<br>"; else echo "NO<br>" ; $query = preg_replace($regex, "SELECT COUNT(*) AS num_of_rows FROM ", $query); echo "new query -> " . $query . "<br><br>"; ?> How can I modify my regex inorder for this to work ?
  12. I want to return data from httpObject.onreadystatechange = function () . How can I retrieve the data from this function inside my validate() function, which this one is inside ?
  13. I have a form where I can schedule events (set room, date, start and end time). When I click submit Ajax check if there is already something scheduled ta that time, date and room. function get_results() { if(httpObject.readyState == 4) { var conflict_results = httpObject.responseText; if (conflict_results != "0") { // Conflict - Room + Date + time already in use alert(conflict_results); conflict_status = 1; } else { // No Conflict conflict_status = 0; } } } function check_for_conflicts(form) { var workshop_room = form.room.value; var workshop_date = form.date.value; var workshop_time_start = form.time_start.value; var workshop_time_stop = form.time_stop.value; var conflict_status ; // check for schedule conflicts httpObject = getHTTPObject(); if (httpObject != null) { httpObject.open("GET", "check_conflicts.php?d=" + workshop_date + "&r=" + workshop_room + "&st=" + workshop_time_start + "&sp=" + workshop_time_stop, true); httpObject.send(null); httpObject.onreadystatechange = get_results; } if (conflict_status == 0) return true; else return false; } The problem is that get_results() function sets conflict_status variable, but it is not available in the check_for_conflicts() function. The way this supposed to work is that when there is a conflict, the conflict_status variable is set to 1 and based on that check_for_conflicts() function returns False and the form is not submited. How can I get the value of the conflict_status variable passed to the check_for_conflicts() function ?
  14. Got to work. I just printed the results in filter.php and added a readystate function which places the results into a div.
  15. I am having trouble with my code. What it supposed to do is that you see a list of categories (ex. pencils, pens, erasers....) and once you select a category the items should be displayed. The items.php calls the filter.php file which contains a filter MySQL query. This works fine, except I can't get the items once they are retrieved from the database to show up on the items.php page items.php <html> <body> <script language=JavaScript> function getHTTPObject() { if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP"); else if (window.XMLHttpRequest) return new XMLHttpRequest(); else { alert("Please turn on JavaScript or disable NoScript plugin."); return null; } } function filter_cat(select) { var selected_cat_id = select.value; httpObject = getHTTPObject(); if (httpObject != null) { httpObject.open("GET", "filter.php?i=" + selected_cat_id , true); httpObject.send(null); } } </script> ...... <!-- this displays categories ex. pens, pencils /--> <form action="<?=$_SERVER['../PHP_SELF']?>" > <select size="5" onchange="filter_cat(this)" /> <?php foreach($categories as $i) { ?> <option value="<?= $i['id']; ?>" ><? printf ("%.30s", $i['name']); ?></option> <?php } ?> </select> </form> ...... <!-- this should display the items from a choosen category, ex. red pencil, blue pencil ... <?php foreach($items as $i) echo $i['id'] . " - " . $i['name'] . "<br>"; ?> ... </body> </html> filter.php <?php include("DBconnect.php"); $selected_id = mysql_real_escape_string($_GET['i']); $filter_results = mysql_query("SELECT * FROM items WHERE id_cat = '$selected_id'") ; $items = getRows($filter_results); ?> How can I get this to work ?
×
×
  • 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.