I don't know what I'm doing wrong, but it won't update ever. I know all the variables work because I've posted them in several places, I've echoed them out, copied that and put it into the query and it's worked, and I've copied it to an entirely different page and it's worked. The one page I need it to work on, it decides not to work. I've gone through and checked the code several times as well, but for some reason it's deciding not to work. I changed the code to two lines, because I thought there might have been a problem on one line.

I've read through many posts and I've tried different things, but I'm not getting any results :(

$u = "UPDATE Profile SET Image = '$f ' WHERE Forum = '$p'";


mysql_query($u, mysql_connect(host, username, pass));

Dani AI

Generated

Several people already hit the most common mistakes — missing database selection and wrong column names (, , , ). If you have ensured the connection and the field names are correct, try these next checks and quick fixes.

  • Check for SQL errors and affected rows instead of assuming success. Silent failures are usually revealed by the DB error message or a zero affected-row count.
  • Confirm the WHERE actually matches a row. Run the same WHERE as a SELECT in the DB client to see whether any row exists for that key/value.
  • Look for invisible characters in your variables (leading/trailing spaces, newlines). Use a length or hex dump of the string when debugging. The code posted in the thread shows an extra space in a quoted value — accidental whitespace happens.
  • Verify user privileges. The DB user may connect but lack UPDATE rights. Use the DB client to inspect grants for the current user.
  • Consider OS/file-system case sensitivity: table name casing can matter on Linux hosts.
  • Avoid the old mysql extension entirely if possible; use prepared statements to eliminate quoting problems and to get built-in error handling.

A short PDO example (use this pattern to get exceptions and row counts):

try {
    $pdo = new PDO('mysql:host=HOST;dbname=DBNAME;charset=utf8', 'user', 'pass', [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]);
    $stmt = $pdo->prepare('UPDATE `Profile` SET `Image` = :img WHERE `Forum` = :forum');
    $stmt->execute([':img' => $f, ':forum' => $p]);
    if ($stmt->rowCount() === 0) {
        // no rows updated — check WHERE value and permissions
    }
} catch (PDOException $e) {
    // log or display $e->getMessage()
}

Debug plan: enable PHP error reporting, capture and log the DB error string, dump variable values (with length), copy the exact SQL and run it in the MySQL client, and check grants. If none of that shows the cause, paste the exact query and the results of a SELECT with the same WHERE — that will reveal whether the WHERE clause or permissions are the issue.

Recommended Answers

All 4 Replies

check your database field names Forum,Image . is it correct or not.

The mysql_query does not know what database to perform the action on.

$link = mysql_connect('host', 'username', 'pass');
mysql_select_db('database');
$u = "UPDATE Profile SET Image = '$f' WHERE Forum = '$p'";
mysql_query($u, $link);
commented: well said ;) +1

you need to connect select database then query, in that order for thing to work.
although if you are using dreamweaver templates sometimes it meses with things.

$conn = mysql_connect('host', 'user', 'pass');
mysql_select_db('database_name');
$sql = "UPDATE Profile SET Image = '$f' WHERE Forum = '$p'";
mysql_query($sql, $conn);

Hope this helps :)

you forgot to select database. use mysql_select_db('database_name') for select database

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.