Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

php code question

I'm learning how php and mysql interact.  I run phpbb and decided to start learning by making a page that restores the admin status on a particular user in case it ever got changed.  I know there are other easy ways, but I'm trying to learn why mine doesn't work.

In the following, in the table named phpbb_users, I want to make user_id 2's user_level equal 1 via the php script.

The following connects to the database and does the echo at the end, but doesn't actually update the database.  What am I doing wrong?

<?php
$host = "localhost";
$db = "dbnamehere";
$user = "myusername";
$pw = "mypassword";
mysql_connect($host, $user, $pw) or die(mysql_error());
mysql_select_db($db);
$sql = "UPDATE " . phpbb_users . "
SET user_level = 1
WHERE user_id = 2";

echo "admin restored";
?>

What am I doing wrong?

0
source2k3
Asked:
source2k3
1 Solution
 
mattjp88Commented:
you need $result=mysql_query($sql); before the echo.  Here is a great tutorial about php and mysql, everything you need.  http://www.freewebmasterhelp.com/tutorials/phpmysql/1

-Matt
0
 
source2k3Author Commented:
You're the man.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now