![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2004
Posts: 4
Rep Power: 0
![]() |
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 insertIt 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 ]) |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 5
![]() |
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
. 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.
__________________
_______________________________ BlazingWolf |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0
![]() |
I think you need to mysql_fetch_array($result)
__________________
Don't wound what you can't kill |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
No, he doesnt need mysql_fetch_array or mysq_fetch_assoc but he can make it easier on himself by using it...
__________________
|
|
|
|
|
|
#5 |
|
Expert Programmer
|
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.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|