Staredit Network > Forums > Technology & Computers > Topic: New question about PHP
New question about PHP
Jan 12 2009, 2:02 pm
By: Devourer  

Jan 12 2009, 2:02 pm Devourer Post #1

Hello

I'm currently working on a "profile-script". It displays the information staying in the mysql database table 'users'.
One of my friends and I worked on it but we still don't get it. It always says that the mysql_fetch_array supplys an invalid argument.

here is the code:
<?php

$user = $_GET['user'];

$con = mysql_connect("localhost","name","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

$sql = "SELECT `username`,`geld`,`avatar`,`joined`,`posts`,`topics`,`shouts` FROM users WHERE `username`='" . $user . "'";
$result = mysql_query($sql,$con);

if(mysql_num_rows($result)==1){

while($row = mysql_fetch_array($result)){
echo "<table border=1>";
echo "<tr><td bgcolor=black><center><font color=white> Username: </font></center></td>";
echo "<td bgcolor=black><center><font color=white>" . $row['username'] . "</font></center></td>";

echo "<tr><td bgcolor=black><center><font color=white> Geld: </font></center></td>";
echo "<td bgcolor=black><center><font color=white>" . $row['geld'] . "</font></center></td>";

echo "<tr><td bgcolor=black><center><font color=white> Avatar: </font></center></td>";
echo "<td bgcolor=black><center><font color=white>" . $row['avatar'] . "</font></center></td>";

echo "<tr><td bgcolor=black><center><font color=white> Joined: </font></center></td>";
echo "<td bgcolor=black><center><font color=white>" . $row['joined'] . "</font></center></td>";

echo "<tr><td bgcolor=black><center><font color=white> Posts: </font></center></td>";
echo "<td bgcolor=black><center><font color=white>" . $row['posts'] . "</font></center></td>";

echo "<tr><td bgcolor=black><center><font color=white> Topics: </font></center></td>";
echo "<td bgcolor=black><center><font color=white>" . $row['topics'] . "</font></center></td>";

echo "<tr><td bgcolor=black><center><font color=white> Shouts: </font></center></td>";
echo "<td bgcolor=black><center><font color=white>" . $row['shouts'] . "</font></center></td>";
echo "</table>";
echo "<table border=1><tr height=30%><colgroup width=500></colgroup>";
echo "<td bgcolor=black <center>";
}
}
else{
if(mysql_num_rows($result)==0)
{echo "no user found in database"; }
else{
echo "more than one user found in database";
}
}

?>


We get the $_get['user'] from the "memberlist" however, the memberlist.php is right programmed, we are pretty sure.
Help please.



Please report errors in the Staredit.Network forum.

Jan 12 2009, 2:18 pm Forsaken Archer Post #2



Try mysql_fetch_assoc() instead.



None.

Jan 13 2009, 1:59 am slayer766 Post #3



It's not best to use the <center> tag in HTML, as it's deprecated. I don't know if that's all the code you are using but you also have an open td and center tag at the end. But try this out:

Code
<?php
$user = $_GET['user'];
$con = mysql_connect("localhost","name","password");

if (!$con){
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db");
$result = mysql_query("SELECT `username`,`geld`,`avatar`,`joined`,`posts`,`topics`,`shouts` FROM users WHERE `username`='" . $user . "'");

if(mysql_num_rows($result) == 0){
    echo "no user found in database";
}
else if(mysql_num_rows($result) == 1){
    while($row = mysql_fetch_array($result)){
        echo "<table border=1>";
        echo "<tr><td bgcolor=black><center><font color=white> Username: </font></center></td>";
        echo "<td bgcolor=black><center><font color=white>" . $row['username'] . "</font></center></td>";

        echo "<tr><td bgcolor=black><center><font color=white> Geld: </font></center></td>";
        echo "<td bgcolor=black><center><font color=white>" . $row['geld'] . "</font></center></td>";

        echo "<tr><td bgcolor=black><center><font color=white> Avatar: </font></center></td>";
        echo "<td bgcolor=black><center><font color=white>" . $row['avatar'] . "</font></center></td>";

        echo "<tr><td bgcolor=black><center><font color=white> Joined: </font></center></td>";
        echo "<td bgcolor=black><center><font color=white>" . $row['joined'] . "</font></center></td>";

        echo "<tr><td bgcolor=black><center><font color=white> Posts: </font></center></td>";
        echo "<td bgcolor=black><center><font color=white>" . $row['posts'] . "</font></center></td>";

        echo "<tr><td bgcolor=black><center><font color=white> Topics: </font></center></td>";
        echo "<td bgcolor=black><center><font color=white>" . $row['topics'] . "</font></center></td>";

        echo "<tr><td bgcolor=black><center><font color=white> Shouts: </font></center></td>";
        echo "<td bgcolor=black><center><font color=white>" . $row['shouts'] . "</font></center></td>";
        echo "</table>";
        echo "<table border=1><tr height=30%><colgroup width=500></colgroup>";
        echo "<td bgcolor=black> <center>";
    }
}
else{
    echo "more than one user found in database";
}
?>




None.

Jan 13 2009, 2:35 pm Devourer Post #4

Hello

Both didn't worked.



Please report errors in the Staredit.Network forum.

Jan 13 2009, 7:43 pm slayer766 Post #5



Hmm...you are inputting your name,pass, and database correct?

Add this at the end of your mysql_query, but before the semicolon:

Code
or trigger_error("Error querying database. Please contact administrator.")

If you get that error, then there is a problem with your query, which you might want to change to this:

Code
mysql_query("SELECT * FROM users WHERE `username`='" . $user . "'")




None.

Jan 13 2009, 11:36 pm Forsaken Archer Post #6



Yeah, I was going to suggest that in your last topic: put error catching on all your sql queries.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[02:14 am]
Oh_Man -- pluto vs pro gamer snow: https://youtu.be/NOXXpATkdZU
[2026-9-25. : 2:22 pm]
Oh_Man -- https://youtu.be/Lfo4C0xzU04
[2026-9-25. : 12:00 am]
Oh_Man -- he hasnt won a single game so far this is hilarious
[2026-9-24. : 11:41 pm]
Oh_Man -- new arty username Rage Against The Machine
[2026-9-24. : 10:14 pm]
Oh_Man -- https://m.youtube.com/watch?v=KPXri8q9ZBs artys vsing the bot now
[2026-9-24. : 8:12 pm]
Ultraviolet -- do you even lift bro?
[2026-9-23. : 5:21 pm]
NudeRaider -- Oh_Man
Oh_Man shouted: NudeRaider yeh thts straight up cheating
the mutas yes, the wraiths probably not. Have you even watched the video? ;)
[2026-9-23. : 12:56 pm]
Oh_Man -- NudeRaider
NudeRaider shouted: Oh_Man Artosis hasn't caught on how devastating the perfect focus fire is. With the mutas he was like "the Mutas always seem to have less hp than against a human". But he didn't notice that the flock he had selected always just had one muta that was hurt. Same with the wraiths here. He's talking about how valks+wraith is gonna destroy Pluto's valks, then 5s later he's dumbfounded the human player's air is just gone and he never figured out why. And for some reason didn't even think to go back and look at the battle.
yeh thts straight up cheating
[2026-9-23. : 12:24 pm]
Oh_Man -- arty's done another vid. he's also announced he's going to organise showmatches with pro, with NO maphacks, so we can see its actual capabilities
Please log in to shout.


Members Online: O)FaRTy1billion[MM], MobMob