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.
[2026-6-04. : 3:42 am]
RIVE -- Hellooooo, Nurse
[2026-6-03. : 4:19 pm]
NudeRaider -- Hello World!
[2026-6-01. : 4:03 pm]
IskatuMesk -- no Hello World? No Hello . jpeg? Not even ddosing some government website? smh my head
[2026-5-31. : 10:02 pm]
Symmetry -- I was really just figuring out how to compile
[2026-5-31. : 10:02 pm]
Symmetry -- I didn't make it do anything
[2026-5-31. : 9:17 pm]
Ultraviolet -- hell yeah. did you have trouble making the button functional, or just haven't gotten there yet?
[2026-5-31. : 8:29 pm]
Symmetry -- I made the marine shoot lasers and gave the medic a nonfunctional button
[2026-5-31. : 8:07 pm]
Ultraviolet -- Symmetry
Symmetry shouted: I did my first EUD thing today. Feels like me finding arsenal at age 8 again
haha for sure. in some ways it's even more exciting because you can play EUD maps on regular battle.net, don't need to convince someone to download your mod to play with you. what did you do?
[2026-5-31. : 6:47 pm]
Symmetry -- I did my first EUD thing today. Feels like me finding arsenal at age 8 again
[2026-5-31. : 3:20 pm]
l)ark_ssj9kevin -- le reddit
Please log in to shout.


Members Online: NudeRaider, DarkenedFantasies