Website Help

vampist

Fully Optimized
You are going to need some PHP.
You also SHOULD and would be easier to do with Mysql.

Now Php is obviously a server side scripting language, Mysql is a database manager that Php can talk to.

I would recommend you do some research on these two subjects before trying this. It could end up being VERY bad.. (spam possibly even viruses).
 

j031

~~~~~~~~
Use a Captcha, and you should be fine. It wont be too hard to code - You could even just have it email the message/"shout" to you?
 

tom-knox

Fully Optimized
If it were me i'd just hack up a really simple guestbook script. Change the normal screen to just the input form (sans the previous entries). Then put the entries on another page.

I'll do it for you tomorrow if you still need it.
 

ssc456

Fully Optimized
hey guys,

i did what was suggested and i did some research into PHP and ive come up with the below.

Code:
 <form action="result.php" method="post"> 
	     Name: <input name="name" type="text" /> 
		 <br>
		 Message: <input name="message" type="text" /> 
		<input type="submit" value="Send Shout" />
now thats working ok and on the results page i have.

Code:
<?php
$name = $_POST['name'];
$message = $_POST['message'];

echo "Name: ". $name . " <br />";
echo "Message: ". $message . ".<br />";

?>
no problems working fine but i noticed when i click send shout it takes me to the next page to view the shout, is it possible to have it loop back to the same page so that the shout is only viewable by me on the results page.

also if someone sends a shout straight after someone else i will not have chance to read the first one so is there a way to make it a long list of shouts?

i think i do need a modded guest book script but again im still starting out any pre made scripts i could play with would be great :)

thanks for the help
 

Daeva

In Runtime
you would need a database system to "queue" the orders or at the very least a text file.

Here is an example of a database script you could use on your results page:
PHP:
<?
  $conn = mysql_connect("localhost","userName","password");
  if(!$conn) { // mysql_connect returns false on failure
    die("Could not connect to database.  Reason: " . mysql_error() ."\n");
  } else {
    mysql_select_db("databaseName"$conn);
    $query = "INSERT INTO [shoutBox] ([shoutBox_Name],[shoutBox_Message]) VALUES (";
    $name = addslashes($_POST['name']);
    $message = addslashes($_POST['message']);
    $query .= "'" . $name . "','" . $message . "')";
    $rowsAffected = 0;
    mysql_query($query,$conn);
    $rowsAffected = mysql_affected_rows($conn);
    if ($rowsAffected > 0) {
      echo "Your shout was successfully added!\n";
    } else {
      echo "Your shout was not added.\n";
    } // end if/else
  } // end if/else
?>
Breif explanation:

mysql_connect: connects you to a pre-existing (you'll have to create it and I can show you how) instance of mySQL server with a specified username and password. For security purposes, you should create a seperate login for this database that doesn't have access to the rest of your databases. Also, this login should not have delete permission.

if this succeeds we continue, otherwise we print the reason why and exit.

if we continue, we then select the database we are going to be performing these tasks on.

After this, we build a "query" statement that is the insert statement used on the shoutBox (needs to be created) table (I can help you with this also if you need it).

Once our statement is done, we execute it and find out if it was successful (by calling mysql_affected_rows). If it was successful we will have had at least 1 row changed, otherwise it failed.

This also eliminates your need to re-direct if you don't want them to see it.

Hope this helps.
 

ssc456

Fully Optimized
ok people im progressing.

i have my shoutbox sorted.

http://mkradio.co.nr

but at the moment i can only view the shouts by going to my phpmyadmin and looking at the database i need some help pulling the info from the database and displaying it
 

Daeva

In Runtime
ok, I see you're running apache. You should (if you don't already) have a password protected directory. To do this, create a new folder in your website. Then create a file called .htaccess
in this file, place the following code:
Code:
AuthUserFile C:/WAMP/www/news/includes/.htpasswd
AuthName "Access to Admin"
AuthType Basic

require valid-user
Where the AuthUserFile is the location to a password file named .htpasswd
AuthName is the title of the box that comes up.

Then, create a file called .htpasswd in the same directory and add a line for every user-account you want to use in this form:

UserName : password
Username2 : password2
etc...
without the spaces between the colon. (smileys show up if I don't put the spaces.)

Once you have that setup on the (private) folder (NOTE* putting this in the root of your website will deny people access to view the site).

in your private folder, create a new php file and connect to the database as before.

establish the connection, call mysql_select_db on your database, then set query equal to something like this:
Code:
SELECT * FROM [myTableName]
where myTableName is the name of your table.

Next, you have to "iterate" through the result set.

Code:
$rs = mysql_query($query,$conn);
//loop through all the rows returned by the query

while ($row = mysql_fetch_array($rs,MYSQL_ASSOC)) {
  echo $row['column_name'] . "<br />\n";
} // end while

format that however you want, probably in a table.  $row is an associative array with a number of elements equal to the number of columns you have in your database table.

NOTE: Make sure to close your connection to your database!
[code]
mysql_close($conn);
Hope that helps.
 
Top