How to Make a Shoutbox With PHP and SQL

A shoutout box is a type of interface installed on the sidebar of a blog or website where users send messages that display real-time on the page. You can use a SQL database to store the messages so that each page displays the messages each time a user opens the page. Shoutout boxes let readers express thoughts without creating an account or commenting in blog comment sections.

Instructions

    • 1

      Open your PHP editor and the file you want to use to create the shoutout program interface.

    • 2

      Create the shoutout box using a simple HTML form. The following code creates the HTML form in the PHP page:

      <form action='storeinfo.php' method='post'>
      <input type="text" id="shoutout">
      </form>

      In this example, the "storeinfo.php" file stores the message in the SQL database. Replace this file with your own file name.

    • 3

      Open the PHP processing file to store the message in the database. Start the code with a connection to the database, like so:

      $connect = mysql_connect($host,$username,$password) ;
      mysql_select_db($database,$connect)

      Replace the host, username and password values with the values needed to connect to the server. Replace the database value with the name of your database.

    • 4

      Create the query to insert the message into the shoutout table:

      $query = "insert into shoutout (message) values ('" .$_POST['shoutout']. "')";
      mysql_query($query)

    • 5

      Redirect the reader back to the page from which the shoutout message was written, so the reader can continue to read your website content:

      http_redirect("article.php");

      Replace the PHP page with your site's content page.

Related Searches:

References

Comments

Related Ads

Featured