PDA

View Full Version : MySQL Database showing on a page.



jad9321
07-07-2006, 03:00 AM
Hello,
Is their anyway to make MySQL Database results show up in a web browser? As in the MySQL database tabel results will be shown on any page I want it to? The only option I want is for each seperate result to be deleted with a simple delete button. Anyone know of a script that can do this?

Thanks in advance,
Joe

djr33
07-07-2006, 12:06 PM
Clearly, you want this secure... so don't code it yourself.

The point of mysql is to use php (and other languages) to get the data then display, yes, as html.


however, in this case, you'd want to use a real manager for it, so it's secure, can do a bunch, etc.

I'd recomment myphpadmin, if you don't already have that. If you do, get used to it... it's a good way to navigate, once you get used to the controls.

jad9321
07-07-2006, 04:00 PM
Err... Dosen't need to be secure... I'm going to password protect it so its fine. And if its still not secure after the password than its not that big if a deal... Dosent matter to me if people can see it. I just want it to show on a page.

Twey
07-07-2006, 05:00 PM
<?php
$conn = mysql_connect('dbserver', 'dbusername', 'dbpassword');
mysql_select_db('databasename');
$tablename = 'mytable';
if(isset($_GET['delete']))
if(!is_numeric($_GET['delete'])) die();
else mysql_query('delete from `' . $tablename . '` where id=' . $_GET['delete'] . ';');

$rs = mysql_query('select * from `' . $tablename . '`;');
$row = mysql_fetch_array($rs);
$cols = array();
foreach($row as $k => $v)
array_push($cols, $k);
array_push($cols, 'del');
echo('<table><tr>');
for($i = 0; $i < count($cols); ++$i)
echo('<th>' . $cols[$i] . '</th>');
echo('</tr>');
do {
$row['del'] = '<form action="?delete=' . $row['id'] . '" method="get"><input type="submit" value="Delete"></form>';
echo('<tr>');
for($i = 0; $i < count($cols); ++$i) {
?>
<td><?php echo($row[$i]); ?></td>
<?php
}
echo('</tr>');
} while($row = mysql_fetch_array($rs));
echo('</table>');
?>Untested.

jad9321
07-07-2006, 05:03 PM
Ok do I need to change anything accept for the db info????

Twey
07-07-2006, 05:34 PM
No, so long as you have a unique numerical column called "id".

jad9321
07-07-2006, 08:14 PM
And how do you get that???

jad9321
07-07-2006, 08:15 PM
?___?

Twey
07-07-2006, 08:15 PM
Uh... you... add it to your table. :)

jad9321
07-07-2006, 08:16 PM
Huhhh? Can you tell me how?

jad9321
07-07-2006, 08:21 PM
Well someone gave me this script...


<html>
<title>Request Line</title>

<?php
$username = DBUSERNAME;
$password = DBPASSWORD;
$database = "DBNAME";
$db = mysql_connect(localhost, $username, $password) or die(mysql_error());
mysql_select_db($database, $db) or die("Unable to select database");
$query = "SELECT Habbo Name, Song Request, Shoutout/Joke";
$result = mysql_query($query, $db);

echo '<h1 style="text-align: center; font-weight: bold;">Season 2006/07 Squad</h1><br/><br/>';

while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $key => $value) {
$$key = htmlspecialchars($value);
}

echo '<table cellspacing="3" cellpadding="5" align="center" style="border:1px solid #999999; width: 70%;">';
echo "<tr><td><b>Habbo Name</b></td><td>$Habbo Name</td></tr>";
echo "<tr><td><b>Song Request</b></td><td>$Song Request</td></tr>";
echo "<tr><td><b>Shoutout/Joke</b></td><td>$Shoutout/Joke</td></tr>";
echo "</table><br/><br/>";
}
mysql_close($db);
?>
</html>

It just needs the delete function.

Twey
07-07-2006, 08:25 PM
However you created the table in the first place. :)

Errrr... I'm pretty sure that won't work.

jad9321
07-07-2006, 08:29 PM
Idk I really want a simple code to have it show up in a table with a delete button. can you do that like without all the ID crap... Or teach me the ID CRAP?

Twey
07-07-2006, 08:37 PM
All you need is a unique column, which your table must already have. Just change the 'id' to the name of your unique column, and surround the value with quotes where it's used in to delete a row if the value isn't numerical.

jad9321
07-08-2006, 06:34 PM
Ok I Get This error.

Warning: Invalid argument supplied for foreach() in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 14
del



:/ what should i do?

Twey
07-08-2006, 07:49 PM
Is that with my script, or the other?

jad9321
07-08-2006, 08:07 PM
Yours...

Twey
07-08-2006, 08:26 PM
I'm guessing you missed a quote somewhere.
<?php
$conn = mysql_connect('dbserver', 'dbusername', 'dbpassword');
mysql_select_db('databasename');
$tablename = 'mytable';
$uniquerow = 'id';
if(isset($_GET['delete']))
if(!is_numeric($_GET['delete'])) die();
else mysql_query('delete from `' . $tablename . '` where ' . $uniquerow . '=\'' . $_GET['delete'] . '\';');

$rs = mysql_query('select * from `' . $tablename . '`;');
$row = mysql_fetch_array($rs);
$cols = array();
foreach($row as $k => $v)
array_push($cols, $k);
array_push($cols, 'del');
echo('<table><tr>');
for($i = 0; $i < count($cols); ++$i)
echo('<th>' . $cols[$i] . '</th>');
echo('</tr>');
do {
$row['del'] = '<form action="?delete=' . $row[$uniquerow] . '" method="get"><input type="submit" value="Delete"></form>';
echo('<tr>');
for($i = 0; $i < count($cols); ++$i) {
?>
<td><?php echo($row[$i]); ?></td>
<?php
}
echo('</tr>');
} while($row = mysql_fetch_array($rs));
echo('</table>');
?>Should work if you just change the details.

jad9321
07-08-2006, 09:00 PM
Now i got this error.

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 12

Warning: Invalid argument supplied for foreach() in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 14
del


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 30


and lets say the Uneque colom is named ID would it be (ID)

???

Twey
07-08-2006, 09:05 PM
and lets say the Uneque colom is named ID would it be (ID)Eh?

Paste the top bit of the script after you've configured it (without username and password, obviously).

jad9321
07-08-2006, 09:18 PM
<?php
$conn = mysql_connect('localhost', '', '');
mysql_select_db('smiletest');
$tablename = 'request';
$uniquerow = '(ID)';
if(isset($_GET['delete']))
if(!is_numeric($_GET['delete'])) die();
else mysql_query('delete from `' . $tablename . '` where ' . $uniquerow . '=\'' . $_GET['delete'] . '\';');

$rs = mysql_query('select * from `' . $tablename . '`;');
$row = mysql_fetch_array($rs);
$cols = array();
foreach($row as $k => $v)
array_push($cols, $k);
array_push($cols, 'del');
echo('<table><tr>');
for($i = 0; $i < count($cols); ++$i)
echo('<th>' . $cols[$i] . '</th>');
echo('</tr>');
do {
$row['del'] = '<form action="?delete=' . $row[$uniquerow] . '" method="get"><input type="submit" value="Delete"></form>';
echo('<tr>');
for($i = 0; $i < count($cols); ++$i) {
?>
<td><?php echo($row[$i]); ?></td>
<?php
}
echo('</tr>');
} while($row = mysql_fetch_array($rs));
echo('</table>');
?>Should work if you just change the details.

Twey
07-08-2006, 09:22 PM
No, not (ID), just ID.

jad9321
07-08-2006, 09:26 PM
Gots an error...


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 12

Warning: Invalid argument supplied for foreach() in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 14
del


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 30

Twey
07-08-2006, 09:37 PM
Usually means there were no results. What's the layout of your table?

jad9321
07-08-2006, 09:40 PM
Lol there are no results...

jad9321
07-09-2006, 05:34 PM
Not working:


<?php

$conn = mysql_connect('localhost', '', '');
mysql_select_db('');
$tablename = 'request';
$uniquerow = 'ID';
if(isset($_GET['delete']))
if(!is_numeric($_GET['delete'])) die();
else mysql_query('delete from `' . $tablename . '` where ' . $uniquerow . '=\'' . $_GET['delete'] . '\';');

$rs = mysql_query('select * from `' . $tablename . '`;');
$row = mysql_fetch_array($rs);
$cols = array();
foreach($row as $k => $v)
array_push($cols, $k);
array_push($cols, 'del');
echo('<table><tr>');
for($i = 0; $i < count($cols); ++$i)
echo('<th>' . $cols[$i] . '</th>');
echo('</tr>');
do {
$row['del'] = '<form action="?delete=' . $row[$uniquerow] . '" method="get"><input type="submit" value="Delete"></form>';
echo('<tr>');
for($i = 0; $i < count($cols); ++$i) {
?>
<td><?php echo($row[$i]); ?></td>
<?php
}
echo('</tr>');
} while($row = mysql_fetch_array($rs));
echo('</table>');
?>


Gets error:
Warning: Invalid argument supplied for foreach() in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 14
del

jad9321
07-10-2006, 01:31 AM
Any one have any idea about the above??? ^^^^^^

Twey
07-10-2006, 01:52 AM
You still haven't answered my question.

jad9321
07-10-2006, 01:56 AM
What question???

jr_yeo
07-10-2006, 03:24 AM
What's the layout of your table?

this question :cool:

jad9321
07-10-2006, 03:48 AM
I think its like accross the top...

Habbo Name, Song Request, Shoutout/Joke, ID

Twey
07-10-2006, 04:15 AM
Well how about you find out?

jad9321
07-10-2006, 10:00 PM
Yeah its....

Habbo Name, Song Request, Shoutout/Joke, ID


(I found out...)

jad9321
07-11-2006, 12:12 AM
-sighs-

jad9321
07-11-2006, 08:34 PM
hmmmmmmmmmmmmmmmmmmmmmmm...

jr_yeo
07-12-2006, 06:40 PM
Joe, have u tried the latest script posted by Twey? :p

anywayz, i did and it worked on my local web server :D

<EDIT>



<table border=1><tr><th>0</th><th>ID</th><th>1</th><th>Habbo Name</th><th>2</th><th>Song Request</th><th>3</th><th>ShoutOut/Joke</th><th>del</th></tr><tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr></table>

why is there an additional table header before the ID, Habbo Name, Song Request, ShoutOut/Joke? :p and extra table data after the execution of the request.php

jad9321
07-13-2006, 12:04 AM
Ok... I am reallly confused.

This is EXACCLY whats in the requests.php file:


<?php

$conn = mysql_connect('localhost', 'smiletest', 'jjaadd');
mysql_select_db('smiletest');
$tablename = 'request';
$uniquerow = 'ID';
if(isset($_GET['delete']))
if(!is_numeric($_GET['delete'])) die();
else mysql_query('delete from `' . $tablename . '` where ' . $uniquerow . '=\'' . $_GET['delete'] . '\';');

$rs = mysql_query('select * from `' . $tablename . '`;');
$row = mysql_fetch_array($rs);
$cols = array();
foreach($row as $k => $v)
array_push($cols, $k);
array_push($cols, 'del');
echo('<table><tr>');
for($i = 0; $i < count($cols); ++$i)
echo('<th>' . $cols[$i] . '</th>');
echo('</tr>');
do {
$row['del'] = '<form action="?delete=' . $row[$uniquerow] . '" method="get"><input type="submit" value="Delete"></form>';
echo('<tr>');
for($i = 0; $i < count($cols); ++$i) {
?>
<td><?php echo($row[$i]); ?></td>
<?php
}
echo('</tr>');
} while($row = mysql_fetch_array($rs));
echo('</table>');
?>


And what was the thingy you posted?????? Huh?:


<table border=1><tr><th>0</th><th>ID</th><th>1</th><th>Habbo Name</th><th>2</th><th>Song Request</th><th>3</th><th>ShoutOut/Joke</th><th>del</th></tr><tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr></table>

Where is that supposed to go? :| God i'm confused...

jr_yeo
07-13-2006, 05:40 AM
the output of the request.php if u run the script :p

Joe, have u tried the latest script posted by Twey? :p
anywayz, i did and it worked on my local web server :D

jad9321
07-13-2006, 07:46 PM
Omg i am REALLY CONFUSED!

jr_yeo
07-13-2006, 07:54 PM
question :D have u tried running the request.php? :p

jad9321
07-13-2006, 09:50 PM
Uhh. There is no request.php

Theres only Requests.php

jr_yeo
07-14-2006, 04:20 AM
oic :D

have u tried running the REQUESTS.PHP? :p

jad9321
07-15-2006, 08:04 PM
Yes...

Well i'm just gona do this...


Requests.php:



<?php

$conn = mysql_connect('', '', '');
mysql_select_db('');
$tablename = 'request';
$uniquerow = 'ID';
if(isset($_GET['delete']))
if(!is_numeric($_GET['delete'])) die();
else mysql_query('delete from `' . $tablename . '` where ' . $uniquerow . '=\'' . $_GET['delete'] . '\';');

$rs = mysql_query('select * from `' . $tablename . '`;');
$row = mysql_fetch_array($rs);
$cols = array();
foreach($row as $k => $v);
array_push($cols, $k);
array_push($cols, 'del');
echo('<table><tr>');
for($i = 0; $i < count($cols); ++$i);
echo('<th>' . $cols[$i] . '</th>');
echo('</tr>');
do {
$row['del'] = '<form action="?delete=' . $row[$uniquerow] . '" method="get"><input type="submit" value="Delete"></form>';
echo('<tr>');
for($i = 0; $i < count($cols); ++$i) {
?>
<td><?php echo($row[$i]); ?></td>
<?php
}
echo('</tr>');
} while($row = mysql_fetch_array($rs));
echo('</table>');
?>


Than I have my mysql database...

I have this NOWARE:

<table border=1><tr><th>0</th><th>ID</th><th>1</th><th>Habbo Name</th><th>2</th><th>Song Request</th><th>3</th><th>ShoutOut/Joke</th><th>del</th></tr><tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr></table>


I have NO IDEA WHERE THAT IS SUPPOSED TO GO....

jr_yeo
07-16-2006, 05:37 AM
I have NO IDEA WHERE THAT IS SUPPOSED TO GO....

this is the output/result/outcome that i got when i ran the requests.php :p


<table border=1><tr><th>0</th><th>ID</th><th>1</th><th>Habbo Name</th><th>2</th><th>Song Request</th><th>3</th><th>ShoutOut/Joke</th><th>del</th></tr><tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr></table>

thought u might want to compare it with what uve got

if u could just ignore this if this is not the same as what u got when u ran the requests.php, that would be great (for me, at least)

jad9321
07-16-2006, 03:36 PM
Ohhhhhhhhhhhhh... No I didnt get that...
I said earlier in this thread I got error:

Warning: Invalid argument supplied for foreach() in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 14
del



ok... ok... now were on the same page.......

jr_yeo
07-16-2006, 03:49 PM
huh? :D the script is running smoothly on my end :p

no errors whatsoever :p

jad9321
07-16-2006, 04:46 PM
Can you tell me EXACCLY WHATS IN YOUR Request.php... Or requests.php... What ever.

I might be like retarded.

:P

jr_yeo
07-16-2006, 06:36 PM
Can you tell me EXACCLY WHATS IN YOUR Request.php... Or requests.php

sorry :( just formatted my hard disk :(

jad9321
07-16-2006, 06:57 PM
Uhh... Ok can you run it again and see if it works... And if it did send itt?

jr_yeo
07-16-2006, 07:00 PM
wait.... :p

trying to find a copy of the requests.php :D

jad9321
07-16-2006, 08:56 PM
Did you?

jr_yeo
07-16-2006, 09:03 PM
impatient are we? :D

jr_yeo
07-16-2006, 09:21 PM
ran the script :p

this is the output/result/outcome from my end :D



<table><tr><th>del</th></tr><tr><td></td>
</tr></table>

jad9321
07-17-2006, 01:43 PM
What EXACCLY is in the request.php or Requests.php file?

jr_yeo
07-17-2006, 02:11 PM
this :p


<?php

$conn = mysql_connect('localhost', 'habbo', 'habbo');
mysql_select_db('habbo');
$tablename = 'request';
$uniquerow = 'ID';
if(isset($_GET['delete']))
if(!is_numeric($_GET['delete'])) die();
else mysql_query('delete from `' . $tablename . '` where ' . $uniquerow . '=\'' . $_GET['delete'] . '\';');

$rs = mysql_query('select * from `' . $tablename . '`;');
$row = mysql_fetch_array($rs);
$cols = array();
foreach($row as $k => $v)
array_push($cols, $k);
array_push($cols, 'del');
echo('<table><tr>');
for($i = 0; $i < count($cols); ++$i)
echo('<th>' . $cols[$i] . '</th>');
echo('</tr>');
do {
$row['del'] = '<form action="?delete=' . $row[$uniquerow] . '" method="get"><input type="submit" value="Delete"></form>';
echo('<tr>');
for($i = 0; $i < count($cols); ++$i) {
?>
<td><?php echo($row[$i]); ?></td>
<?php
}
echo('</tr>');
} while($row = mysql_fetch_array($rs));
echo('</table>');
?>


What EXACTLY is in YOUR copy of requests.php? :p

jad9321
07-20-2006, 03:20 AM
Same thing...
But i STILL GET THE ERRRRRRRRRRRRRRRRRRRRORRRRRRRRRRRRRR!

Warning: Invalid argument supplied for foreach() in /fpgs/fpgshttpd/smileyoureahabbo/scripts/radiobox/requests.php on line 14
del

I guess its telling me that there is something wrong with
foreach($row as $k => $v)
-sigh- this will never work will it?

jr_yeo
07-20-2006, 04:27 AM
Same thing...
are u sure? :p

coz i ran the requests.php on WinXP. this is the result :



<table><tr><th>0</th><th>id</th><th>1</th><th>Name</th><th>2</th><th>Song</th><th>3</th><th>Joke</th><th>del</th></tr><tr><td>00001</td>
<td>Michael Smith</td>
<td>Trust His Heart</td>
<td>Joke Joke Joke Joke Joke Joke Joke Joke Joke Joke Joke Joke Joke</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr></table>

and this is the result of requests.php in Linux :



<table><tr><th>del</th></tr><tr><td></td>
</tr></table>

whats ur OS? :p

Twey
07-20-2006, 01:24 PM
I think your PHP and MySQL versions are more important than your OS. Tell us those, and manually execute the command:
select * from `request`;... on your database. What is the output?

jad9321
07-20-2006, 08:14 PM
PHP Version 5.0.4
MySql Version 4.1.20

And HUH?????

jad9321
07-21-2006, 11:00 PM
:[


:[

jr_yeo
07-22-2006, 03:33 PM
can u make ur requests.php to requests.txt just to really see if we're on the page? :D tnx :p

jad9321
07-22-2006, 09:59 PM
I sourta dont know if i can. It has my passwords and stuff.

jr_yeo
07-23-2006, 01:52 AM
oic :D oh right :p i forgot :D

jad9321
07-24-2006, 03:42 AM
:[ :[ :[ :[ :[

jr_yeo
07-24-2006, 12:05 PM
that's all i could do to help :p i running out of ideas on how to help you solve the problem :D

jad9321
07-24-2006, 03:35 PM
God damn. I really need help.

jad9321
07-24-2006, 07:12 PM
Yay.

XD i played around w/ it and i got it like 1/2 working.
I still have like two little problems,
The table is poorly aligned.
And The delete function wont work.


sample:http://smileyoureahabbo.freepgs.com/scripts/radiobox/requests.php

Twey
07-24-2006, 08:19 PM
Not enough info. What's the code now, then?

jad9321
07-24-2006, 08:57 PM
<?php

$conn = mysql_connect('localhost', '', '');
mysql_select_db('');
$tablename = 'request';
$uniquerow = 'ID';
if(isset($_GET['delete']))
if(!is_numeric($_GET['delete'])) die();
else mysql_query('delete from `' . $tablename . '` where ' . $uniquerow . '=\'' . $_GET['delete'] . '\';');

$rs = mysql_query('select * from `' . $tablename . '`;');
$row = mysql_fetch_array($rs);
$cols = array();
foreach($row as $k => $v)
array_push($cols, $k);
array_push($cols, 'del');
echo('<table><tr>');
for($i = 0; $i < count($cols); ++$i)
echo('<th>' . $cols[$i] . '</th>');
echo('</tr>');
do {
$row['del'] = '<form action="?delete=' . $row[$uniquerow] . '" method="get"><input type="submit" value="Delete"></form>';
echo('<tr>');
for($i = 0; $i < count($cols); ++$i) {
?>
<td><?php echo($row[$i]); ?></td>
<?php
}
echo('</tr>');
} while($row = mysql_fetch_array($rs));
echo('</table>');
?>

Twey
07-24-2006, 09:47 PM
<td><?php echo($row[$i]); ?></td>Should be:
<td><?php echo($row[$cols[$i]]); ?></td>I think.

jad9321
07-24-2006, 10:13 PM
You think. Lol... Got us a little closer.
The delete button is there... Just dosent work.
And theres doubles of each result.
http://smileyoureahabbo.freepgs.com/scripts/radiobox/requests.php

Twey
07-24-2006, 10:19 PM
Please add another row to the database.

jad9321
07-24-2006, 10:44 PM
Ok...
I added one...
its still not working.
http://smileyoureahabbo.freepgs.com/scripts/radiobox/requests.php

jad9321
07-25-2006, 01:13 AM
hmmmmmmmmm..

jad9321
07-25-2006, 03:10 AM
hmmmmmmmm Twey. Have any idea?

jad9321
07-25-2006, 09:33 PM
Any ideassss?

jad9321
07-26-2006, 05:31 PM
I feel like i'm being ignored...

jad9321
07-27-2006, 04:33 PM
:[ :[ :[

BLiZZaRD
07-28-2006, 12:45 AM
Not ignored... just... well.. I dunno... did you say somehting? :p

jad9321
07-28-2006, 03:18 AM
I'm serious... Please Twey Help!

jad9321
07-29-2006, 12:40 AM
Twey??? Please Man!

jad9321
08-01-2006, 07:56 PM
I REALLY NEED HELP Twey! PLEASEEEE!

jad9321
08-01-2006, 08:20 PM
SO I Guess everyone in the fourms hates me now? Noone is paying attention to me... :(

jr_yeo
08-02-2006, 04:54 AM
SO I Guess everyone in the fourms hates me now?
not really :p i, for one, can't help you. m still learning all this myself :) sound like a signature of somebody... he he :cool:

Twey
08-02-2006, 05:14 AM
I've bookmarked this thread, and I consider it daily :) When I spot an answer, I assure you I'll let you know.

jad9321
08-15-2006, 02:35 AM
I guess still no idea?