Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   2 Questions (http://www.programmingforums.org/showthread.php?t=1058)

nickk Nov 7th, 2004 11:00 AM

Hi,

I have 2 questions:

Firstly, I have the following function, but it doesnt work Sad
:

function insert($school_id, $email, $text, $pic) {
 * * $sql = "select class, first_name, second_name from yearbook where school_id = '$school_id'";
 * * $result = mysql_query($sql);
 * * $class = mysql_result($result, 1, "class");
 * * $first_name = mysql_result($result, 1, "first_name");
 * * $last_name = mysql_result($result, 1, "last_name");
 * * $pic = "../" . $class . "/" . $first_name . "-" . $last_name . ".jpg";

 * * $sql = "update yearbook set email = '$email', text = '$text', pic = '$pic' "
    * . "where school_id = '$school_id'";
 * * if(mysql_query($sql)) {
 * * * * *echo "<b>Text and picture sucessfully uploaded!</b>\n";
 * * * * *return 1;
 * * } else {
 * * * * *echo "<b>Error submitting text and picture to the database, go back and try again</b>\n";
 * * * * *return 0;
 * * }
} //end function insert


It gives me the following errors:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/home/nickk/public_html/yearbook/provide/upload.php on line 228

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/home/nickk/public_html/yearbook/provide/upload.php on line 229

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /usr/home/nickk/public_html/yearbook/provide/upload.php on line 230

and it doesnt add the proper values for "pic" to the database Sad

Secondly, I'm having problems uploading files (pictures to be exact) with PHP. Does anyone know how this is done?

Thanks, Nick

(added a little code formatting, courtesy of your friendly neighborhood Spider Man .. [ AKA: SykkN ])

BlazingWolf Nov 7th, 2004 12:08 PM

I can't help you with the picture uploading but I can tell say you are trying run an query without ever connecting to the databse :P.

Before you run the query you need to have

:

$dbconnect = mysql_connect('localhost', 'root', 'mypassword');
mysql_select_db('mydb');


And when your run your query you need to include the vaible that has your connection info

:

$result = mysql_query($command,$dbconnect);

And as a good habit after you run your query you want to close the connection to the database.

:

mysql_close($dbconnect);

I can't help you with mysql_result because I've never used it before and I can't figure what your trying to do with it.

Ade Nov 7th, 2004 12:14 PM

I think you need to mysql_fetch_array($result)

tempest Nov 7th, 2004 1:15 PM

No, he doesnt need mysql_fetch_array or mysq_fetch_assoc but he can make it easier on himself by using it...

kurifu Nov 8th, 2004 1:04 AM

mysql_result is perfectly acceptable. Whenever you get an error such as that it means that your query was rejected by the server. You need to debug and figure out why, I would suggest using print_r( $query_handle ) or mysql_error( ) for more information.

In this case it looks to simply be that you forgot to connect to the database server. mysql_connect() is what you want for that.


All times are GMT -5. The time now is 6:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC