Hello! This will be my first post to this forum but I am hoping to become one of the programmers helping others here. The reason I’m here is a home project(making a website for my game guild) has taken me into the world of both HTML, PHP and MySQL, and I’m loving it! I am mostly scavenging through all the websites and tutorials I can find to learn more, but this one has me beat for now.
I am making a user database for the website, and I’ve made an admin index page where user and guild management can be done. Here I’ve made a table that updates dynamically with set values from the MySQL table. I tested this a bit and noticed nothing happened. I did however not get an error connecting to MySQL, selecting the database, or submitting the information to the database.
So in order to debug I added an echo of the actual query submitted to the database, and found it only submitted the last row in the database back, not every record as I intended.
I was wondering if one of your bright minds could have a look at the code for this and see where I’ve gone horribly wrong
Here we make the connection to the database in order to fill the variables we want to update the fields with:
[php]<?php
$username=“username”;
$password=“password”;
$database=“database”;
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die(“Unable to select database”);
$query=“SELECT * FROM Users WHERE weight > 5 ORDER BY weight”;
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$ID=mysql_result($result,$i,“ID”);
$name=mysql_result($result,$i,“usrname”);
$class=mysql_result($result,$i,“usrcla”);
$title=mysql_result($result,$i,“usrtit”);
$level=mysql_result($result,$i,“usrlvl”);
$alt=mysql_result($result,$i,“usralt”);
$officer=mysql_result($result,$i,“usrofficer”);
$active=mysql_result($result,$i,“Active”);
?>[/php]
Here we display the information in a table(I’m sure there may be a way of optimizing the boolean fields but I’m not that comfortable with the possibilities yet and wanted to go with something that would return what I wanted):
[code]
Name |
Class |
Title |
Level |
Alt |
Officer |
Active |
|
<? echo $class; ?> Powertech Mercenary Juggernaut Marauder Operative Sniper Sorcerer Assassin | "><?if ($alt == 1) { echo "Yes"; } else { echo "No"; }; ?> "><?if ($alt == 1) { echo "No"; } else { echo "Yes"; }; ?> | "><?if ($officer == 1) { echo "Yes"; } else { echo "No"; }; ?> "><?if ($officer == 1) { echo "No"; } else { echo "Yes"; }; ?> | "><?if ($active == 1) { echo "Yes"; } else { echo "No"; }; ?> "><?if ($active == 1) { echo "No"; } else { echo "Yes"; }; ?> |
?> [/code] (I'm aware I also cheated on the select box for the class field, but I think it works to its purpose :p)
And here’s usrupdate.php
[php]<?php
$id=$_POST[‘ud_id’];
$usrname=$_POST[‘ud_usrname’];
$usrcla=$_POST[‘ud_usrcla’];
$usrtit=$_POST[‘ud_usrtit’];
$usrlvl=$_POST[‘ud_usrlvl’];
$usralt= $_POST[‘ud_usralt’];
$usrofficer= $_POST[‘ud_usrofficer’];
$Active= $_POST[‘ud_active’];
mysql_connect (“localhost”, “username”, “password”)
or die (‘I cannot connect to the database.’);
mysql_select_db (“database”)
or die(mysql_error(‘I can not select the table.’));
$query = “Update Users SET usrname=’$usrname’, usrcla=’$usrcla’, usrtit=’$usrtit’, usrlvl=’$usrlvl’, usralt=’$usralt’, usrofficer=’$usrofficer’, Active=’$Active’ WHERE id=’$ud_id’”;
echo $query;
if ($query) {
Print “The user has been successfully updated.”;
}
else{
Print “Unable to update user.”;
}
mysql_query($query);
mysql_close();
?>[/php]
I know this is a big thing to look through but I’m close to losing my mind troubleshooting this, hope you can assist!