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.
[03:45 am]
Sylph-Of-Space -- Does the shoutbox get disabled when there's spammers?
[06:47 am]
NudeRaider -- lil-Inferno
lil-Inferno shouted: nah
strong
[05:41 am]
Ultraviolet -- 🤔 so inf is in you?
[2024-5-17. : 4:57 am]
O)FaRTy1billion[MM] -- my name is mud
[2024-5-17. : 4:35 am]
Ultraviolet -- mud, meet my friend, the stick
[2024-5-16. : 10:07 pm]
lil-Inferno -- nah
[2024-5-16. : 8:36 pm]
Ultraviolet -- Inf, we've got a job for you. ASUS has been very naughty and we need our lil guy to go do their mom's to teach them if they fuck around, they gon' find out
[2024-5-16. : 5:25 pm]
NudeRaider -- there he is, right on time! Go UV! :D
[2024-5-16. : 5:24 pm]
lil-Inferno -- poopoo
[2024-5-16. : 5:14 pm]
UndeadStar -- I wonder if that's what happened to me. A returned product (screen) was "officially lost" for a while before being found and refunded. Maybe it would have remained "lost" if I didn't communicate?
Please log in to shout.


Members Online: fithplanet, 6gabriellac2322yc4