mysql-link error message

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
danwguy
Forum Contributor
Posts: 256
Joined: Wed Nov 17, 2010 1:09 pm
Location: San Diego, CA

mysql-link error message

Post by danwguy »

I have the following code, that when run,should take a file that has been uploaded, resize it, save it, then open it up as data and add it to a blob in the db but I keep getting an error. The cod I have is...

Code: Select all

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 
      include('SimpleImage.php');
      $image = new SimpleImage();
      $image->load($_FILES['image']['tmp_name']);
      $image->resize(128, 128);
      $image->save('avatar.jpg');
      $fp = fopen("avatar.jpg", 'r');
 $data = fread($fp, filesize("avatar.jpg"));
      $data = addslashes($data);
      fclose($fp);
 $query = "UPDATE users SET ";
      $query .= "icon='$data' WHERE username='$uname'";
      $results = mysql_query($query, $link);
      if($results) {
      header('location: desktop.php');
      exit();
$uname is set as $uname = $_SESSION['username']; I can echo out $uname and it shows the correct username but I keep getting the following error...
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in avatarupload.php on line 82
I am uing a connect.php file that handles connecting to the database and selecting the right table, and that is working right, because it is usedon every other pge and shows properly. Please someone help me out on this one, I can't see where the error is.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: mysql-link error message

Post by Christopher »

You need to do a $link = mysql_connect(...) somewhere.
(#10850)
Post Reply