*sigh* Still having problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

*sigh* Still having problems

Post by Sephern »

I'm sorry to have to ask for help again but I really can't seem to get this working.

Code: Select all

<?php
$username = "root";
$password = "password";
$hostname = "localhost"; 
 
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("flyff",$dbhandle)
  or die("Could not select database");
 
//Connected to database, below is functionality
 
//Select Character name from form
$name = $_POST ["character"];
//Find characters account name
$accountQuery = mysql_query("select accountname from characters where charname='$name'");
$account = mysql_result($accountQuery, 0, "accountname");
//Update accesslevel for account
mysql_query("UPDATE accounts SET accesslevel = '0' WHERE username = '$account'");
//Text feedback.
echo "The Account:";
echo $account; 
echo "has been banned.";
?>
 
I don't know why it isn't working, but not even the echo's are showing on the php page.

If anybody can read over and debug my code, it will be greatly appreciated :D
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: *sigh* Still having problems

Post by mattpointblank »

I don't know if you're using this script in conjunction with something else, but if you're not, your $_POST variable for $name will be empty unless there's a form pointed at your script.

Also, I'd rewrite line 20 to look like this:

Code: Select all

 
$account = mysql_result($accountQuery) or die(mysql_error());
 
This will show an error printout from your database so you can see more accurately what's not working. You could use this again under your second query on line 22.
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: *sigh* Still having problems

Post by Sephern »

Yeah, I'm using it with a form. If you want the code for it, it's-

Code: Select all

<?php
$username = "root";
$password = "";
$hostname = "localhost"; 
 
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("flyff",$dbhandle)
  or die("Could not select database");
 
//Connected to database, below is functionality
?>
 
<html><head><title>Panel</title></head><body>
 Set an access level to 0.<br>
<br>
<form action =accesslevel0.php method="post">
  Character Name: 
  <input type="text" name="character" />
<input type="submit" />
</form>
</body>
</html>
 
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: *sigh* Still having problems

Post by andyhoneycutt »

Similarly, I would add "or die(mysql_error());" to line 19's mysql_query call. See if you're getting any errors there.
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: *sigh* Still having problems

Post by Sephern »

The problem was that it couldn't connect to the SQL, even though the form could o.o

When I changed the connection host to the global ip, rather than local host, it connected...

I now have a new problem though. It connects to the SQL, but doesn't change the field accesslevel.

=[
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: *sigh* Still having problems

Post by mattpointblank »

Haha, it could be because you changed that mysql_result line I suggested. That line was originally assigning a variable:

$account = mysql_result($accountQuery, 0, "accountname");

If you changed it like I said to:

$account = mysql_result($accountQuery) or die(mysql_error());

you're no longer assigning a single result to that variable. I'd normally use that syntax when working with lots of results, not one, so you could change your code and integrate it with mine, like so:

$account = mysql_result($accountQuery, 0, "accountname") or die(mysql_error());

Try that?

Also, a tip: make a separate php file with your mysql connection info in it, and include it at the start of your pages - makes it much easier if you need to move your database later, you just edit one file.
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: *sigh* Still having problems

Post by Sephern »

hm, okay, thanks for the help, and the tip =]
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: *sigh* Still having problems

Post by Sephern »

Okay, I made a new post to bump the thread, cos it still doesn't work.

The code now looks like this:

Code: Select all

<html><head><title>Banning an Account...</title></head><body><?php
$username = "root";
$password = "dbpass";
$hostname = "localhost"; 
 
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
  or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("flyff",$dbhandle)
  or die("Could not select database");
 
//Connected to database, below is functionality
 
$name = $_POST ["character"];
$accountQuery = mysql_query("select accountname from characters where charname='$name'");
$account = mysql_result($accountQuery, 0, "accountname") or die(mysql_error());
mysql_query("UPDATE accounts SET accesslevel = '0'WHERE username = '$account'") or die(mysql_error());
echo "The Account:" or die (mysql_error());
echo $account; 
echo "has been banned.";
?>
</body></html>
It still doesn't seem to work.

When you submit, all that happens is it echoes 'Connected to MySQL'.

No error at all, and it still doesn't edit the database.
Sephern
Forum Commoner
Posts: 73
Joined: Sun Jan 04, 2009 4:44 pm

Re: *sigh* Still having problems

Post by Sephern »

Bump.

Still nothing =[
Post Reply