Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 7th, 2004, 12:00 PM   #1
nickk
Newbie
 
Join Date: Oct 2004
Posts: 4
Rep Power: 0 nickk is on a distinguished road
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 ])
nickk is offline   Reply With Quote
Old Nov 7th, 2004, 1:08 PM   #2
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 207
Rep Power: 5 BlazingWolf is on a distinguished road
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
BlazingWolf is offline   Reply With Quote
Old Nov 7th, 2004, 1:14 PM   #3
Ade
Hobbyist Programmer
 
Ade's Avatar
 
Join Date: Oct 2004
Location: England, UK
Posts: 139
Rep Power: 0 Ade is an unknown quantity at this point
I think you need to mysql_fetch_array($result)
__________________
Don't wound what you can't kill
Ade is offline   Reply With Quote
Old Nov 7th, 2004, 2:15 PM   #4
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
No, he doesnt need mysql_fetch_array or mysq_fetch_assoc but he can make it easier on himself by using it...
__________________

tempest is offline   Reply With Quote
Old Nov 8th, 2004, 2:04 AM   #5
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:34 PM.

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