[SOLVED] Resource id

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
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

[SOLVED] Resource id

Post by Wldrumstcs »

Hi, I am making a site for my school and one page that I am making is an "Update your profile" page.

Here is my code:

Code: Select all

$username = "usernmae";
$password = "password";
$database = "db";

mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server."); 
$db = mysql_select_db("$database") or die ("Unable to select requested database.");

$subjects = mysql_query("SELECT subjects FROM teachers WHERE id='$_COOKIE[id]'");
$phone = mysql_query("SELECT phone FROM teachers WHERE id='$_COOKIE[id]'");
$email = mysql_query("SELECT email FROM teachers WHERE id='$_COOKIE[id]'");
$biography = mysql_query("SELECT biography FROM teachers WHERE id='$_COOKIE[id]'");

IF($_POST[submit]){
$encryptoldpassword = md5($_POST[oldpassword]);
$encryptnewpassword1 = md5($_POST[newpassword1]);
$encryptnewpassword2 = md5($_POST[newpassword2]);
IF($_POST[newpassword1] == "" AND $_POST[newpassword2] == "" AND $_POST[oldpassword] == ""){
$sql = "INSERT INTO teachers (subjects,phone,email,biography) VALUES ('$_POST[subjects]','$_POST[phone]','$_POST[email]','$_POST[biography]') WHERE id='$_COOKIE[id]'";
$result = mysql_query($sql);
}ELSEIF($encryptnewpassword1 == "$encryptnewpassword2" AND $encryptoldpassword == "$_COOKIE[password]"){
$sql = "INSERT INTO teachers (password,subjects,phone,email,biography) VALUES ('$encryptnewpassword2','$_POST[subjects]','$_POST[phone]','$_POST[email]','$_POST[biography]') WHERE id='$_COOKIE[id]'";
$result = mysql_query($sql);
}}
When I echo the $subject, $phone, $email, and $biography in text fields, it instead echos "Resource id #" then a number. What is the error? Thanks a ton!
Last edited by Wldrumstcs on Wed Nov 24, 2004 1:04 pm, edited 1 time in total.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Try using the following code:

Code: Select all

<?php

$subjects = mysql_query("SELECT subjects FROM teachers WHERE id='$_COOKIE[id]'");


      while($row = mysql_fetch_array($subjects)) 
      { 
        $subj_result = $row['subjects']; 
}

echo $subj_result;

?>
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Post by Wldrumstcs »

You fixed it. Thanks a lot for the help!
Post Reply