Page 1 of 1

*sigh* Still having problems

Posted: Wed Jan 07, 2009 11:26 am
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

Re: *sigh* Still having problems

Posted: Wed Jan 07, 2009 11:32 am
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.

Re: *sigh* Still having problems

Posted: Wed Jan 07, 2009 11:44 am
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>
 

Re: *sigh* Still having problems

Posted: Wed Jan 07, 2009 11:56 am
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.

Re: *sigh* Still having problems

Posted: Wed Jan 07, 2009 12:14 pm
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.

=[

Re: *sigh* Still having problems

Posted: Thu Jan 08, 2009 3:12 am
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.

Re: *sigh* Still having problems

Posted: Thu Jan 08, 2009 7:56 am
by Sephern
hm, okay, thanks for the help, and the tip =]

Re: *sigh* Still having problems

Posted: Fri Jan 09, 2009 10:49 am
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.

Re: *sigh* Still having problems

Posted: Sat Jan 10, 2009 3:49 pm
by Sephern
Bump.

Still nothing =[