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-23. : 3:29 am]
DarkenedFantasies -- Probably just didn't care. For example, at some point before release, they've updated the graphics of some of the Protoss buildings (Forge, CyberCore, Citadel, Observatory, Arbiter Tribunal), but instead of properly re-rendering them with edited 3D models, they did crappy copy-paste jobs on the rendered graphics.
[2026-6-22. : 8:35 pm]
Ultraviolet -- :wob:
[2026-6-21. : 11:38 pm]
Symmetry -- :wob:
[2026-6-21. : 4:56 am]
Ultraviolet -- I suppose we'll likely never know, but my guess would be that they already saw it operating successfully and there was no monetary incentive to finish the original work. And the dev cycle in old school Blizzard was so hectic, it's possible it just got forgotten about after the original game got released. Plus there's an element of existing MPQ files that were packaged with the original discs becoming outdated if they updated it. And it's not like they remade the original MPQs, they just made new ones for BW specifically
[2026-6-21. : 4:26 am]
Oh_Man -- so that makes me think maybe the theory they are unfinished is not true and its a deliberate design decision, coz why not finish them wen ur making brood war?
[2026-6-21. : 4:25 am]
Oh_Man -- the thing is thos buildings are from classic. that means they went ahead and made brood war without ever finishing the 'unfinished' buildings
[2026-6-20. : 6:15 pm]
Ultraviolet -- Yeah he's talked about a lot of that stuff in his casts before. It seems plausible. Especially knowing how Blizzard of yesteryear operated.
[2026-6-20. : 3:47 pm]
NudeRaider -- to clarify: couldn't recall the behavior for every single Protoss building but I was aware the disparity exists.
[2026-6-20. : 3:43 pm]
NudeRaider -- Contained nothing new for me. Didn't know all building's behavior, but very much all unit's. Also Terran balance whine - also nothing new :lol:
[2026-6-19. : 9:57 am]
Oh_Man -- makes me wonder if SEN knows anything about the topic
Please log in to shout.


Members Online: RIVE, O)FaRTy1billion[MM]