Jump to content

Pastulio

Members
  • Posts

    85
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Pastulio's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It might not be 100% compatible with my code, but it makes sense to me, so thanks a lot . Didn't know they had to be the same "instance".
  2. Yes but I was not aware that I had to run it there and then because my page will only need to connect once generally, so is it absolutely required to run one class simultaneously with the other when using Inheritance?
  3. Well it's just a variable for the other class as you can see in my code
  4. I am not, but I can't figure out what I'm doing wrong here =(
  5. Ok so this is what I did database_classes.php <?php // Class db_connect class db_connect { // MySQL Config var $db_host; // MySQL host (usually 'localhost') var $db_username; // MySQL username var $db_password; // MySQL password var $db_name; // MySQL database name var $db_connection; // MySQL database connection variable var $db_select; // MySQL database selection variable function connect () { // Connect to the MySQL server $this -> db_connection = mysql_connect ($this -> db_host, $this -> db_username, $this -> db_password); // Test the MySQL connection if (!$this -> db_connection) { return false; } else { return true; } } // END db_connect function select () { $this -> db_select = mysql_select_db ($this -> database, $this -> db_connection); // Test the MySQL selection if (!$this -> db_select) { return false; } else { return true; } } } // Class db_create class db_create extends db_connect { var $error; // MySQL config var $database_name; // MySQL database name function check_Existence () { $result = mysql_list_dbs ($this -> db_connection); if ($result){ while ($list = mysql_fetch_array($result)) { $database_list[] = $list['database']; } if (!in_array($this -> database_name, $database_list)) { return true; } } } function create_Database () { $query = "CREATE DATABASE `" . $this -> database_name . "`"; $result = mysql_query ($query); if (!$result) { return false; } else { return true; } } // create_Database function create () { if ($this -> check_Existence ()){ if ($this -> create_Database ()){ $error = "Database Created sucessfully."; } else { $error = "Database Could not be created."; } } else { $error = "The database you want to create already exists."; } return $error; } } ?> And here is where I actually want to use my objects: db_create_test.php <?php include ('classes/database_classes.php'); $db_connect = new db_connect (); $db_connect -> db_host = 'localhost'; $db_connect -> db_username = 'root'; $db_connect -> db_password = ''; $db_connect -> connect(); $db_create = new db_create (); // Call the class $db_create -> database_name = 'Pastulio'; // Set the MySQL to be created database name $result = $db_create -> create(); echo $result; ?> Now the error I'm getting back is This would indicate that the $this ->db_connection isn't being properly declared in my extended class this is line 47: $result = mysql_list_dbs ($this -> db_connection); Any further help would be great thanks
  6. Cool thanks man
  7. sure but I gotta go i'll check my error tomorrow somewhere cya
  8. I don't think I'll be here tomorrow lol upload this as doit.php <?php //including the database connection include('config.php'); //getting everything that has been submitted $name=mysql_real_escape_string(strip_tags($_POST['name'])); $mail=mysql_real_escape_string(strip_tags($_POST['mail'])); $message=mysql_real_escape_string(strip_tags($_POST['message'])); $submit=$_POST['submit']; //get the current time with php date() function //note that the server time will be recorded //more info about all functions - http://php.net $time=date("m/d/y - g:i a"); //get the ip. Note that this wont see through proxies $ip=$_SERVER['REMOTE_ADDR']; //just some basic error checking which //checks if name,e-mail and message //hasnt been left blank or with default text if (($name!=="") || ($name!=="Name") || ($mail!=="") || ($mail!=="E-mail") || ($message!=="") || ($message!=="Your text")) { //inserts data into the database $sql = "INSERT INTO shoutbox (id, name, mail, message, time, ip) VALUES ('NULL', '$name', '$mail', '$message', '$time', '$ip')"; mysql_query($sql) or die(mysql_error()); $query = "SELECT * FROM `shout_user_log` WHERE `ip` = '$ip'"; $result = mysql_query ($query); $num_rows = mysql_num_rows ($result); if ($num_rows > 0) { $query = "DELETE * FROM `shout_user_log` WHERE `ip` = '$ip'"; mysql_query ($query); } $query = "INSERT INTO `shout_user_log` (`id`, `username`, `email`, `ip`) VALUES ('', '$name', '$mail', '$ip')"; mysql_query ($query); //sends the user back to the form header("Location:".$_SERVER['HTTP_REFERER']); } else{ header("Location:".$_SERVER['HTTP_REFERER']); } ?> Now the name and E-mail should be remembered
  9. Don't have either <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Shoutbox</title> </head> <body> <?php include 'shouts.php'; $query = "SELECT * FROM `shout_user_log` WHERE `ip` = '$ip'"; $result = mysql_query ($query); $user_info = mysql_fetch_array ($result); if (!$user_info['id']){ $name = "Name"; $email = "E-mail"; } else { $name = $user_info['username']; $email = $user_info['email']; } ?> <form method="post" action="doit.php"> <input type='text' name='name' value='<?php echo $name; ?>' onfocus='this.value=""'><br> <input type='text' name='mail' value='<?php echo $email; ?>' onfocus='this.value=""'><br> <textarea name='message' onfocus='this.value=""' rows='3' cols='20'>Your Text Here</textarea> <br> <input type='submit' value='submit' name='submit'> </form> </body> </html> try altering it to that
  10. I do, tell me when you altered "form.php"
  11. this is your Form.php, it should not yet have been altered
  12. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Shoutbox</title> </head> <body> <?php include 'shouts.php'; $query = "SELECT * FROM `shout_user_log` WHERE `ip` = '$ip'"; $result = mysql_query ($query); $user_info = mysql_fetch_array ($result); if (!$user_info[id]){ $name = "Name"; $email = "E-mail"; } else { $name = $user_info['username']; $email = $user_info['email']; } ?> <form method="post" action="doit.php"> <input type='text' name='name' value='<?php echo $name; ?>' onfocus='this.value=""'><br> <input type='text' name='mail' value='<?php echo $email; ?>' onfocus='this.value=""'><br> <textarea name='message' onfocus='this.value=""' rows='3' cols='20'>Your Text Here</textarea> <br> <input type='submit' value='submit' name='submit'> </form> </body> </html> Change your Form.php to this
  13. That's because I'm not done
  14. change your doit.php with this <?php //including the database connection include('config.php'); //getting everything that has been submitted $name=mysql_real_escape_string(strip_tags($_POST['name'])); $mail=mysql_real_escape_string(strip_tags($_POST['mail'])); $message=mysql_real_escape_string(strip_tags($_POST['message'])); $submit=$_POST['submit']; //get the current time with php date() function //note that the server time will be recorded //more info about all functions - http://php.net $time=date("m/d/y - g:i a"); //get the ip. Note that this wont see through proxies $ip=$_SERVER['REMOTE_ADDR']; //just some basic error checking which //checks if name,e-mail and message //hasnt been left blank or with default text if (($name!=="") || ($name!=="Name") || ($mail!=="") || ($mail!=="E-mail") || ($message!=="") || ($message!=="Your text")) { //inserts data into the database $sql = "INSERT INTO shoutbox (id, name, mail, message, time, ip) VALUES ('NULL', '$name', '$mail', '$message', '$time', '$ip')"; mysql_query($sql) or die(mysql_error()); $query = "SELECT * FROM `shout_user_log` WHERE `ip` = '$ip'"; $result = mysql_query ($query); $num_rows = mysql_num_rows ($result); if ($num_rows > 0) { $query = "DELETE * FROM `shout_user_log` WHERE `ip` = '$ip'"; mysql_query ($query); } $query = "INSERT INTO `shout_user_log` (`id`, `username`, `email`, `ip`) VALUES "; mysql_query ($query); //sends the user back to the form header("Location:".$_SERVER['HTTP_REFERER']); } else{ header("Location:".$_SERVER['HTTP_REFERER']); } ?> Updated version Now give me your current version of "SHOUT.PHP"
  15. Hold up, I accidentally changed the code back to not include the time
×
×
  • 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.