Jump to content

Thaikhan

Members
  • Posts

    14
  • Joined

  • Last visited

Thaikhan's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hey guys, I've built an AJAX/PHP user chat box within public_html/chat/... and what I would like to do is reference public_html/chat/index.php within the home page of my website and have it function as it does when you navigate to the index file itself. I've tried: include '../chat/index.php'; It will display the contents of the index file but it doesn't reference it's style sheet or function. What is the best way of going about doing something like this? Thank you in advance!!
  2. So I'm trying to create an AJAX chat system. I've gotten to the point where I should be able to print_r(new Chat->fetchMessages()); the dummy data I've put into the db table but for some reason it's not coming up. I've searched for any errors in the code and looked at the error logs on the server and haven't come up with anything. Please have a look. Thank you in advance!! index.php: <?php error_reporting(E_ALL ^ E_NOTICE); session_start(); $userid = $_SESSION['userid']; $username = $_SESSION['username']; echo $userid; echo "|"; echo $username; echo "|"; require 'core/classes/Core.php'; require 'core/classes/Chat.php'; $chat = new Chat(); print_r($chat->fetchMessages()); echo mysql_error(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>AJAX Chat</title> <link href="./style.css" rel="stylesheet" type="text/css" /> </head> <body> <!-- Chat Start --> <div class="chat"> <div class="messages"> </div> <textarea class="entry" placeholder="Type here and hit Enter. Use Shift + Enter for a new line."></textarea> </div> <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script src="./chat.js"></script> </body> </html> Core.php and Chat.php within ./core/classes/: Core.php: <?php class Core { protected $db, $result; private $rows; public function __construct() { $this->db = new mysqli('localhost', 'root', 'db_password', 'db_name'); } public function query($sql) { $this->result = $this->db->query($sql); } public function rows() { for ($x = 1; $x <= $this->db->affected_rows; $x++) { $this->rows[] = $this->result->fetch_assoc(); } return $this->rows; } } Chat.php: <?php class Chat extends Core { public function fetchMessages() { $this->query("SELECT `chat`.`message`, `users`.`username`, `users`.`id` FROM `chat` JOIN `users` ON `chat.`user_id` = `users`.`id` ORDER BY `chat`.`timestamp` DESC"); return $this->rows(); } public function throwMessages($user_id, $message) { //insert into db } } Let me know if any other information would be helpful. Thank you!!!
  3. Thank you mac_gyver. I thought the server logs were giving me everything but I guess I was wrong. Thanks so much for your help!
  4. The script below will echo checked or unchecked accordingly, so it's working, but I don't understand why it's not echoing 0 or 1 for var $fn. if ( $_POST['registerbtn'] ) { $getuser = $_POST['user']; $getemail = $_POST['email']; $getpass = $_POST['pass']; $getretypepass = $_POST['retypepass']; if (isset($_POST['fn'])) { $fn == 1; echo $fn; echo "Checked"; echo mysql_error(); exit(); } else { $fn == 0; echo $fn; echo "Unchecked"; echo mysql_error(); exit(); }
  5. There's no mysql_error and the browser isn't coming up with anything. Neither is the server log.
  6. My problem is that it's not setting the variable. Any ideas? if ( $_POST['registerbtn'] ) { $getuser = $_POST['user']; $getemail = $_POST['email']; $getpass = $_POST['pass']; $getretypepass = $_POST['retypepass']; if (isset($_POST['fn'])) { $fn == 1; } else { $fn == 0; } echo $fn; exit(); Nothing is being echoed...
  7. Hey guys, I'm struggling to find why my checkbox isn't posting as set. I would really appreciate it if someone could tell me what I'm doing wrong. Here's the form: $form = "<form action='./register.php' method='post'> <table> <tr> <td></td> <td><font color='red'>$errormsg</font></td> </tr> <tr> <td>Username:</td> <td><input type='text' name='user' value='$getuser' /></td> </tr> <tr> <td>Email:</td> <td><input type='text' name='email' value='$getemail' /></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='pass' value='' /></td> </tr> <tr> <td>Retype Password:</td> <td><input type='password' name='retypepass' value='' /></td> </tr> <tr> <td>Receive Forum Notifications:</td> <td><input type='checkbox' name='fn' value='1' /></td> </tr> <tr> <td></td> <td><input type='submit' name='registerbtn' value='Register' /></td> </tr> </table> </form>"; And here's the beginning of the page: <?php error_reporting(E_ALL ^ E_NOTICE); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Member System - Register</title> <link href="./style.css" rel="stylesheet" type="text/css" /> </head> <body> <?php if ( $_POST['registerbtn'] ) { $getuser = $_POST['user']; $getemail = $_POST['email']; $getpass = $_POST['pass']; $getretypepass = $_POST['retypepass']; if (isset($_POST['fn'])) { echo "checked"; exit(); } else echo "unchecked"; exit(); Thanks so much!!
  8. I found the issue. I was missing a y in my $query.
  9. I'm very new to the programming scene. Could you please explain how to do that Barrikor?
  10. Hello guys, I'm trying to make a login system linked to a mySQL database and below is what I have so far. The problem I'm having is when I try to submit both a username and password, I think the database query is failing and it leads to a blank page. Any ideas? Thanks you. Any help will be greatly appreciated. Here's the page I'm talking about: http://aerithea.com/login/login.php <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Member System - Login</title> </head> <body> <?php $form = "<form action='./login.php' method='post'> <table> <tr> <td>Username:</td> <td><input type='text' name='user' /></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password' /></td> </tr> <tr> <td></td> <td><input type='submit' name='loginbtn' value='Login' /></td> </tr> </table> </form>"; if ($_POST['loginbtn']) { $user = $_POST['user']; $password = $_POST['password']; if ($user) { if ($password) { require("connect.php"); $password = md5(md5("q`wkIa4".$password."qwe;lnm")); //make sure login info correct $query = msql_query("SELECT * FROM users WHERE username='$user'"); $numrows = mysql_num_rows($query); if ($numrows == 1) { $row = mysql_fetch_assoc($query); $dbid = $row['id']; $dbuser = $row['username']; $dbpass = $row['password']; $dbactive = $row['active']; if($password == $dbpass) { if($dbactive == 1) { //set session info $_SESSION['userid'] = $dbid; $_SESSION['username'] = $dbuser; echo "You have been logged in as <b>$dbuser</b>. <a href='./member.php'>Click here</a> to go to the member page."; } else echo "You must activate your account to login. $form"; } else echo "You did not enter the correct password. $form"; } else echo "The username you entered was not found. $form"; mysql_close(); } else echo "You must enter your password. $form"; } else echo "You must enter your username. $form"; } else echo $form; ?> </body> </html>
  11. Thank you kicken. It was a simple fix and I just wasn't seeing it. I appreciate your help.
  12. Hey guys, I'm new to the whole programming scene and am trying to setup a website. The domain is aerithea.com and I'm trying to link the logo on the top left to this php file below but it's not coming up. The anchor seems to be correct but I can't seem to figure out why it's not working. Any help would be greatly appreciated <?php session_start(); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Member System - Login</title> </head> <body> <?php $form = "<form action='./login.php' method='post'> <table> <tr> <td>Username:</td> <td><input type='text' name='user' /></td> </tr> <tr> <td>Password:</td> <td><input type='password' name='password' /></td> </tr> <tr> <td></td> <td><input type='submit' name='loginbtn' value='Login' /></td> </tr> </table> </form>"; if ($_POST['loginbtn']) { $user = $_POST['user'] $password = $_POST['password'] if ($user) { if ($password) { echo "$user - $password <hr/> $form"; } else echo "You must enter your password. $form"; } else echo "You must enter your username. $form"; } else echo $form; ?> </body> </html>
×
×
  • 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.