Thread: Mysql with MyRage(-Quit) [Commenting!]

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 Mysql with MyRage(-Quit) [Commenting!] 
    Banned
    Join Date
    Apr 2011
    Age
    24
    Posts
    1,363
    Thanks given
    370
    Thanks received
    184
    Rep Power
    0
    Yes, this is sloppy. I'm not gonna release something nice just for you to leach. I also do not know if this works. It was put together in this post, Sooo... :P

    Ok, so we gonna do some MySQL Tutorials on dis tread, kay?

    Bold - Indicates Field that needs to be changed!

    Anyways, To start. Connecting to a database

    Code:
    Config.php
    Code:
    <?php
         mysql_connect('localhost', 'username', 'password') or die(mysql_error);
         mysql_select_db('Database_Name') or die(mysql_error);
    ?>
    What this does;
    - Connects to the server name (localhost) in this case
    - Logs in to phpmyadmin basicly
    - Selects a database that we will edit/modify
    - If anything goes wrong, it will display an error

    Okay, moving on. Creating a table in mysql...

    Open up PHPMyAdmin, and generate/run this code;

    Code:
    CREATE TABLE IF NOT EXISTS `comments` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `username` varchar(255) NOT NULL,
      `text` text NOT NULL,
      `ip` varchar(255) NOT NULL,
      `time` int(11) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
    What this does;

    - Creates a row named ID. This will tell the engine how to display the code later on
    - Creates a row named Username
    - Creates a row named text where we will process the given text
    - Creates a row named IP Which will log the users Ip
    - Creates a row named time that logs the time that the post was... posted.

    Now, we will need to start programming our actual code. So, to do this, start by making a simple form.

    Code:
    <?php $postname = 'Set name here.'; ?>
    <h3>Comment [Post: <?php echo $postname; ?>]</h3>
    <form action="" method="post">
    Name: <input type="text" name="username"><br>
    Comment: <textarea name="comment" maxlength="200" stlye="max-width:580px;min-width:580px;min-height:80px;max-height:80px;"></textarea><br>
    <button>Comment!</button>
    What this does;
    - Sets a postname which you will have to edit
    - Sets two text fields, name and comment
    - Sets a button that when clicked will display a certain function, which we will add later

    Now, we need to make the actual PHP Part, so add this code to the page in which you made the Html part in...

    Code:
    <?php
    
    include('config.php');
    
    if(!$comment) {
       die('You need to fill in the comment field!');
       return false;
    }
    if($name == "") {
       $name = 'Anonymous';
    }
    
    $comment = $_POST[comment];
    $name = $_POST[name];
    
    if(isset($comment)) {
       if(strlen($comment)<="5") {
          		echo "<error><div style='box-shadow: rgba(0, 0, 0, 0.3) 0px 1px 4px, inset #ED5151 0px 1px 0px;border-radius:5px;padding:5px;border:1px solid red;background:#F01111;display:inline-block;color:white;'>You must enter a message more then 5 characters long!</div><br></error>";
       } else {
       mysql_query("INSERT INTO comments (username, text, ip, time)VALUES('".$name."', '".comment."', '".$_SERVER[REMOTE_ADDR]."', '".time()."')");
    }
    }
    ?>
    What this does;
    - If the name field is blank, it sets the name to Anonymous
    - If the comment field is empty, it quits the operation
    - If everything is right, it procedes
    - If the comment field is less then 5 letters, it stops and gives an error message
    - If this all goes right, then it enters all the necessary data into the database

    Now, we need to make a field that actually displays the messages! So, in the same file, create the following code

    Code:
    <?php
    
    $commentsfetch = mysql_query("SELECT * FROM comments ORDER by id DESC LIMIT 15");
    while($row = mysql_fetch_array($commentsfetch)) {
    ?>
    [<?php  echo date("d-M-Y H:i:s",$row[time]);  ?>] 
    <?php if(empty($row[username])) {
    echo "Anonymous"; }
    ?>
    <br>
    <?php echo $row[text]; ?>
    What this does;
    - Fetches the code and displays 15 of the comments [Editable by you!]
    - Echoes the date of the post in []'s, and then displays the username
    - If the username spot is still blank, it sets it as anonymous
    - It then echoes the text after a enter code basicly

    Finishing off...

    Well, we finished the actually inside code, but we need something to filter the comments!

    Code:
    <?php
    	$inapp = array(
    	"fuck",
    	"nigger",
    	"cunt",
    	"bitch",
    	"ass",
    	"asshole",
    	"fuckhead",
    	"xat",
            ".com"
    	);
    	if(check_array($row[text], $inapp) {
    		str_replace($row[text], "<div style="color: red;"><b>- Sorry, this message contains inapropriate content! -</b></div>");
    	}
    ?>
    What this does;
    - Checks if the row named text includes any inappropriate text
    - If it does, then it replaces it with a inappropriate message

    Note: You may need to change the $row[text], $inapp around to make it work!

    All credits go to me, rage-quit.
    Reply With Quote  
     

  2. #2  
    Banned
    Join Date
    Apr 2011
    Age
    24
    Posts
    1,363
    Thanks given
    370
    Thanks received
    184
    Rep Power
    0
    Fixed 5 or 6 errors that I noticed.
    Reply With Quote  
     

  3. #3  
    Registered Member
    'Hunter's Avatar
    Join Date
    Sep 2008
    Posts
    739
    Thanks given
    12
    Thanks received
    7
    Rep Power
    160
    Nice post.
    ~ Hunter


    Reply With Quote  
     

  4. #4  
    Community Veteran

    Songoty's Avatar
    Join Date
    Dec 2007
    Posts
    2,734
    Thanks given
    205
    Thanks received
    1,019
    Rep Power
    2326
    Code:
    e:
    
    <?php
         mysql_connect('localhost', 'username', 'password') or die(mysql_error);
         mysql_select_db('Database_Name') or die(mysql_error);
    ?>
    - Logs in to phpmyadmin basicly
    you have no idea what you're talking about, do you.

    also your programming style is horrendous.

    I advise you to go read up more on SQL and then come back. Also you do not need to break out of the quotation marks when using double (") quotation marks to use a variable.
    Reply With Quote  
     

  5. #5  
    Banned
    Join Date
    Apr 2011
    Age
    24
    Posts
    1,363
    Thanks given
    370
    Thanks received
    184
    Rep Power
    0
    Quote Originally Posted by Songoty View Post
    Code:
    e:
    
    <?php
         mysql_connect('localhost', 'username', 'password') or die(mysql_error);
         mysql_select_db('Database_Name') or die(mysql_error);
    ?>


    you have no idea what you're talking about, do you.

    also your programming style is horrendous.

    I advise you to go read up more on SQL and then come back. Also you do not need to break out of the quotation marks when using double (") quotation marks to use a variable.
    I know, I know, and I know. This clearly said it's 'Sloppy' for a reason. I posted this because why would I post some shit that someones gonna leach thats nice? ALSO, Before hating, I hope you realize, that this does log you into phpmyadmin. Hence the 'mysql_connect'. And I learned php, mysql, html, css, js, and all that shit on my own. Ask my friends, I don't use tutorials. And I know that you can use variables in ""'s... Ask zerak, I told him that too a couple days ago. I did it because I like how it looks better.
    Reply With Quote  
     

  6. #6  
    Banned
    Join Date
    Apr 2011
    Age
    24
    Posts
    1,363
    Thanks given
    370
    Thanks received
    184
    Rep Power
    0
    Quote Originally Posted by Songoty View Post
    Code:
    e:
    
    <?php
         mysql_connect('localhost', 'username', 'password') or die(mysql_error);
         mysql_select_db('Database_Name') or die(mysql_error);
    ?>


    you have no idea what you're talking about, do you.

    also your programming style is horrendous.

    I advise you to go read up more on SQL and then come back. Also you do not need to break out of the quotation marks when using double (") quotation marks to use a variable.
    And my programming style is neater. This is sloppy because I clearly said it was. I didn't space or line anything neatly or type anything neatly because this is a tutorial, not a leach and run shit thing.
    Reply With Quote  
     

  7. #7  
    Community Veteran

    Songoty's Avatar
    Join Date
    Dec 2007
    Posts
    2,734
    Thanks given
    205
    Thanks received
    1,019
    Rep Power
    2326
    Quote Originally Posted by Rage-Quit View Post
    I know, I know, and I know. This clearly said it's 'Sloppy' for a reason. I posted this because why would I post some shit that someones gonna leach thats nice? ALSO, Before hating, I hope you realize, that this does log you into phpmyadmin. Hence the 'mysql_connect'. And I learned php, mysql, html, css, js, and all that shit on my own. Ask my friends, I don't use tutorials. And I know that you can use variables in ""'s... Ask zerak, I told him that too a couple days ago. I did it because I like how it looks better.
    Don't post rubbish that is sloppy. No one is going to leech this, this is basic SQL.

    No, it does not log you into phpmyadmin. Do you know what phpmyadmin is? It's a user interface to handle administration of a SQL database.

    mysql_connect function has nothing to do with phpmyadmin. What mysql_connect does is exactly what its name describes: it connects to a SQL server.

    That's great you learned it on your on, so did most people. That doesn't make you a good programmer.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Freezia's Avatar
    Join Date
    Feb 2011
    Posts
    5,537
    Thanks given
    1,136
    Thanks received
    750
    Rep Power
    1259
    Your SQL could use some work but thanks for attempting to teach... I say attempting because if someone was to look at this post and learn they would never become good at php you have to start at the basics and the basics isn't good these basics are amateur but at least you tried.


    Click above to get the cheapest WEB HOSTING options! We also provide VIRTUAL PRIVATE SERVERS (VPS)! Now equipped with DDOS Protection.


    Reply With Quote  
     

  9. #9  
    Banned
    Join Date
    Dec 2011
    Age
    24
    Posts
    231
    Thanks given
    14
    Thanks received
    49
    Rep Power
    0
    Jesus.

    3/10?

    Sorry I wouldn't use it.
    Reply With Quote  
     

  10. #10  
    Banned
    Join Date
    Apr 2011
    Age
    24
    Posts
    1,363
    Thanks given
    370
    Thanks received
    184
    Rep Power
    0
    Quote Originally Posted by Songoty View Post
    Don't post rubbish that is sloppy. No one is going to leech this, this is basic SQL.

    No, it does not log you into phpmyadmin. Do you know what phpmyadmin is? It's a user interface to handle administration of a SQL database.

    mysql_connect function has nothing to do with phpmyadmin. What mysql_connect does is exactly what its name describes: it connects to a SQL server.

    That's great you learned it on your on, so did most people. That doesn't make you a good programmer.
    My point is so that people can look at this and have a general idea, and not leach it, GEEZ, HOW MANY TIMES DO I HAVE TO REPEAT IT?

    @Freezia; I have a video channel on youtube that has 100+ tutorials...

    @Mac Miller: Reasons please?
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Re-adding mysql to non-mysql dementhium?
    By Coruption in forum Help
    Replies: 1
    Last Post: 01-25-2012, 09:53 PM
  2. Commenting Debate
    By Slawth Baws in forum Spam
    Replies: 18
    Last Post: 01-01-2012, 07:02 AM
  3. MySQL: Cannot Find MySQL Driver
    By Glass O Wine in forum Help
    Replies: 3
    Last Post: 05-02-2010, 11:30 AM
  4. [MySQL]MySQL Intergration By Mikelmao [DELTA]
    By mikelmao in forum Tutorials
    Replies: 16
    Last Post: 12-02-2009, 10:06 AM
  5. Question? MySQL or Non-MySQL
    By Shivers in forum Help
    Replies: 19
    Last Post: 11-29-2009, 06:53 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •