Help - Search - Members - Calendar
Full Version: Please Help
Zymic Webmaster Forums > Zymic Free Web Hosting > Databases & MySQL
genie19
hi my names tony i am very new to all this. I am trying to make a shoutbox for my website. this is very important because the website is a radio station and the shoutbox is a way for the listeners to interact with the dj's. I already have an existing shoutbox that was just a script i had to embedd into my webpage but the trouble is we have no way to stop abusive users and spammers as all the shouts appear instantly in the same page from all users. Here is my website my website. I have found a solution this is to create a shoutbox that uses a mysql database and php scripting to enter information into the database and then retrieve it via a website. This would mean that all users (listeners) can write a comment into a submit form but then only we the administrators (or dj) could see it. examples of this can be found at example website
basically in that example the shouts are submitted with the submit button they then go into the databse and then the website has a seperate php page that pulls the information from the database and displays it into a table with the ability to delete shouts (data) as well the page also auto refreshes so that new data is displayed automatically. i have tried doing it myself but keep getting errors and i am unsure exactly how to set up the databases and tables to do this. my freind has given me the zip containing all the script files which he then modified for his own shoutbox which is here shoutbox script so i was wondering if neone knew how to do this already and could help me in doing it or if someone could look at the existing files that my freind modified and help me modify them so that it will work for me. or if neone can come up with a simpler way to acomplish this. thanks for your time i hope you can help.
wozzym
wow that wuz alot to read. id suggest having the shoutbox messages be sent to a regular shoutbox with different profile settings for admins. this would mean that only admins could see it.
genie19
QUOTE(wozzym @ Mar 25 2008, 10:54 PM) *
wow that wuz alot to read. id suggest having the shoutbox messages be sent to a regular shoutbox with different profile settings for admins. this would mean that only admins could see it.


sorry i thought the more information i gave the easier it wud be for someone to help lol. thanks for replying but i want it exactly like the one in the example webpage (http://www.ukgsoldiers.com/listen.php#menu) where the customers only see the submit form. and then we can only see the information. in simple i need a submit form that enters listeners name and listeners message into a database and then a php scripted page that pulls that information from the database and displays it in table form with the ability to delete information and where the page automatically refreshes to display new information as it is entered. thanks
wozzym
more information is good smile.gif i get what you want. but different profile settings could solve that problem probably quicker and simpler..
uncled1023
lol, that is easy to do. ill make you up a code tonight.
uncled1023
ok, here is my finished code. This only works with a user system of some sorts.... and has to have a database in mysql. so here it it.
You can put it anywhere you want the form to be. But remember to change the action="/shoutbox.php" near the bottom of the code at the start of the input form, or else it wont send the info to the top of the page. and remember to put a copy of the require(db_connect.php); ABOVE the <head> tag.

You will need to make a table called shoutbox and have 2 variables in it. username, and message. if you decide to change any of those, remember to change it in the code below.


CODE
<?php
require 'db_connect.php'; //this is the file that connects to the mysql database, so change to fit your files.


        $username = $_POST['username'];

        $message = $_POST['message'];

        $error = '0';
$row = mysql_query ("SELECT * FROM members"); //the "members" is the table that your admin user variable is in.
       $myrow = mysql_fetch_array($row);
        
$admin = $myrow['username']; //the "username" is the name of the user variable in the table "members".  all it is doing is getting all the usernames out of the member table and storing them as $admin.

if($admin == "admin") //the "admin" is the actual name of the user that you want to be able to view the shouts.

            {
            
            $query = "SELECT username, message FROM shoutbox"; //this is getting the sender(username) and the message from the shoutbox table.
        $sqlshouts = mysql_query($query);
        
        
        if(!$sqlshouts)
            {
            ?>
            
            <p><?php print '$query: '.$query.mysql_error();?></p>
            <?php
            }
        
      
          
        elseif (!mysql_num_rows($sqlshouts) )
            {
            ?>
            <center><p><b>There are no Shouts.</b></p></center>
            <?php
            }
        
        

        else
            {
            
            ?>
            
            <table width="80%">
            
              
            <?php
          
            while($shouts = mysql_fetch_array($sqlshouts))
                {
              
                $username = $shouts['username'];
                $message = $shouts['message'];
                
                
                ?>

                <center>
                 <tr>
                <td width="50px" valign="top"><p><b><u>Sender:<?php echo $sender; ?></u></b></p></td>  
                </tr>
                <tr>
                <td width="50px" valign="top"><p><b><u>Shout:</u></b></p></td>
                </tr>
                <tr>
                <td width="100px" valign="top"><p><?php echo $message; ?></p><br><br></td>
                </tr>
                </center>
                <?php
            }
            ?>
            </table>
          
            

          

            <?php
            }        
}
       else  //this tells the page to show the shout box input table when the person viewing the page isnt logged in as admin.
       {

            

        if(!$username AND !$message)

            {

            ?>

            <p><b>Make a Shout</b></p>

            <br>

            <?php

            }

        

        //Since this form was partially filled out we need to return an error message

        else

            {

            if (!$username)

                {

                $error = 'You must enter a your name!';

                }

            

            

            if (!$message)

                {

                $error = 'You must enter a shout';

                }

            

            //If the variable error is not set to zero, we have a problem and should show the error message

            if($error != '0')

                {

                echo "<p>$error</p><br>";

                }

            

            //There are no errors so far which means the form is completely filled out    

            else

                {                    

                            //And not we stick the message in the database with all the correct information

                            mysql_query("INSERT INTO shoutbox (username, message) VALUES('$username', '$message')") or die (mysql_error());
                            

                        //Let the user know everything went ok.

                        echo "<p><b>You have successfully posted your Shout!</b></p><br>";

                        }

    

                

                }

            

      
            

    

            //Here's the form for the input

            ?>
            <center>
            <form name="send" method="post" action="/shoutbox.php"> <?php //the /shoutbox.php is going to be the same as whatever you name this page.
            ?>
          
              Your Name:
                <input name="username" type="text" id="username" value="<?php echo $username; ?>">      

               <br><br>

              Your Shout:

                <textarea name="message" type="text" id="message" value="" cols="30" rows="5"></textarea>

               <br>

                <input type="submit" name="Submit" value="Submit">

              

            </center>

            </form>

            <?php

            }

    ?>
wozzym
heh nice uncled wink.gif
genie19
QUOTE(uncled1023 @ Mar 27 2008, 07:33 AM) *
ok, here is my finished code. This only works with a user system of some sorts.... and has to have a database in mysql. so here it it.
You can put it anywhere you want the form to be. But remember to change the action="/shoutbox.php" near the bottom of the code at the start of the input form, or else it wont send the info to the top of the page. and remember to put a copy of the require(db_connect.php); ABOVE the <head> tag.

You will need to make a table called shoutbox and have 2 variables in it. username, and message. if you decide to change any of those, remember to change it in the code below.
CODE
<?php
require 'db_connect.php'; //this is the file that connects to the mysql database, so change to fit your files.
        $username = $_POST['username'];

        $message = $_POST['message'];

        $error = '0';
$row = mysql_query ("SELECT * FROM members"); //the "members" is the table that your admin user variable is in.
       $myrow = mysql_fetch_array($row);
        
$admin = $myrow['username']; //the "username" is the name of the user variable in the table "members".  all it is doing is getting all the usernames out of the member table and storing them as $admin.

if($admin == "admin") //the "admin" is the actual name of the user that you want to be able to view the shouts.

            {
            
            $query = "SELECT username, message FROM shoutbox"; //this is getting the sender(username) and the message from the shoutbox table.
        $sqlshouts = mysql_query($query);
        
        
        if(!$sqlshouts)
            {
            ?>
            
            <p><?php print '$query: '.$query.mysql_error();?></p>
            <?php
            }
        
      
          
        elseif (!mysql_num_rows($sqlshouts) )
            {
            ?>
            <center><p><b>There are no Shouts.</b></p></center>
            <?php
            }
        
        

        else
            {
            
            ?>
            
            <table width="80%">
            
              
            <?php
          
            while($shouts = mysql_fetch_array($sqlshouts))
                {
              
                $username = $shouts['username'];
                $message = $shouts['message'];
                
                
                ?>

                <center>
                 <tr>
                <td width="50px" valign="top"><p><b><u>Sender:<?php echo $sender; ?></u></b></p></td>  
                </tr>
                <tr>
                <td width="50px" valign="top"><p><b><u>Shout:</u></b></p></td>
                </tr>
                <tr>
                <td width="100px" valign="top"><p><?php echo $message; ?></p><br><br></td>
                </tr>
                </center>
                <?php
            }
            ?>
            </table>
          
            

          

            <?php
            }        
}
       else  //this tells the page to show the shout box input table when the person viewing the page isnt logged in as admin.
       {

            

        if(!$username AND !$message)

            {

            ?>

            <p><b>Make a Shout</b></p>

            <br>

            <?php

            }

        

        //Since this form was partially filled out we need to return an error message

        else

            {

            if (!$username)

                {

                $error = 'You must enter a your name!';

                }

            

            

            if (!$message)

                {

                $error = 'You must enter a shout';

                }

            

            //If the variable error is not set to zero, we have a problem and should show the error message

            if($error != '0')

                {

                echo "<p>$error</p><br>";

                }

            

            //There are no errors so far which means the form is completely filled out    

            else

                {                    

                            //And not we stick the message in the database with all the correct information

                            mysql_query("INSERT INTO shoutbox (username, message) VALUES('$username', '$message')") or die (mysql_error());
                            

                        //Let the user know everything went ok.

                        echo "<p><b>You have successfully posted your Shout!</b></p><br>";

                        }

    

                

                }

            

      
            

    

            //Here's the form for the input

            ?>
            <center>
            <form name="send" method="post" action="/shoutbox.php"> <?php //the /shoutbox.php is going to be the same as whatever you name this page.
            ?>
          
              Your Name:
                <input name="username" type="text" id="username" value="<?php echo $username; ?>">      

               <br><br>

              Your Shout:

                <textarea name="message" type="text" id="message" value="" cols="30" rows="5"></textarea>

               <br>

                <input type="submit" name="Submit" value="Submit">

              

            </center>

            </form>

            <?php

            }

    ?>



Hi thanks a lot for helping me but like i said i am a complete noob at coding and php scripts. i know how to set up the table so i will do that. do i also need another table with members in it like you said so i can have admin in there? Also what shud i name my database so this code will work ?
and i dont really understand this bit sorry

"You can put it anywhere you want the form to be. But remember to change the action="/shoutbox.php" near the bottom of the code at the start of the input form, or else it wont send the info to the top of the page. and remember to put a copy of the require(db_connect.php); ABOVE the <head> tag." how many pages do i need to make or do i put this whole script into one page? thanks again and hope to hear from you soon
Andrew
I prefer flatfile shoutboxes, ones that write to a file instead of a database. Here are a list of shoutboxes, I don't know if they are all flatfile or not, but there are a few good ones in there.
http://php.resourceindex.com/Complete_Scripts/Chat/Shoutbox/
genie19
QUOTE(genie19 @ Mar 28 2008, 06:24 PM) *
Hi thanks a lot for helping me but like i said i am a complete noob at coding and php scripts. i know how to set up the table so i will do that. do i also need another table with members in it like you said so i can have admin in there? Also what shud i name my database so this code will work ?
and i dont really understand this bit sorry

"You can put it anywhere you want the form to be. But remember to change the action="/shoutbox.php" near the bottom of the code at the start of the input form, or else it wont send the info to the top of the page. and remember to put a copy of the require(db_connect.php); ABOVE the <head> tag." how many pages do i need to make or do i put this whole script into one page? thanks again and hope to hear from you soon


hi just to let you know what i have tried. ok i have a database set up as genie19_bouncy inside i have 2 tables. the first is shoutbox which is set up as follows
Field Name Type Null Default Extra
username varchar(50) No
message varchar(50) No

second table is members which is set up as follows
Field Name Type Null Default Extra
Id int(11) No auto_increment primary key
name varchar(50) No

i then made a file called db_connect and used the following script (dont know if its right)

<html>
<head>
<title>Test PHP Page</title>
</head>

<body>
<?php

mysql_connect ("localhost", "MY USERNAME WAS HERE",
"MY PASSWROD WAS HEREl") or die ('I cannot connect to the
database because: ' . mysql_error());

mysql_select_db ("genie19_bouncy");

?>
</body>
</html>

i then made a new page called shoutbox.php and used the following script (trying to do what you said in this post)
<html>
<head>
<title>Test PHP Page</title>
</head>

<body>
<?php
require 'db_connect.php';
$username = $_POST['username'];

$message = $_POST['message'];

$error = '0';
$row = mysql_query ("SELECT * FROM members");
$myrow = mysql_fetch_array($row);
admin = $myrow['username'];
if($admin == "admin")

{

$query = "SELECT username, message FROM shoutbox";
$sqlshouts = mysql_query($query);
if(!$sqlshouts)
{
?>

<p><?php print '$query: '.$query.mysql_error();?></p>
<?php
}

else if (!mysql_num_rows($sqlshouts) )
{
?>
<center><p><b>There are no Shouts.</b></p></center>
<?php
}

else
{

?>

<table width="80%">


<?php

while($shouts = mysql_fetch_array($sqlshouts))
{

$username = $shouts['username'];
$message = $shouts['message'];


?>

<center>
<tr>
<td width="50px" valign="top"><p><b><u>Sender:<?php echo $sender; ?></u></b></p></td>
</tr>
<tr>
<td width="50px" valign="top"><p><b><u>Shout:</u></b></p></td>
</tr>
<tr>
<td width="100px" valign="top"><p><?php echo $message; ?></p><br><br></td>
</tr>
</center>
<?php
}
?>
</table>





<?php
}
}

else

{



if(!$username AND !$message)

{

?>

<p><b>Make a Shout</b></p>

<br>

<?php

}

else

{

if (!$username)

{

$error = 'You must enter a your name!';

}





if (!$message)

{

$error = 'You must enter a shout';

}

if($error != '0')

{

echo "<p>$error</p><br>";

}

else

{

mysql_query("INSERT INTO shoutbox (username, message) VALUES('$username', '$message')") or die (mysql_error());

echo "<p><b>You have successfully posted your Shout!</b></p><br>";

}





}

?>
<center>
<form name="send" method="post" action="/shoutbox.php"> <?php

Your Name:
<input name="username" type="text" id="username" value="<?php echo $username; ?>">

<br><br>

Your Shout:

<textarea name="message" type="text" id="message" value="" cols="30" rows="5"></textarea>

<br>

<input type="submit" name="Submit" value="Submit">



</center>

</form>

<?php

}

?>
</body>
</html>
I then uploaded both the shoutbox.php and the db_connect page but when i click on shoutbox.php to open in the webbrowser i just get an empty page the same happens when i click db_connect.

thanks for your time n help i hope you can figure out what im doing wrong.
uncled1023
QUOTE(genie19 @ Mar 28 2008, 06:24 PM) *
Hi thanks a lot for helping me but like i said i am a complete noob at coding and php scripts. i know how to set up the table so i will do that. do i also need another table with members in it like you said so i can have admin in there? Also what shud i name my database so this code will work ?
and i dont really understand this bit sorry

"You can put it anywhere you want the form to be. But remember to change the action="/shoutbox.php" near the bottom of the code at the start of the input form, or else it wont send the info to the top of the page. and remember to put a copy of the require(db_connect.php); ABOVE the <head> tag." how many pages do i need to make or do i put this whole script into one page? thanks again and hope to hear from you soon



ok, first thing, you want to put all that code into whatever page you want the shoutbox to be on. then, down near the bottom of the code, shange the action="/shoutbox.php" to the page you put the code on. then, on the same page you put all the code, put require(db_connect.php); at the VERY top of the page. now,

now for you question about the tables, you tables are set up right, but you need to have the "name" in your members table to be "username"
genie19
QUOTE(uncled1023 @ Mar 28 2008, 09:00 PM) *
ok, first thing, you want to put all that code into whatever page you want the shoutbox to be on. then, down near the bottom of the code, shange the action="/shoutbox.php" to the page you put the code on. then, on the same page you put all the code, put require(db_connect.php); at the VERY top of the page. now,

now for you question about the tables, you tables are set up right, but you need to have the "name" in your members table to be "username"


hi sorry thanks again for your help is there ne chance you could make the shoutbox more simple for me as i am having trouble. could you take out the admin member bit and just have it so that all the posts are visible but they are displayed on a webpage that only we are gonna know the address for (so noone else can view it) ive managed to make a form that submits name and comment to the database but im having trouble displaying the information i always end up with a blank page. thanks
wozzym
that would be alot easier with the profile settings. I dont know if thats wut uncled coded before but id suggest that.
uncled1023
ok, ill see what i can do, it should be easy. im busy tomorrow, but ill try thursday.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.