Jump to content
Eternal Lands Official Forums
Sign in to follow this  
Aerowind

PHP Help?

Recommended Posts

So, I'm trying to revive my site House of Pwn, and I'm trying to get everything database based.

But I keep getting this error. Can anyone help?

 

$dbuname and $dbserver are not the actual values

Warning: mysql_connect() [function.mysql-connect]: Access denied for user '$dbuname'@'$dbserver' (using password: YES) in /home/houseofp/public_html/admin/header.inc on line 12

I cannot connect to the database because: Access denied for user '$dbuname'@'$dbserver' (using password: YES)

 

Here's the block of code causing the issue.

Line 12 -> $dbh = mysql_connect($dbserver, $dbuname, $dbupass) or die ('I cannot connect to the database because: ' . mysql_error());
//Create Database, if it doesn't exist
$sql = "CREATE DATABASE IF NOT EXISTS $dbname";
mysql_query($sql);
echo 'Error: ' . mysql_error();
mysql_select_db($dbname);

Edited by Aerowind

Share this post


Link to post
Share on other sites

Hmm, it's not a PHP error :icon13: It's an MySQL problem :P

Maybe your port is wrong $dbserver -> $sbserver:portnumber (user/password could be wrong too, I'd assume you have checked that though :P).

Depending on what other options you have to connect to the database, check if you're allowed to connect using those methods (say phpMyAdmin or something like that), if that doesn't work, maybe get in touch with tech support :)

Share this post


Link to post
Share on other sites

Alright, well I decided to make the quick fix and MANUALLY create the database which is not what I was aiming for, because I wanted PHP to behave and work. So it works, and now I want to upload files (image specifically) and submit the name of the file to a database so I can later retrieve that and embed it into the site. Any ideas? I mean I guess I could always have me/other admins of the site manually enter that information but that would create more work that I don't want to do later on, so I just want this all working now.

 

I'm assuming it'll be something to do with

move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
   "../uploads/{$_FILES['uploadFile'] ['name']}")

 

EDIT: I might think I have it figured out, but then again I might not, I'll tell you when I test it.

 

EDIT: It did not work. Here's what I have

$image = $_FILES[image];
$imagename = $image[name];
$flash = $_FILES[flash];
$flashname = $flash[name];

echo $imagename;
echo $flashname;
$sql="INSERT INTO $dbgame (GameName, ImageName, FlashFileName, Description) VALUES ('$_POST[gamename]','$imagename','$flashname','$_POST[description]')";
if(!mysql_query($sql))
{
echo 'Error: ' . mysql_error();
}

It submits, Game Name, and Description, but just puts in blank values for Image Name and Flash File Name. Help?

Edited by Aerowind

Share this post


Link to post
Share on other sites

Hmm,

a.) escape string array indices (see "Array do's and don'ts" in the Arrays manual entry).

b.) check with the manual for handling file uploads (sorry for this, but can't assume you did everything right since you're having a problem :P, maybe forgot MAX_FILE_SIZE or set a wrong enctype in the form ;)).

c.) check if $_FILES['image']['error'] is 0 (file upload error messages), same for $_FILES['flash']['error'].

d.) I'd be careful with move_uploaded_file and a relative path, uploads will (most likely) go to the server's tmp directory (probably /tmp), so "../uploads/" is "/uploads" instead of "/var/www/uploads/" or wherever you want it to go ;)

Share this post


Link to post
Share on other sites

Try to logon (if you can on that server) and try to connect to your database using mysql client (command-line client). It is obvious either you cannot connect because of bad username/password or because or something else. Re-check hostname too. Some MySQL setups do not allow connections from anything else except localhost - think about that too.

Share this post


Link to post
Share on other sites

Hmm,

a.) escape string array indices (see "Array do's and don'ts" in the Arrays manual entry).

b.) check with the manual for handling file uploads (sorry for this, but can't assume you did everything right since you're having a problem :D, maybe forgot MAX_FILE_SIZE or set a wrong enctype in the form :wub:).

c.) check if $_FILES['image']['error'] is 0 (file upload error messages), same for $_FILES['flash']['error'].

d.) I'd be careful with move_uploaded_file and a relative path, uploads will (most likely) go to the server's tmp directory (probably /tmp), so "../uploads/" is "/uploads" instead of "/var/www/uploads/" or wherever you want it to go ;)

 

My problem is that all the guides for uploading files that are connected to databases are the files are getting uploaded to the database, sure, I want the file uploaded but I just need the name of the file stored in the database and nothing else. So MAX_FILE_SIZE, shouldn't be important, and it doesn't seem like I'd have to physically upload the file for it to retrieve the name (yet). Which is what I'm curious about.

Share this post


Link to post
Share on other sites

Well, if you are using a file upload input control you will upload the file even if only to some tmp directory and the $_FILES array will contain the data you want and "The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field" makes it clear that in order to upload (or even to fail(!) to upload) anything you'll have to set that control. Easiest way to see if it solves your problem would be to try it, because it certainly doesn't matter if you think it's important or not :confused: I'd say it's save to assume that if the official manual tells you to set that input field, they have a reason for it :lurker:

On the other hand if you are not uploading anything, then of course the $_FILES array will be empty.

Share this post


Link to post
Share on other sites

I figured out what I needed to figure out, I guess it was hard to explain what I wanted. I'm all set now, I just used $_POST to get what was in the name of the form field of both image and flash and then used basename().

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×