Jump to content

Twinbird

Members
  • Posts

    18
  • Joined

  • Last visited

Twinbird's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I found my problem ... The issue was caused by my CSS. My "wrapper" class (applied to a div in the body) had "overflow-y: auto;". I removed this and now things are working! Hooray!
  2. Working with Chrome Developer Tools and Firefox Firebug, I noticed that the jQuery code is not actually setting a cookie :/ The only cookie being set is "PHPSESSID" for my PHP session. Once again, there are no errors on the page and my HTML is valid. Edit: Sorry, I see there is a cookie being set in Chrome Developer Tools. However, the value it contains is always 0 ... Also, when running "$.cookie("scroll", $(document).scrollTop() );" or "$.cookie("scroll", $(window).scrollTop() );" in the Chrome Developer Tools console, I get "scroll=0" as the output, regardless of where I am on the page. I don't get it ... This is the JS code in my head tag: <script src="jquery.min.js"></script> <script src="jquery.color.js"></script> <script src="//ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script> <script src="jquery.cookie.js"></script> <script type="text/javascript"> // When document is ready... $(document).ready(function() { // If cookie is set, scroll to the position saved in the cookie. if ( $.cookie("scroll") !== null ) { $(document).scrollTop( $.cookie("scroll") ); } // When scrolling happens.... $(window).on("scroll", function() { // Set a cookie that holds the scroll position. $.cookie("scroll", $(document).scrollTop() ); }); }); </script> Any more suggestions?
  3. Thanks for your suggestion nogray. Unfortunately, I still can't get it working
  4. So AJAX is not exactly what I want. There are certain times when the page will need to be refreshed, or when the user might refresh the page, during which a form is not submitted. I just tried this solution as well: http://stackoverflow.com/questions/7577897/javascript-page-reload-while-maintaining-current-window-position ... but it didn't work. I really have no clue why. Any suggestions guys?
  5. I just threw this post up here before I left work. Here is the source code for the page (implementing the jQuery solution, which isn't working for me): <!DOCTYPE html> <html> <head> <title>My web page</title> <!--========== CSS ==========--> <meta charset="UTF-8" /> <link rel="stylesheet" type="text/css" href="css/styles.css" /> <link rel="stylesheet" type="text/css" href="css/buttons.css" /> <!--[if gte IE 9]> <style type="text/css"> .gradient { filter: none; } </style> <![endif]--> <!--========== /CSS ==========--> <script src="jquery-1.10.2.min.js"></script> <script src="jquery.cookie.js"></script> <script type="text/javascript"> $(document).ready(function() { // If cookie is set, scroll to the position saved in the cookie. if ( $.cookie("scroll") !== null ) { $(document).scrollTop( $.cookie("scroll") ); } // When scrolling happens.... $(window).on("scroll", function() { // Set a cookie that holds the scroll position. $.cookie("scroll", $(document).scrollTop() ); }); }); </script> </head> <body> <div class="wrapper"> <!--========== The header ==========--> <div class="header"> <div style="background-color:black;width:100%;height:70px;margin:auto;max-width:1010px;"> <div class="uimage"><img src="images/logo-white.png" alt="White Logo" /></div> <span class="titleS"><b>|</b> My Web Application<br><span class="titleSsub">Visit Day: Thursday, March 8th</span></span> <span class="rightMenu menuLink"> Logged in as <u>Smith, John</u><span style="color:grey;"> | </span> <a href="http://example.com" target="_blank">Wiki Page</a><span style="color:grey;"> | </span><a href="" target="_self">Logout</a> </span> </div> <div style="height:5px; width:100%;background-color:#FECB00;margin:auto;max-width:1010px;"></div> </div> <!--========== /The header ==========--> <div class="content"> <a class="inactive" href="?page=options" target="_self">1 Preferences</a> <a class="button" href="?page=student" target="_self">2 Preferences</a> <a class="button" href="?page=lab" target="_self">3 Preferences</a> <a class="button" href="?page=admin" target="_self">User Admin</a> <a class="button" href="?page=schedule" target="_self">Settings</a> <br><br> <h1>1 preferences</h1> <form method="post"> <label>Select the professor you would like to view:</label> <select name="user"> <option selected value="1">Fehér Liüntika</option> <option value="2">Álmos Árpád</option> <option value="3">Nagy Tibor</option> <option value="4">Erős Pista</option> <option value="5">Erős Róbert</option> <option value="6">Szabó Bálint</option> </select> <input type="submit" value="Set user"> </form> <div class="userHighlight"> <form method="post"> <span>» Fehér Liüntika</span> <br><br><br> <label>Number of something:</label> <select name="group_number"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option selected value="3">3</option> </select> <br><br><br> <label>Select the time(s) the professor is available for a meeting:</label><br><br> <table> <thead> <tr> <th style="visibility: hidden;"></th> <th>Time Slot</th> </tr> </thead> <tbody> <tr class="interested" > <td><input type="checkbox" name="user_time[]" value="1" checked ></td> <td>time1</td> </tr> <tr class="interested" > <td><input type="checkbox" name="user_time[]" value="2" checked ></td> <td>time2</td> </tr> <tr class="interested" > <td><input type="checkbox" name="user_time[]" value="3" checked ></td> <td>time3</td> </tr> </tbody> </table> <br><br><br> <label>Select the students:<br> <span style="font-size: 11px;">(<span style="color: red;">♥</span> = student is interested in meeting with you)</span></label><br><br> <table> <thead> <tr> <th style="visibility: hidden;"></th> <th>Student</th> <th>Research</th> <th style="visibility: hidden;"></th> </tr> </thead> <tbody> <tr class="interested-i" > <td> <input checked type="radio" name="user_student[1]" value=""> Not interested<br> <input type="radio" name="user_student[1]" value="1"> Individual<br> <input checked type="radio" name="user_student[1]" value="0"> Group<br> </td> <td>student1</td> <td></td> <td style="background: none;"><span style="color: red;">♥</span></td> </tr> <tr > <td> <input checked type="radio" name="user_student[2]" value=""> Not interested<br> <input type="radio" name="user_student[2]" value="1"> Individual<br> <input type="radio" name="user_student[2]" value="0"> Group<br> </td> <td>student2</td> <td></td> <td style="background: none;"></td> </tr> <tr class="interested" > <td> <input type="radio" name="user_student[3]" value=""> Not interested<br> <input checked type="radio" name="user_student[3]" value="1"> Individual<br> <input type="radio" name="user_student[3]" value="0"> Group<br> </td> <td>student3</td> <td></td> <td style="background: none;"></td> </tr> <tr class="interested" > <td> <input type="radio" name="user_student[4]" value=""> Not interested<br> <input checked type="radio" name="user_student[4]" value="1"> Individual<br> <input type="radio" name="user_student[4]" value="0"> Group<br> </td> <td>student4</td> <td></td> <td style="background: none;"></td> </tr> <tr class="interested-i" > <td> <input checked type="radio" name="user_student[5]" value=""> Not interested<br> <input type="radio" name="user_student[5]" value="1"> Individual<br> <input checked type="radio" name="user_student[5]" value="0"> Group<br> </td> <td>student5</td> <td></td> <td style="background: none;"></td> </tr> <tr > <td> <input checked type="radio" name="user_student[6]" value=""> Not interested<br> <input type="radio" name="user_student[6]" value="1"> Individual<br> <input type="radio" name="user_student[6]" value="0"> Group<br> </td> <td>student6</td> <td></td> <td style="background: none;"></td> </tr> <tr > <td> <input checked type="radio" name="user_student[7]" value=""> Not interested<br> <input type="radio" name="user_student[7]" value="1"> Individual<br> <input type="radio" name="user_student[7]" value="0"> Group<br> </td> <td>student7</td> <td></td> <td style="background: none;"></td> </tr> </tbody> </table><br> <input name="form_submitted" style="padding: 5px 10px; margin-top:20px;" type="submit" value="Save"> </form> </div> </div> </div> </body> </html> I tested this solution using a static HTML page and it worked. So I'm not sure why it's not working with my PHP app. I get no errors on the page and I checked my code using W3C's Markup Validation Service (http://validator.w3.org). I'm assuming it could be something to do with the fact that all pages are being loaded through index.php using include statements that get data from the query string. So each page would actually look something like this: myserver.example.com/webapp/index.php?page=preferences1 or myserver.example.com/webapp/?page=preferences1 I'll look into using AJAX - but I will need it to refresh the html elements on the page, since the form will cause data to be added to my database which must be reflected in the html. Thanks for your reply josh.
  6. Hello, I've searched for a while now and can't find a working solution for my web app. I have a PHP web app with a bunch of include statements (this should be irrelevant) that can generate a page with a large height. When a user refreshes the page or clicks a submit button on the form (at the bottom of the page), I want the page to appear at the same scroll position when it reloads. A couple of things I've tried (but failed): http://blog.crondesign.com/2009/09/scrollfix-remember-scroll-position-when.html http://stackoverflow.com/questions/12744145/how-to-remember-scroll-position-o-page Any suggestions? I'm not sure why these aren't working for me.
  7. Hello, Nowhere in my code do I declare/create an $id variable. However, when I echo $id, I get a number! index.php: <?php require_once 'access.php'; userIsLoggedIn(); echo $id; // This outputs a number, yet I do not define or use $id anywhere! exit(); access.php: <?php function userIsLoggedIn() { if(!empty($_SERVER['REMOTE_USER'])) { $uid = $_SERVER['REMOTE_USER']; } if (isset($uid) and databaseContainsUserid($uid)) { return TRUE; } else { return FALSE; } } function userIsAdmin() { $uid = $_SERVER['REMOTE_USER']; if (isset($uid) and databaseContainsUseridAdmin($uid)) { return TRUE; } else { return FALSE; } } function databaseContainsUserid($userid) { include 'db.php'; try { $sql = 'SELECT id, name FROM user WHERE userid = :userid and type > 0'; $s = $pdo->prepare($sql); $s->bindValue(':userid', $userid); $s->execute(); } catch (PDOException $e) { echo 'Error searching for userid. ' . $e; exit(); } $row = $s->fetch(); if ($row['id'] > 0) { $GLOBALS['id'] = $row['id']; $GLOBALS['name'] = $row['name']; return TRUE; } else { return FALSE; } } function databaseContainsUseridAdmin($userid) { include 'db.php'; try { $sql = 'SELECT COUNT(*) FROM user WHERE userid = :userid AND type = 2'; $s = $pdo->prepare($sql); $s->bindValue(':userid', $userid); $s->execute(); } catch (PDOException $e) { echo 'Error searching for userid. ' . $e; exit(); } $row = $s->fetch(); if ($row[0] > 0) { return TRUE; } else { return FALSE; } } db.php: <?php try { $pdo = new PDO('mysql:host=localhost;dbname=****', '****', '****'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdo->exec('SET NAMES "utf8"'); } catch (PDOException $e) { echo 'Unable to connect to database server. ' . $e; exit(); } Using echo statements, I can only determine that $id is set (to the number 5, in my case) after I call the function userIsLoggedIn. At no other point before this (including inside the userIsLoggedIn function in access.php) is $id defined. This makes no sense to me. Can anyone shine some light on the issue? Thanks.
  8. EDIT: Thanks for the reply gizmola! I figured it out Didn't think it would be so simple. Well, this seems to do exactly what I want: SELECT student.name AS sName, user.name AS uName FROM student_user INNER JOIN student ON student.id = student_user.student_id INNER JOIN user ON user.id = student_user.user_id; Problem solved. Usually things don't work out this fast for me ...
  9. Hello, I have three tables, like so: user: id | name ----------- 1 Bob 2 Jim 3 Alex ... student: id | name ----------- 1 Sarah 2 Hans 3 Kim ... user_student <--- this is an intermediate table linking users to students user_id | student_id ------------------------- 1 2 1 3 2 1 ... Is there an easy way (i.e. using a single query) to display all user_student links, but instead of showing: 1 2 1 3 2 1 ... It would show: Bob Hans Bob Kim Jim Sarah ... I found this related thread, but I'm looking for something a little more basic. Thanks!
  10. Hello, I have the following code: $sql = 'SELECT id, name, research_interests FROM students ORDER BY name ASC'; $s = $pdo->prepare($sql); $s->execute(); This code works with no problems. But when I change it to use bindValue(), it fails. $sql = 'SELECT id, name, research_interests FROM students ORDER BY name :order'; $s = $pdo->prepare($sql); $s->bindValue(':order', 'ASC'); $s->execute(); What could be causing the problem? This is the error I receive: exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1' in /var/www/grad/support/myMeetings.php:146 Stack trace: #0 /var/www/grad/support/myMeetings.php(146): PDO->prepare('SELECT id, name...') #1 /var/www/grad/controllers/myMeetings.php(73): listStudents() #2 /var/www/grad/index.php(36): include('/var/www/grad/c...') #3 {main} Thanks, Twin
  11. Thanks for the replies guys! PHP/PDO is using mysql client libraries, and not mysqlnd. I tried parse_ini_file('/etc/mysql/my.cnf') but my.cnf is not a valid configuration file.
  12. So, I came accross the following: http://php.net/manual/en/ref.pdo-mysql.php PDO::MYSQL_ATTR_READ_DEFAULT_FILE Is it possible to use this constant to read the my.cnf file?
  13. Hello, The title says it all: MySQL is not using the hostname, user, and password that I have specified in my MySQL configuration file (my.cnf). I have a my.cnf file located at /etc/mysql and a .my.cnf file at ~/. The file in my ~ direcotry contains the following: [client] host = localhost user = root password = ***** In my php script, I have the following: try { $pdo = new PDO('mysql:dbname=grad'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->exec('SET NAMES "utf8"'); } catch (PDOException $e) { echo $e; exit(); } When I run mysql --print-defaults I can see that MySQL has indeed loaded the host, user and password from my config file, but it does not seem to take effect as my php script gives me the following error: exception 'PDOException' with message 'SQLSTATE[42000] [1044] Access denied for user ''@'localhost' to database 'grad'' in /var/www/ ... MySQL version: 5.5.29-0ubuntu0.12.04.1 Web server: Apache 2.2.22 (Ubuntu) Any suggestions? Thanks!
×
×
  • 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.