Helpful Information
 
 
Category: MySQL and other databases
MySQL Database showing on a page.

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

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.

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.

<?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.

Ok do I need to change anything accept for the db info????

No, so long as you have a unique numerical column called "id".

And how do you get that???

?___?

Uh... you... add it to your table. :)

Huhhh? Can you tell me how?

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.

However you created the table in the first place. :)

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

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?

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.

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?

Is that with my script, or the other?

Yours...

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.

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)

???

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).

<?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.

No, not (ID), just ID.

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

Usually means there were no results. What's the layout of your table?

Lol there are no results...

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

Any one have any idea about the above??? ^^^^^^

You still haven't answered my question.

What question???

What's the layout of your table?

this question :cool:

I think its like accross the top...

Habbo Name, Song Request, Shoutout/Joke, ID

Well how about you find out?

Yeah its....

Habbo Name, Song Request, Shoutout/Joke, ID


(I found out...)

-sighs-

hmmmmmmmmmmmmmmmmmmmmmmm...

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

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...

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

Omg i am REALLY CONFUSED!

question :D have u tried running the request.php? :p

Uhh. There is no request.php

Theres only Requests.php

oic :D

have u tried running the REQUESTS.PHP? :p

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....

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)

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.......

huh? :D the script is running smoothly on my end :p

no errors whatsoever :p

Can you tell me EXACCLY WHATS IN YOUR Request.php... Or requests.php... What ever.

I might be like retarded.

:P

Can you tell me EXACCLY WHATS IN YOUR Request.php... Or requests.php

sorry :( just formatted my hard disk :(

Uhh... Ok can you run it again and see if it works... And if it did send itt?

wait.... :p

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

Did you?

impatient are we? :D

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>

What EXACCLY is in the request.php or Requests.php file?

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

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?

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

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?

PHP Version 5.0.4
MySql Version 4.1.20

And HUH?????

:[


:[

can u make ur requests.php to requests.txt just to really see if we're on the page? :D tnx :p

I sourta dont know if i can. It has my passwords and stuff.

oic :D oh right :p i forgot :D

:[ :[ :[ :[ :[

that's all i could do to help :p i running out of ideas on how to help you solve the problem :D

God damn. I really need help.

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

Not enough info. What's the code now, then?

<?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>');
?>

<td><?php echo($row[$i]); ?></td>Should be:
<td><?php echo($row[$cols[$i]]); ?></td>I think.

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

Please add another row to the database.

Ok...
I added one...
its still not working.
http://smileyoureahabbo.freepgs.com/scripts/radiobox/requests.php

hmmmmmmmmm..

hmmmmmmmm Twey. Have any idea?

Any ideassss?

I feel like i'm being ignored...

:[ :[ :[

Not ignored... just... well.. I dunno... did you say somehting? :p

I'm serious... Please Twey Help!

Twey??? Please Man!

I REALLY NEED HELP Twey! PLEASEEEE!

SO I Guess everyone in the fourms hates me now? Noone is paying attention to me... :(

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:

I've bookmarked this thread, and I consider it daily :) When I spot an answer, I assure you I'll let you know.

I guess still no idea?










privacy (GDPR)