Jump to content

Drezard

Members
  • Posts

    244
  • Joined

  • Last visited

    Never

Everything posted by Drezard

  1. Hello, Im trying to make a news script, except im currently stuck. I need someone to finish this off for me (or atleast guide me) Now, I connect to the MySQL Database on another script that uses this class, so dont worry about that. Okay heres the script: <?php class news_report { function news_new() { echo "<form action='' method='post'> Subject: <input type='text' size='200' name='subject'><br> News: <input type='text'size='10000' name='news'><br> <input type='submit' name='submit'> </form>"; if (isset($_POST['news'])) { $subject = $_POST['subject']; $news = $_POST['news']; $date = date("Ymdgi"); $time = date("g:i A D d F"); $query ="INSERT INTO news_all (date, subject, news, time) VALUES ('$date', '$subject', '$news', '$time')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo "News Added"; } } function news_all() { $query = "SELECT date, subject, news, time FROM news_all ORDER BY date"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) { while($row = mysql_fetch_row($result)) { } } } } ?> Now, I want it too output the first 5 bits of news. In order of the date. So the most recent ones first. I also want it to display the subject at the top, then the time, then the news so.... Subject Time News Subject Time News Like that. Now, how would i do that?
  2. Hello, Im making a HTML Form that i want the different fields to have a maximum and a minimum value. How do I do this: <form action='' method='post'> User name: <input type='text' name='user'> Password: <input type='password' name='pass'> <input type='submit' name='submit'> </form> Now I want the text box for the user field to be at least 150 letters so the text box is much larger. What would be the code for it? - Cheers, Daniel
  3. Sorry under $user in the database is Peter and $priv is 1 in the the database
  4. Okay, SQL has been a great friend of mine for a while. But now its just being a ..... So heres my code for my WHOLE function: if (!isset($_SESSION['userinfo'])) { echo "You are not logged in <br>"; } if (isset($_SESSION['userinfo'])) { $this->check_userid(); if ($this->logged == 1) { $userinfo = $_SESSION['userinfo']; $pieces = explode(" ", $userinfo); $user = $pieces[0]; $query = "SELECT * FROM user_ids WHERE user='$user' AND priv=0"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); if ($count == 1) { echo "<form action='' method='post'> <select name='race'> <option value='human'>Human - Your Average Human</option> <option value='shadow'>Shadow - Dark and Mysterious</option> <option value='vampire'>Vampire - Half-Human Half-Bat</option> </select> <br> <select name='class'> <option value='hunt'>Hunter</option> <option value='defend'>Defender</option> <option value='rogue'>Rogue</option> <option value='war'>Warlock</option> <option value='priest'>Priest</option> </select> <br> <input type='submit' name='submit'> </form>"; if (isset($_POST['race'])) { $race = $_POST['race']; $class = $_POST['class']; $str = 10; $dex = 10; $con = 10; $mag = 10; if ($race == "human") { $str - 4; $dex + 2; $mag + 5; $con - 3; } if ($race == "shadow") { $mag - 3; $con - 3; $dex + 3; $str + 3; } if ($race == "vampire") { $mag - 5; $str - 3; $con + 5; $dex + 3; } if ($class == "hunt") { $mag - 5; $str + 5; } if ($class == "defend") { $mag - 5; $con + 4; $str + 1; } if ($class == "rogue") { $con - 5; $dex + 3; $str + 2; } if ($class == "war") { $con - 5; $str - 5; $mag + 7; $dex + 3; } if ($class == "priest") { $con + 3; $str - 5; $dex - 5; $mag + 7; } $query ="INSERT INTO user_chars (user, race, class, str, dex, con, mag) VALUES ('$user', '$race', '$class', '$str', '$dex', '$con', '$mag')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query ="INSERT INTO user_ids (priv) VALUES ('2')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo "Character Created"; } } if ($count == 0) { echo "You have already created"; } } } if ($this->logged == 0) { echo "Incorrect Session"; } } Now, In my Database in user_ids under user is the name Peter and under priv is 1. Now whenever I try and run this script it always says char already created. What have i done wrong.
  5. so when do i use ` and when do i not use them?
  6. Okay heres my code: $query = "SELECT * FROM user_chars WHERE user='$user' AND `character`='1'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); Now in my Database under character it is 1. The only problem is when i run this script, count = 0. The variable $user contains the right stuff what else could it be? - Cheers, Daniel
  7. Swaping Char to the word Character.... Gives me this error: For this bit of code: $character = 0; $query ="INSERT INTO user_ids (user, pass, priv) VALUES ('$user', '$pass', '$priv')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_profiles (user, email) VALUES ('$user', '$email')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_chars (user, 'character') VALUES ('$user', '$character')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); What else could it be? - Cheers, Daniel
  8. Hello, These queries all before it work though... Except the last one: $query ="INSERT INTO user_ids (user, pass, priv) VALUES ('$user', '$pass', '$priv')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_profiles (user, email) VALUES ('$user', '$email')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_chars (user, char) VALUES ('$user', '$char')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); Thats why i dont understand it...
  9. Doing a check now. 0 is what i want for char. Just telling you that user wasn't the problem. And the column are all varchars. What else could be wrong? - Cheers, Daniel
  10. Hello, I have got this error twice with 2 different queries... Here is the error: And here is the code that corresponds to it: $char = 0; $query = "INSERT INTO user_chars (user, char) VALUES ('$user', '$char')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); the variable $user is set elsewhere and it definitly sets it (using echo i found that out). What else could be wrong? Cheers, Daniel
  11. Drezard

    Rand()

    Hello, I want to use the rand() function for a variable. So like: Code: <?php number = rand(); ?> But it gives me these errors: Quote: Whats wrong or how can i do this? - Cheers, Daniel
  12. Hello. Now, I need a little help with some form validation. I have this form here: <form action='' method='post'> Username: <input type='text' name='user'><br> Password: <input type='password' name='pass'><br> <input type='submit' name='submit'> </form> So theres my HTML form. Can someone please give me an example using this code on how to validate a form. Now, I just want it that if the user doesn't enter any thing into either input boxes it throws back an error at the top of the page then shows the form again. - Cheers, Daniel
  13. Hello, Here is my code for my classes document: [CODE] <?php error_reporting(E_ALL); /* * Mysql.php * * This class is meant to do most of the interaction with the MySQL database. * * Last updated: Jan 8, 2007. */ /* * This class contains these functions: * * Connect(); * View_page($page); * * * */ class mysql { var $dbuser = "0"; var $dbpass = 0; var $dbhost = "0"; var $db = "0"; var $page = NULL; var $connection = NULL; function Connect() { $this->connection = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass) or die ("Unable to connect!");         mysql_select_db($this->db) or die ("Unable to select database!"); } function view_page() { $page = $this->page; $sql = "SELECT '$page' FROM pages"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); if (mysql_num_rows($result) > 0) {     while($row = mysql_fetch_row($result)) {       echo $row[0];     } } else {   echo "Page can not be found"; } } } ?> [/CODE] Now, when i run this code it outputs: [QUOTE] Notice: Undefined variable: query in /home/wintersw/public_html/classes/mysql.php on line 47 Notice: Undefined variable: query in /home/wintersw/public_html/classes/mysql.php on line 47 Error in query: . Query was empty [/QUOTE] And hes the code for my script that runs the class: [CODE] <?php include('classes/mysql.php'); $myclass = new mysql; $myclass->connect(); $myclass->page = "about"; $myclass->view_page(); ?> [/CODE] Now what have I done wrong? - Cheers, Daniel
  14. Yea, then it gives me the an error. Headers already sent. - Cheers, daniel
  15. Hello, Here is my code for my class.php file. This file contains all of my functions to be used inside my PHP applications. I want to set a cookie there with the $user and $pass function where the comment is: [QUOTE] // set cookie here [/QUOTE] Here my code: [CODE] <?php /* * Mysql.php * * This class is meant to do most of the interaction with the MySQL database. * * Last updated: December 16, 2006. */ /* * This class contains these functions: * * connect() * */ include ('constants.php'); /* * MySQLDB contains most of the functions to interact with the MySQL database. */ class MySQLDB { var $connection; // Contains all the connection to MySQL information function connect() { // Connects to the MySQL database $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error()); mysql_select_db(DB_NAME, $this->connection) or die(mysql_error()); } /* * This function is used to check the username and password from a form against the one in the database. * * This function is used at login. * */ function check_username($user, $pass) { $query = "SELECT * FROM user_ids WHERE user='$user' AND pass='$pass'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); if ($count == 1) { return 0; // set cookie here } if ($count == 0) { return 1; } } /* * This function is used to check the username and password from a cookie or session against the one in the database. * * This function is used on every page to see if a user is logged in. */ function check_userid($userid, $pass) { $query = "SELECT * FROM user_ids WHERE userid='$userid' AND pass='$pass'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); if ($count == 1) { return 0; } if ($count == 0) { return 1; } } /* * This function contains the form to get the user to login. * * This function is used when you want to login */ function user_form() { if (!isset($_SESSION['userinfo'])) { echo "Please login:<br><br>"; echo "<form action='' method='post'>     Username: <input type='text' name='user'><br>     Password: <input type='password' name='pass'><br>     <input type='submit' name='submit'>     </form>"; $user = $_POST['user']; $pass = $_POST['pass']; $this->check_username($user, $pass); } if (isset($_SESSION['userinfo'])) { echo "You are already logged in"; } } } ?> [/CODE] How do I set a cookie there? - Cheers, Daniel
  16. Hello, I'm trying to make a membership system and I want to use cookies but I cant get it too work. I was wondering whether any one could show me there code for there membership systems. - Cheers, Daniel
  17. Just use the date() function its easier. You just have to use this code... [CODE] <?php // Using some of thorpes code...   $host="localhost";   $database = "DateDB"; // Ive changed your db name.   $dusername = "root" ;   $dbpassword = "";   mysql_connect($host,$database,$dusername,$dpassword) ;   mysql_select_db($database) or die( "Could not select DateDB database !" ) ;   $date = Date("d/m/Y");   $query = "INSERT INTO DateDB useradded VALUES ('$date')"; // Ive changed your field name.   if (mysql_query($query))     echo "success";   } else {     echo mysql_error();   } ?> [/CODE] Use that code. Thanks, Daniel
  18. I cant believe i missed that. Thanks, Daniel
  19. Hello, Ive got this error: [QUOTE] Parse error: parse error, unexpected ';' in C:\Program Files\xampp\htdocs\test\classes.php on line 29 [/QUOTE] I dont get it. Cause on line 29 is a function with a ';' at the end and the line above it is an IF statement. Heres line 27 - 31: [CODE] if (!isset($_SESSION['userinfo'] {       $this->user_login_box(); } [/CODE] Whats wrong with this? - Cheers, Daniel
  20. hello, I have a problem with this line of code: [CODE] $query = "INSERT INTO profiles (user, email, name, add, sub, postcode, state) VALUES ('$user', '$email', '$name', '$add', '$sub', '$post', '$state')"; [/CODE] It comes up with this error when i try and execute that query: [QUOTE] Error in query: INSERT INTO profiles (user, email, name, add, sub, postcode, state) VALUES ('drezard54', 'adgadf', 'adfgdafgadgadg', 'adgadf', 'adgadf', 'adgadf', 'adgadf').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 'add, sub, postcode, state) VALUES ('drezard54', 'adgadf', 'adfgdafgadgadg', 'adg' at line 1 [/QUOTE] I dont understand whats wrong with my query? - Cheers, Daniel
  21. So you just want to store a user's name and email that they've submitted on a page in a file? - Cheers, Daniel
  22. The double quotes worked. Thanks for the help. - Cheers, Daniel
  23. PHP Also has a time function called Date(); You can use this with a number of parameters. An example would be, if you want to get the Day, Month and Year. You would use Date("d/m/Y"); You can check this function up on php.net or this link : http://www.w3schools.com/php/php_date.asp Cheers, Daniel
  24. Hello, Heres my class with all my functions: [CODE] <?php session_start(); error_reporting(E_ALL); class web { var $connection = NULL; var $login = NULL; var $dbhost = "localhost";   var $dbuser = "test";   var $dbpass = "test";   var $db = "sellyourownhome"; function connect() { $this->connection = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass) or die ("Unable to connect!");         mysql_select_db($this->db) or die ("Unable to select database!"); } function close_connect() { mysql_close($this->connection); } function check_user() {       if (!isset($_SESSION['userinfo'])) {         $this->login_box();           }         if (isset($_SESSION['userinfo'])) {         $this->connect(); $userinformation = explode(" ", $_SESSION['userinfo']); $user = $userinformation[0]; $pass = $userinformation[1]; echo $user; echo $pass; $query = "SELECT * FROM users WHERE user='$user' AND pass='$pass'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); if ($count == 1) { $this->login = 1; } if ($count == 0) { echo "ERROR: Session has corrupted. Please logout and relogin"; $this->login = 0; }       }     } function add_user() {     if (isset($SESSION['userinfo'])) {           $this->check_user();         }         if (!isset($_SESSION['userinfo'])) {       $this->connect(); if (!isset($_POST['user'])) { echo "<form action='' method='post'>     Username: <input type='text' name='user'>     Password: <input type='password' name='pass'> Comfirm Password: <input type='password' name='pass2'> Email: <input type='text' name='email'> Comfirm Email: <input type='text' name='email2'>     <input type='submit' name='submit'>     </form>"; } if (isset($_POST['user'])) { $user = $_POST['user']; $pass = $_POST['pass']; $pass2 = $_POST['pass2']; $email = $_POST['email']; $email2 = $_POST['email2']; $priv = $_POST['priv']; if ($pass == $pass2) { if ($email == $email2) {               $query = "SELECT * FROM users WHERE user='$user' AND pass='$pass'";         $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());         $count = mysql_num_rows($result);         if ($count == 1) {           echo "Username already created";           }         if ($count == 0) {           $query = "INSERT INTO users (user, pass, priv) VALUES ('$user', '$pass', '2')";     $result = mysql_query($query) or die ("Error in query: $query.");     $query = "INSERT INTO profiles (user, email) VALUES ('$user', '$email')";     $result = mysql_query($query) or die ("Error in query: $query.");     echo "Acount sucessfully created";         } } else { echo "Emails dont match"; } } else { echo "Passwords dont match"; }     }               }             } function login_box() { $this->connect(); if (isset($_SESSION['userinfo'])) { $this->check_user(); $userinformation = explode(" ", $_SESSION['userinfo']); $user = $userinformation[0]; echo 'Welcome, $user'; } if (!isset($_SESSION['userinfo']) && !isset($_POST['user'])) { echo "<form action='' method='post'>     Username: <input type='text' name='user'>     Password: <input type='password' name='pass'>     <input type='submit' name='submit'>     </form>"; } if (!isset($_SESSION['userinfo']) && isset($_POST['user'])) { $user = $_POST['user']; $pass = $_POST['pass']; $query = "SELECT * FROM users WHERE user='$user' AND pass='$pass'"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $count = mysql_num_rows($result); if ($count == 1) { $_SESSION['userinfo'] = '$user $pass'; echo "Sucessfully logged in"; } if ($count == 0) { echo "Username or password are incorrect."; } } } function logout() { if (!isset($_SESSION['userinfo'])) { echo "You have to be logged in to view this."; } if (isset($_SESSION['userinfo'])) { session_destroy(); echo "You have sucessfully logged out"; } }   } ?> [/CODE] Alright so with the function check_user(); it doesnt explode the session properly. The variables $user and $pass are empty. Whats wrong with it? The whole code is there so you should be able to see that the function login_box sets the session and i want check_user to read it but it doesnt. - Cheers, Daniel
×
×
  • 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.