Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I think this is easy but can't figure out !

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Hi,

My problem is this I have an insert statement that works fine and all the relevant info goes into my database.
The first two fields are id_premium & user_id. Once this info is entered the next thing i want to do is select the id_premium where user_id = whatever but i keep getting
Resource #7 to echo out instead of the id_premium number.

Could someone please have a look at the code i'm baffled

Regards
Graham

if (isset($_POST['submit']))
// Check if the form has been submitted
{

// Connect to the database
require_once ('../mysql_connect3.php');

$a = $_SESSION['user_id'];
$b = escape_data($_SESSION['qualifications']);
$c = escape_data($_SESSION['experience']);
$d = escape_data($_SESSION['additional_locations']);
$e = escape_data($_SESSION['availability']);
$f = escape_data($_SESSION['rate_per_hour']);
$g = escape_data($_SESSION['additional_number']);
$h = escape_data($_SESSION['email_address']);
$i = escape_data($_SESSION['additional_information']);

$j = escape_data($_SESSION['county']);
$k = escape_data($_SESSION['town']);
$l = escape_data($_SESSION['contact_name']);
$m = escape_data($_SESSION['contact_number']);






// Add the premium add
$query1 = "INSERT INTO premium
(
user_id,
qualifications,
experience,
additional_locations,
availability,
rate_per_hour,
additional_number,
email_address,
additional_information
)
VALUES
(
'$a',
'$b',
'$c',
'$d',
'$e',
'$f',
'$g',
'$h',
'$i'
)";





$result1 = @mysql_query($query1);





if ($result1)
{

********** Problem *****************

// Select the id_premium from the premium table before inserting into the users table
$query2 = "SELECT id_premium FROM premium WHERE user_id='$a'";
$result2 = @mysql_query ($query2);


echo"$result2"; // This outputs Resource #7




echo '</div>'; // This div is to shut the header div early NB !!
include('includes/footer.htm');
exit();
}
 
That line should output something along the lines of "Resource 7".

mysql_query(), when used with a SELECT query, returns a handle, similar in many ways to a file handle. And like a file handle, you have to fetch the data out of the handle. Take a look at the example code on the PHP online manual pag for mysql_fetch_assoc() or mysql_fetch_array().


As an aside, see the warning on the PHP online manual page that deals with the "@" error-control operator:

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks alot sleipnir214 I figures it out with your guidance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top