Click to See Complete Forum and Search --> : sql


lukezweb
12-06-2003, 11:20 AM
$dbh=mysql_connect ("localhost", "lukezweb_admin", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lukezweb_shouts");



is this correct to connect to my database on my host?

i just place it in my php code?

lukezweb
12-06-2003, 11:25 AM
Originally posted by lukezweb

$dbh=mysql_connect ("localhost", "lukezweb_admin", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lukezweb_shouts");



is this correct to connect to my database on my host?

i just place it in my php code?

i also have this now...

CREATE TABLE `shouts` (
`username` TEXT NOT NULL ,
`message` TEXT NOT NULL
);

in the sql file

how can i set a form of a text box and a textarea to set a new row to this ?? when you submit the form?

pyro
12-06-2003, 12:31 PM
Something like this...

$dbh=mysql_connect ("localhost", "lukezweb_admin", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lukezweb_shouts");
$sql = "INSERT INTO `shouts` (`username`, `message`) VALUES ('".$_POST['username']."', '".$_POST['message']."')";
mysql_query($sql);

Though when creating the table, you really should include a column named ID, like this:

CREATE TABLE `shouts` (
`id` int(11) NOT NULL auto_increment,
`username` TEXT NOT NULL ,
`message` TEXT NOT NULL
);

and then run have an SQL statement like this:

$sql = "INSERT INTO `shouts` (`id`, `username`, `message`) VALUES ('', '".$_POST['username']."', '".$_POST['message']."')";

lukezweb
12-06-2003, 12:33 PM
Originally posted by pyro
Something like this...

$dbh=mysql_connect ("localhost", "lukezweb_admin", "<PASSWORD HERE>") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lukezweb_shouts");
$sql = "INSERT INTO `shouts` (`username`, `message`) VALUES ('".$_POST['username']."', '".$_POST['message']."')";
mysql_query($sql);

Though when creating the table, you really should include a column named ID, like this:

CREATE TABLE `shouts` (
`id` int(11) NOT NULL auto_increment,
`username` TEXT NOT NULL ,
`message` TEXT NOT NULL
);

and then run have an SQL statement like this:

$sql = "INSERT INTO `shouts` (`id`, `username`, `message`) VALUES ('', '".$_POST['username']."', '".$_POST['message']."')";

uhuh i see
so whats the ID part for?

pyro
12-06-2003, 12:36 PM
The id (set to auto increment) is so you always have something unique in your rows -- a very good idea.

lukezweb
12-06-2003, 12:42 PM
Originally posted by pyro
The id (set to auto increment) is so you always have something unique in your rows -- a very good idea.

Heres my file.....


<?php
// MESSGAE BOX Version 1
// Made By Luke Dyson
// http://lukezweb.tk
$version = "0.1";
echo "<html>";
echo "<head>";
echo "<LINK REL='stylesheet' TYPE='text/css' HREF='style.css'>";
echo "<title>Message Box</title>";
$dbh=mysql_connect ("localhost", "lukezweb_admin", "admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lukezweb_shouts");
$sql = "INSERT INTO `shouts` (`username`, `message`) VALUES ('".$_POST['username']."', '".$_POST['message']."')";
mysql_query($sql);
?>
<script>
function add(tags){
document.getElementsByTagName('textarea')[0].innerHTML+= ""+tags+"";
}
function alert(message){
alert(""+message+"");
}
</script>

<?php
echo "</head>";
echo "<body style='margin: 0pt;'>";
echo "<center><form name=shout><table>";
echo "<tr><td bgcolor=#000099><div align=center><font class=text2>MessageBox</font></td></tr>";
echo "<tr><td>No Messages...<BR>This is Due To It Being Under-Consturction!<HR width=90%></td></tr>";
echo "<tr><td>Post A Message:</td></tr>";
echo "<tr><td>";
echo "<div align=center>[<a href=javascript:add('TEXT')>";
echo "B</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "I</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "U</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "<font style=' font-decoration: strikethrough;'>S</font></a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "G</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "S</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "<-</a>]";
echo "[<a href=javascript:add('[hr]')>";
echo "HR</a>]";
echo "[<a href=javascript:add('')>";
echo "WWW</a>]";
echo "[<a href=javascript:add('URL')>";
echo "IMG</a>]";
echo "[<a href=javascript:add('')>";
echo "@</a>]";
echo "</td></tr><tr><td><div align=center>
<a href=javascript:add(':-/')><img src=annoyed.gif></a>";
echo "<a href=javascript:add(':-[')><img src=bad.gif></a>";
echo "<a href=javascript:add(':@')><img src=blush.gif></a>";
echo "<a href=javascript:add(':D')><img src=cheesy.gif></a>";
echo "<a href=javascript:add('8)')><img src=cool.gif></a>";
echo "<a href=javascript:add('???')><img src=huh.gif></a>";
echo "<a href=javascript:add(':-)')><img src=kiss.gif></a>";
echo "<a href=javascript:add('::)')><img src=rolleyes.gif></a>";
echo "<a href=javascript:add(':(')><img src=sad.gif></a>";
echo "<a href=javascript:add(':O')><img src=shocked.gif></a>";
echo "<a href=javascript:add(':Z')><img src=smartass.gif></a>";
echo "<a href=javascript:add(':)')><img src=smiley.gif></a>";
echo "<a href=javascript:add(':P')><img src=tongue.gif></a>";
echo "<a href=javascript:add(';)')><img src=wink.gif></a>";
echo "</td></tr><tr><td><div align=center valign=middle>Name: <input type=text name=username width=200></td></tr><tr><td><div align=center><textarea name=message rows=12 cols=30 wrap=soft tabindex='1'></text></td></tr>";
echo "<tr><td><div align=center><input type=submit value=Shout tabindex='2' onMouseDown="alert(Test!)"><input type=reset value=Reset tabindex='3'></td></tr>";
echo "<tr><td><div align=center><a href=archive>Archive</a> | <a href=index.php?action=help>Help</a> | <a href=index.php?action=admin>Admin</a></td></tr>";
echo "<tr><td><HR width=90%></td></tr>";
echo "<tr><td><div align=center><a href=http://lukezweb.tk>MessageBox Hosted By Lukezweb</a><br><a href=index.php?action=wantyourown>Want Your Own MessageBox</A><br>Version $version</td></tr>";
echo "</table></form>";
?>

<?php
// SEPERATE PAGES CODING
$action = (isset($_GET['action'])) ? $_GET['action'] : "";
if ($action == "admin") {
echo "<p><table><tr><td colspan=2><font class=text1>Admin:</font></td></tr>";
echo "<tr><td><font class=text1>Username:</td><td><input type=text name=user value=admin></font></td></tr><tr><td>";
echo "<font class=text1>Password:</td><td><input type=password name=pass></font></td></tr>";
echo "<tr><td colspan=2><input type=submit value=Login></td></tr><tr><td colspan=2><a href=index.php>Back...</a></td></tr></table>";
} else if ($action == "help") {
echo "<p>
<table><tr><td>
<font class=text1>Frequently Asked Questions:</font>
</td></tr><tr><td>
<font class=text1>Q) How do i get one?<BR>A) This code is not released yet, but will be soon!</font>
</td></tr><tr><td>
<font class=text1></font>
</td></tr><tr><td>
<a href=index.php>Back...</a>
</td></tr></table>";
} else if ($action == "wantyourown") {
echo "<p>
<table><tr><td>
<font class=text1>Want Your Own Message Box?</font>
</td></tr><tr><td>
<font class=text1>Soon we will be offering you a chance to get your own!</font>
</td></tr><tr><td>
<font class=text1></font>
</td></tr><tr><td>
<a href=index.php>Back...</a>
</td></tr></table>";
} else {

}
echo "</center>";
echo "</body></html>";
?>



I get..... http://lukezweb.jetdownloads.co.uk/php/messagebox/index.php

lukezweb
12-06-2003, 01:17 PM
ah i fixed the error! yay but i um now need to know how to i make the submit button make the file send the data, and how i list the data up top? anyone can help

Thanks,
Luke

lukezweb
12-07-2003, 03:59 AM
Originally posted by lukezweb
ah i fixed the error! yay but i um now need to know how to i make the submit button make the file send the data, and how i list the data up top? anyone can help

Thanks,
Luke


anyone got any ideas?

pyro
12-07-2003, 09:06 AM
Could you rephrase your question? I'm not sure what you mean by the second part. For the first, just submit the form:

<form action="foo.php">
<p><input type="text" name="bar"><br>
<input type="submit" name="submit" value="submit"></p>
</form>

lukezweb
12-07-2003, 10:42 AM
Originally posted by pyro
Could you rephrase your question? I'm not sure what you mean by the second part. For the first, just submit the form:

<form action="foo.php">
<p><input type="text" name="bar"><br>
<input type="submit" name="submit" value="submit"></p>
</form>


sorry pyro like this.....

it uses the form above a few posts that has name of the user in a textbox and their messgae it then needs to submit that and ad it to the mysql table

i then need a code that above the send form displays all content of the mysql database in a basic table :)

hope thats better if not say and ill literally draw pictures, as a picture is worth a 1000 words :)

Thanks again,
Luke

lukezweb
12-07-2003, 12:30 PM
um right all i need is a code to display contetns of my database in a table ?

lukezweb
12-07-2003, 12:37 PM
Originally posted by lukezweb
um right all i need is a code to display contetns of my database in a table ?


really sorry for all the confusion.....
here is the code im using it doesnt appear to be working here...... http://lukezweb.jetdownloads.co.uk/php/messagebox/index.php


<?php
// MESSGAE BOX Version 1
// Made By Luke Dyson
// http://lukezweb.tk
$version = "0.1";
echo "<html>";
echo "<head>";
echo "<LINK REL='stylesheet' TYPE='text/css' HREF='style.css'>";
echo "<title>Message Box</title>";
$dbh=mysql_connect ("localhost", "lukezweb_admin", "admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lukezweb_shouts");
$sql = "INSERT INTO `shouts` (`username`, `message`) VALUES ('".$_POST['username']."', '".$_POST['message']."')";
mysql_query($sql);
?>
<script>
function add(tags){
document.getElementsByTagName('textarea')[0].innerHTML+= ""+tags+"";
}
function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="admin" && password=="admin") { window.location="index.php?action=admin2"; done=1; }
if (done==0) { alert("Incorrect Password!"); }
}
</script>

<?php
echo "</head>";
echo "<body style='margin: 0pt;'>";
echo "<center><form name=shout><table>";
echo "<tr><td bgcolor=#000099><div align=center><font class=text2>MessageBox</font></td></tr>";
echo "<tr><td>No Messages...<BR>This is Due To It Being Under-Consturction!<HR width=90%></td></tr>";
echo "<tr><td>Post A Message:</td></tr>";
echo "<tr><td>";
echo "<div align=center>[<a href=javascript:add('TEXT')>";
echo "B</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "I</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "U</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "<font style=' font-decoration: strikethrough;'>S</font></a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "G</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "S</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "<-</a>]";
echo "[<a href=javascript:add('[hr]')>";
echo "HR</a>]";
echo "[<a href=javascript:add('')>";
echo "WWW</a>]";
echo "[<a href=javascript:add('URL')>";
echo "IMG</a>]";
echo "[<a href=javascript:add('')>";
echo "@</a>]";
echo "</td></tr><tr><td><div align=center>
<a href=javascript:add(':-/')><img src=annoyed.gif></a>";
echo "<a href=javascript:add(':-[')><img src=bad.gif></a>";
echo "<a href=javascript:add(':@')><img src=blush.gif></a>";
echo "<a href=javascript:add(':D')><img src=cheesy.gif></a>";
echo "<a href=javascript:add('8)')><img src=cool.gif></a>";
echo "<a href=javascript:add('???')><img src=huh.gif></a>";
echo "<a href=javascript:add(':-)')><img src=kiss.gif></a>";
echo "<a href=javascript:add('::)')><img src=rolleyes.gif></a>";
echo "<a href=javascript:add(':(')><img src=sad.gif></a>";
echo "<a href=javascript:add(':O')><img src=shocked.gif></a>";
echo "<a href=javascript:add(':Z')><img src=smartass.gif></a>";
echo "<a href=javascript:add(':)')><img src=smiley.gif></a>";
echo "<a href=javascript:add(':P')><img src=tongue.gif></a>";
echo "<a href=javascript:add(';)')><img src=wink.gif></a>";
echo "</td></tr><tr><td><div align=center valign=middle>Name: <input type=text name=username width=200></td></tr><tr><td><div align=center><textarea name=message rows=12 cols=30 wrap=soft tabindex='1'></text></td></tr>";
echo "<tr><td><div align=center><input type=submit value=Shout tabindex='2'><input type=reset value=Reset tabindex='3'></td></tr>";
echo "<tr><td><div align=center><a href=archive>Archive</a> | <a href=index.php?action=help>Help</a> | <a href=index.php?action=admin>Admin</a></td></tr>";
echo "<tr><td><HR width=90%></td></tr>";
echo "<tr><td><div align=center><a href=http://lukezweb.tk>MessageBox Hosted By Lukezweb</a><br><a href=index.php?action=wantyourown>Want Your Own MessageBox</A><br>Version $version</td></tr>";
echo "</table></form>";
?>

<?php
// SEPERATE PAGES CODING
$action = (isset($_GET['action'])) ? $_GET['action'] : "";
if ($action == "admin") {
echo "<p><form name=login><table><tr><td colspan=2><font class=text1>Admin:</font></td></tr>";
echo "<tr><td><font class=text1>Username:</td><td><input type=text name=username value=admin></font></td></tr><tr><td>";
echo "<font class=text1>Password:</td><td><input type=password name=password></font></td></tr>";
echo "<tr><td colspan=2><input type=submit value=Login onClick='Login()'></td></tr><tr><td colspan=2><a href=index.php>Back...</a></td></tr></table></form>";
} else if ($action == "help") {
echo "<p>
<table width=250><tr><td>
<font class=text1>Frequently Asked Questions:</font>
</td></tr><tr><td>
<font class=text1>
Q) How do i get one?
<BR>A) This code is not released yet, but will be soon!</font>
<P>Q) How Do I Post?
<BR>A) Type in you name in the textbox, then in the big textbox enter your message, you can use the buttons above to change the look of your text etc. Or click a smilie to insert a smilie to express your emotion!
<P>Q) Can I Delete A Post?
<BR>A) Currently No
<P>Q) Can I Host It Myself?
<BR>A) Nope, as this code is owned by me you may not host it yourself.
<P>Q) I Own One How Can I Edit It?
<BR>A) Click the admin link and login! Then edit settings there :)
<P>Q) What Can I Expect In The Next Version?
<BR>A) Currently I have no plans on a second version but may soon!
</td></tr><tr><td>
<font class=text1></font>
</td></tr><tr><td>
<a href=index.php>Back...</a>
</td></tr></table>";
} else if ($action == "wantyourown") {
echo "<p>
<table><tr><td>
<font class=text1>Want Your Own Message Box?</font>
</td></tr><tr><td>
<font class=text1>Soon we will be offering you a chance to get your own!</font>
</td></tr><tr><td>
<font class=text1></font>
</td></tr><tr><td>
<a href=index.php>Back...</a>
</td></tr></table>";
} else {

}
echo "</center>";
echo "</body></html>";
?>



all i need is to fix the error and also a way to display all messages above :)

pyro
12-07-2003, 12:47 PM
You'll have to do a SELECT query - here's two simple ones:

# don't forget to connect...
$sql = "SELECT * FROM `tablename`"; # this will select everything from the table
$sql2 = "SELECT * FROM `tablename` WHERE `id = '1'"; # or this will select everything from the table where the row's id is equal to 1
$results = mysql_query($sql); # run the query
$data = mysql_fetch_array($results); # data is an array of the results...

lukezweb
12-07-2003, 12:50 PM
Originally posted by pyro
You'll have to do a SELECT query - here's two simple ones:

# don't forget to connect...
$sql = "SELECT * FROM `tablename`"; # this will select everything from the table
$sql2 = "SELECT * FROM `tablename` WHERE `id = '1'"; # or this will select everything from the table where the row's id is equal to 1
$results = mysql_query($sql); # run the query
$data = mysql_fetch_array($results); # data is an array of the results...



say i wanted to display this:

<TABLE>
<TR><TD>name here</TD></TR>
<TR.<TD>Messgae</TD></TR>
</TABLE>

how do i do it then?

also why isnt the code i psoted submititng the data the submit part what is that?

lukezweb
12-07-2003, 12:52 PM
Originally posted by lukezweb
say i wanted to display this:

<TABLE>
<TR><TD>name here</TD></TR>
<TR.<TD>Messgae</TD></TR>
</TABLE>

how do i do it then?

also why isnt the code i psoted submititng the data the submit part what is that?

is this it?

f($submit)
{
// Code here?
}

pyro
12-07-2003, 12:56 PM
Yes, close -- just do not use register_globals (http://www.webdevfaqs.com/php.php#globalvariables):

if ($_POST['submit'])) {
#code here
}

lukezweb
12-07-2003, 01:14 PM
Originally posted by pyro
Yes, close -- just do not use register_globals (http://www.webdevfaqs.com/php.php#globalvariables):

if ($_POST['submit'])) {
#code here
}

i was checking the database and when i looked.....
they weren't being added is there somehting ive missed......
<?php
// MESSGAE BOX Version 1
// Made By Luke Dyson
// http://lukezweb.tk
$version = "0.1";
echo "<html>";
echo "<head>";
echo "<LINK REL='stylesheet' TYPE='text/css' HREF='style.css'>";
echo "<title>Message Box</title>";
if ($_POST['submit']) {
$dbh=mysql_connect ("localhost", "lukezweb_admin", "admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lukezweb_shouts");
$sql = "INSERT INTO `shouts` (`username`, `message`) VALUES ('".$_POST['username']."', '".$_POST['message']."')";
mysql_query($sql);
}
?>

pyro
12-07-2003, 01:20 PM
Change this:

<form name=login>

to

<form name=\"login\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">;)

lukezweb
12-07-2003, 01:36 PM
Originally posted by pyro
Change this:

<form name=login>

to

<form name=\"login\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">;)


but this is fot the <form name=shout> ?is that the one i shoudl replace?

lukezweb
12-07-2003, 01:48 PM
also how do i display the contents ina table as i said befroe

thansk pyro btw

lukezweb
12-07-2003, 03:05 PM
Originally posted by lukezweb
also how do i display the contents ina table as i said befroe

thansk pyro btw


i tried this but it doesnt work :(


$query = "SELECT * FROM shouts";
$result = mysql_query($query)
or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<tr><td>$username</td></tr>";
echo "<tr><td>$message</td></tr>";
}

lukezweb
12-08-2003, 12:01 PM
pyro? any ideas? why?


Thanks Luke

pyro
12-08-2003, 12:31 PM
Try this:

$query = "SELECT * FROM shouts";
$result = mysql_query($query) or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row['username']."</td></tr>";
echo "<tr><td>".$row['message']."</td></tr>";
}

lukezweb
12-08-2003, 12:49 PM
Originally posted by pyro
Try this:

$query = "SELECT * FROM shouts";
$result = mysql_query($query) or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row['username']."</td></tr>";
echo "<tr><td>".$row['message']."</td></tr>";
}

still doesnt work lol:


<?php
// MESSGAE BOX Version 1
// Made By Luke Dyson
// http://lukezweb.tk
$version = "0.1";
echo "<html>";
echo "<head>";
?>
<script>
function add(tags){
document.getElementsByTagName('textarea')[0].innerHTML+= ""+tags+"";
}
function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="admin" && password=="admin") { window.location="index.php?action=admin2"; done=1; }
if (done==0) { alert("Incorrect Password!"); }
}
</script>
<?php
echo "<LINK REL='stylesheet' TYPE='text/css' HREF='style.css'>";
echo "<title>Message Box</title>";
if ($_POST['submit']) {
$dbh=mysql_connect ("localhost", "lukezweb_admin", "admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("lukezweb_shouts");
$sql = "INSERT INTO `shouts` (`username`, `message`) VALUES ('".$_POST['username']."', '".$_POST['message']."')";
mysql_query($sql);
}
echo "</head>";
echo "<body style='margin: 0pt;'>";
echo "<center><form name=\"shout\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"><table>";
echo "<tr><td bgcolor=#000099><div align=center><font class=text2>MessageBox</font></td></tr>";
echo "<tr><td>Messages:</td></tr>";
$query = "SELECT * FROM shouts";
$result = mysql_query($query) or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row['username']."</td></tr>";
echo "<tr><td>".$row['message']."</td></tr>";
}
echo "<tr><td><HR width=90%></td></tr>";
echo "<tr><td>Post A Message:</td></tr>";
echo "<tr><td>";
echo "<div align=center>[<a href=javascript:add('TEXT')>";
echo "B</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "I</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "U</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "<font style=' font-decoration: strikethrough;'>S</font></a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "G</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "S</a>]";
echo "[<a href=javascript:add('TEXT')>";
echo "<-</a>]";
echo "[<a href=javascript:add('[hr]')>";
echo "HR</a>]";
echo "[<a href=javascript:add('')>";
echo "WWW</a>]";
echo "[<a href=javascript:add('URL')>";
echo "IMG</a>]";
echo "[<a href=javascript:add('')>";
echo "@</a>]";
echo "</td></tr><tr><td><div align=center>
<a href=javascript:add(':-/')><img src=annoyed.gif></a>";
echo "<a href=javascript:add(':-[')><img src=bad.gif></a>";
echo "<a href=javascript:add(':@')><img src=blush.gif></a>";
echo "<a href=javascript:add(':D')><img src=cheesy.gif></a>";
echo "<a href=javascript:add('8)')><img src=cool.gif></a>";
echo "<a href=javascript:add('???')><img src=huh.gif></a>";
echo "<a href=javascript:add(':-)')><img src=kiss.gif></a>";
echo "<a href=javascript:add('::)')><img src=rolleyes.gif></a>";
echo "<a href=javascript:add(':(')><img src=sad.gif></a>";
echo "<a href=javascript:add(':O')><img src=shocked.gif></a>";
echo "<a href=javascript:add(':Z')><img src=smartass.gif></a>";
echo "<a href=javascript:add(':)')><img src=smiley.gif></a>";
echo "<a href=javascript:add(':P')><img src=tongue.gif></a>";
echo "<a href=javascript:add(';)')><img src=wink.gif></a>";
echo "</td></tr><tr><td><div align=center valign=middle>Name: <input type=text name=username width=200 tabindex=1></td></tr><tr><td><div align=center><textarea name=message rows=12 cols=30 wrap=soft tabindex='2'></text></td></tr>";
echo "<tr><td><div align=center><input type=submit name=submit value=Shout tabindex='3'><input type=reset value=Reset tabindex='4'></td></tr>";
echo "<tr><td><div align=center><a href=archive>Archive</a> | <a href=index.php?action=help>Help</a> | <a href=index.php?action=admin>Admin</a></td></tr>";
echo "<tr><td><HR width=90%></td></tr>";
echo "<tr><td><div align=center><a href=http://lukezweb.tk>MessageBox Hosted By Lukezweb</a><br><a href=index.php?action=wantyourown>Want Your Own MessageBox</A><br>Version $version</td></tr>";
echo "</table></form>";
?>

<?php
// SEPERATE PAGES CODING
$action = (isset($_GET['action'])) ? $_GET['action'] : "";
if ($action == "admin") {
echo "<p><form name=login><table><tr><td colspan=2><font class=text1>Admin:</font></td></tr>";
echo "<tr><td><font class=text1>Username:</td><td><input type=text name=username value=admin></font></td></tr><tr><td>";
echo "<font class=text1>Password:</td><td><input type=password name=password></font></td></tr>";
echo "<tr><td colspan=2><input type=submit value=Login onClick='Login()'></td></tr><tr><td colspan=2><a href=index.php>Back...</a></td></tr></table></form>";
} else if ($action == "help") {
echo "<p>
<table width=250><tr><td>
<font class=text1>Frequently Asked Questions:</font>
</td></tr><tr><td>
<font class=text1>
Q) How do i get one?
<BR>A) This code is not released yet, but will be soon!</font>
<P>Q) How Do I Post?
<BR>A) Type in you name in the textbox, then in the big textbox enter your message, you can use the buttons above to change the look of your text etc. Or click a smilie to insert a smilie to express your emotion!
<P>Q) Can I Delete A Post?
<BR>A) Currently No
<P>Q) Can I Host It Myself?
<BR>A) Nope, as this code is owned by me you may not host it yourself.
<P>Q) I Own One How Can I Edit It?
<BR>A) Click the admin link and login! Then edit settings there :)
<P>Q) What Can I Expect In The Next Version?
<BR>A) Currently I have no plans on a second version but may soon!
</td></tr><tr><td>
<font class=text1></font>
</td></tr><tr><td>
<a href=index.php>Back...</a>
</td></tr></table>";
} else if ($action == "wantyourown") {
echo "<p>
<table><tr><td>
<font class=text1>Want Your Own Message Box?</font>
</td></tr><tr><td>
<font class=text1>Soon we will be offering you a chance to get your own!</font>
</td></tr><tr><td>
<font class=text1></font>
</td></tr><tr><td>
<a href=index.php>Back...</a>
</td></tr></table>";
} else {

}
echo "</center>";
echo "</body></html>";
?>

pyro
12-08-2003, 01:01 PM
You'd best move the database connection outside the if conditional...

lukezweb
12-08-2003, 02:20 PM
Originally posted by pyro
You'd best move the database connection outside the if conditional...


thanks for all help :)

how can i reverse the order of the posts so newest go at top ? thansk again pyro:)

pyro
12-08-2003, 02:54 PM
You'll have to edit your database table to include a field to containt a timestamp. Then, you just insert a timestamp with each entry, and order it by that. Something like this, probably.

$query = "SELECT * FROM `shouts` ORDER BY `timestamp` DESC";

lukezweb
12-09-2003, 03:23 PM
firstly i get this error......


Parse error: parse error in /home/shoutbox/public_html/shout.php on line 17
(code at end of post)

and secondly how would i include this:


$post=$r['post'];
// html?
$post = str_replace("<", "<!--", $post);
$post = str_replace(">", "-->", $post);
$post = str_replace("","<b>",$post);
$post = str_replace("","</b>",$post);
$post = str_replace("","<i>",$post);
$post = str_replace("","</i>",$post);
$post = str_replace("","<u>",$post);
$post = str_replace("","</u>",$post);

$post = stripslashes($post);



into this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Remotely Hosted ShoutBoxes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="styles.css" rel="stylesheet" type="text/css">
<script>
function add(tags){
document.getElementsByTagName('textarea')[0].innerHTML+= ""+tags+"";
}
</script>
</head>
<?php
$version = "1.0";
$dbh=mysql_connect ("localhost", "shoutbox_admin", "admin") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("shoutbox_shouts");
f ($_POST['submit']) {
$sql = "INSERT INTO `shouts` (`username`, `message`) VALUES ('".$_POST['username']."', '".$_POST['message']."')";
mysql_query($sql);
}
echo "<body style='margin: 0pt;'>";
echo "<center><form name=\"shout\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"><table>";
echo "<tr><td bgcolor=#000099><div align=center><font class=text2>MessageBox</font></td></tr>";
echo "<tr><td>Messages:</td></tr>";
$query = "SELECT * FROM shouts";
$result = mysql_query($query) or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row['username']."</td></tr>";
echo "<tr><td>".$row['message']."</td></tr>";
}
echo "<tr><td><HR width=90%></td></tr>";
echo "<tr><td>Post A Message:</td></tr>";
echo "<tr><td>";
echo "<div align=center>[<a href=java script:add('TEXT')>";
echo "B</a>]";
echo "[<a href=java script:add('TEXT')>";
echo "I</a>]";
echo "[<a href=java script:add('TEXT')>";
echo "U</a>]";
echo "[<a href=java script:add('TEXT')>";
echo "<font style=' font-decoration: strikethrough;'>S</font></a>]";
echo "[<a href=java script:add('TEXT')>";
echo "G</a>]";
echo "[<a href=java script:add('TEXT')>";
echo "S</a>]";
echo "[<a href=java script:add('TEXT')>";
echo "<-</a>]";
echo "[<a href=java script:add('[hr]')>";
echo "HR</a>]";
echo "[<a href=java script:add('<a href="http://" target="_blank"></a>')>";
echo "WWW</a>]";
echo "[<a href=java script:add('URL')>";
echo "IMG</a>]";
echo "[<a href=java script:add('')>";
echo "@</a>]";
echo "</td></tr><tr><td><div align=center>
<a href=java script:add(':-/')><img src=annoyed.gif></a>";
echo "<a href=java script:add(':-[')><img src=bad.gif></a>";
echo "<a href=java script:add(':@')><img src=blush.gif></a>";
echo "<a href=java script:add('<img src="images/smilies/biggrin.gif" border="0" alt="">')><img src=cheesy.gif></a>";
echo "<a href=java script:add('8)')><img src=cool.gif></a>";
echo "<a href=java script:add('???')><img src=huh.gif></a>";
echo "<a href=java script:add(':-)')><img src=kiss.gif></a>";
echo "<a href=java script:add(':<img src="images/smilies/smile.gif" border="0" alt="">')><img src=rolleyes.gif></a>";
echo "<a href=java script:add('<img src="images/smilies/frown.gif" border="0" alt="">')><img src=sad.gif></a>";
echo "<a href=java script:add(':O')><img src=shocked.gif></a>";
echo "<a href=java script:add(':Z')><img src=smartass.gif></a>";
echo "<a href=java script:add('<img src="images/smilies/smile.gif" border="0" alt="">')><img src=smiley.gif></a>";
echo "<a href=java script:add(':P')><img src=tongue.gif></a>";
echo "<a href=java script:add('<img src="images/smilies/wink.gif" border="0" alt="">')><img src=wink.gif></a>";
echo "</td></tr><tr><td><div align=center valign=middle>Name: <input type=text name=username width=200 tabindex=1></td></tr><tr><td><div align=center><textarea name=message rows=12 cols=30 wrap=soft tabindex='2'></text></td></tr>";
echo "<tr><td><div align=center><input type=submit name=submit value=Shout tabindex='3'><input type=reset value=Reset tabindex='4'></td></tr>";
echo "<tr><td><div align=center><a href=archive>Archive</a> | <a href=index.php?action=help>Help</a> | <a href=index.php?action=admin>Admin</a></td></tr>";
echo "<tr><td><HR width=90%></td></tr>";
echo "<tr><td><div align=center><a href=http://lukezweb.tk>MessageBox Hosted By Lukezweb</a><br><a href=index.php?action=wantyourown>Want Your Own MessageBox</A><br>Version $version</td></tr>";
echo "</table></form>";
?>

<?php
// SEPERATE PAGES CODING
$action = (isset($_GET['action'])) ? $_GET['action'] : "";
if ($action == "admin") {
echo "<p><form name=login><table><tr><td colspan=2><font class=text1>Admin:</font></td></tr>";
echo "<tr><td><font class=text1>Username:</td><td><input type=text name=username value=admin></font></td></tr><tr><td>";
echo "<font class=text1>Password:</td><td><input type=password name=password></font></td></tr>";
echo "<tr><td colspan=2><input type=submit value=Login onClick='Login()'></td></tr><tr><td colspan=2><a href=index.php>Back...</a></td></tr></table></form>";
} else if ($action == "help") {
echo "<p>
<table width=250><tr><td>
<font class=text1>Frequently Asked Questions:</font>
</td></tr><tr><td>
<font class=text1>
Q) How do i get one?
<BR>A) This code is not released yet, but will be soon!</font>
<P>Q) How Do I Post?
<BR>A) Type in you name in the textbox, then in the big textbox enter your message, you can use the buttons above to change the look of your text etc. Or click a smilie to insert a smilie to express your emotion!
<P>Q) Can I Delete A Post?
<BR>A) Currently No
<P>Q) Can I Host It Myself?
<BR>A) Nope, as this code is owned by me you may not host it yourself.
<P>Q) I Own One How Can I Edit It?
<BR>A) Click the admin link and login! Then edit settings there <img src="images/smilies/smile.gif" border="0" alt="">
<P>Q) What Can I Expect In The Next Version?
<BR>A) Currently I have no plans on a second version but may soon!
</td></tr><tr><td>
<font class=text1></font>
</td></tr><tr><td>
<a href=index.php>Back...</a>
</td></tr></table>";
} else if ($action == "wantyourown") {
echo "<p>
<table><tr><td>
<font class=text1>Want Your Own Message Box?</font>
</td></tr><tr><td>
<font class=text1>Soon we will be offering you a chance to get your own!</font>
</td></tr><tr><td>
<font class=text1></font>
</td></tr><tr><td>
<a href=index.php>Back...</a>
</td></tr></table>";
} else {

}
echo "</center>";
echo "</body></html>";
?>