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.
[10:13 pm]
Oh_Man -- No APM in chess. Computer just outthinks the human by seeing more moves ahead and more permutations
[10:12 pm]
Oh_Man -- U reckon? Kasparov waa defeated by computer decades ago
[05:47 pm]
NimoStar -- If its any consolation, the human brain would still mop the floor with this bot if it wasn't limited by the mechanical interface
[05:34 pm]
NimoStar -- Well. The bot didn't come up with any new strategy. It just has superhuman micro. Hard to beat that. I reckon even the simplest dedicated chess engines are unbeatable for humans now.
[02:13 pm]
Oh_Man -- all g
[10:54 am]
NudeRaider -- Oh_Man
Oh_Man shouted: NudeRaider did u watch the entire video? it's not one game. it's currently dominating the ladder at number 1 position. do ur research first!
Oops, caught me there, no I haven't. :( I was imagining how the game went. Sorry for that. Watching it now. brb
[10:52 am]
NudeRaider -- NimoStar
NimoStar shouted: They were not "Unprepared" that was their fifth loss in a row against the bot. The other replays are also available
that doesn't mean he was prepared. When humans come around with new strategies it often takes weeks until the pros figure out how to shut it down. Oh_Man that's certainly a way more convincing argument for micro being "too good to beat".
[09:43 am]
DiearAnother -- wirefram
[08:35 am]
NimoStar -- Well, pros showed that long ago... half of zerg pros just ling muta rush
[08:35 am]
NimoStar -- " its shown is that you can trade 1000's of apm to make up for lack of strategy"
Please log in to shout.


Members Online: O)FaRTy1billion[MM], Oh_Man