Jump to content

How to select a peace of information from mysql?


Jragon

Recommended Posts

Hey guys,

 

I was wondering how i could get a specific peace of information about the user?

 

I know how to select the basics but i dont know how to get a specific peace of info

 

Thanks

 

Jraogn

Link to comment
Share on other sites

Ok so i have done that this is my function:

 

<?php
function getsalt($user){
    include("connect.php");
    $query = 'SELECT salt FROM user WHERE username = "$user"';
    $salt = mysql_query($query);
    return $salt;
}
echo getsalt('rory');
?>

 

But all I'm getting is:

Resource id #4

 

Thanks

 

Jragon

Link to comment
Share on other sites

You still need to make data from that.

<?php
function getsalt($user){
    include("connect.php");
    $query = 'SELECT `salt` FROM user WHERE username = "$user"';
    $saltres = mysql_query($query);
    $saltdata = mysql_fetch_object($saltres);
    return $saltdata->salt;
}
echo getsalt('rory');
?>

Link to comment
Share on other sites

Looks like it should work...

 

What output does this give:

<?php
function getsalt($user){
    include("connect.php");
    $query = 'SELECT `salt` FROM user WHERE username = "$user"';
    $saltres = mysql_query($query);
    $saltdata = mysql_fetch_object($saltres);
    print_r($saltdata);
    return $saltdata->salt;
}
echo getsalt('rory');
?>

Link to comment
Share on other sites

This is my dumb for the table

 

-- phpMyAdmin SQL Dump

-- version 3.2.4

-- http://www.phpmyadmin.net

--

-- Host: localhost

-- Generation Time: Jul 22, 2010 at 10:19 AM

-- Server version: 5.1.41

-- PHP Version: 5.3.1

 

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

 

--

-- Database: `visualupload`

--

 

-- --------------------------------------------------------

 

--

-- Table structure for table `user`

--

 

CREATE TABLE IF NOT EXISTS `user` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `firstname` varchar(25) NOT NULL,

  `lastname` varchar(25) NOT NULL,

  `username` varchar(25) NOT NULL,

  `password` varchar(32) NOT NULL,

  `dob` date NOT NULL,

  `gender` varchar(1) NOT NULL,

  `salt` varchar(12) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

 

--

-- Dumping data for table `user`

--

 

INSERT INTO `user` (`id`, `firstname`, `lastname`, `username`, `password`, `dob`, `gender`, `salt`) VALUES

(1, 'Rory', 'Anderson', 'rory', 'hello', '2010-07-07', 'm', 'akldflasjkdf');

 

 

 

 

 

 

 

 

 

Nothing still

 

Link to comment
Share on other sites

$query = "SELECT `salt` FROM `user` WHERE `username` = '$user'";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$data = mysql_fetch_object($result);
print_r($data);
$salt = $data->salt';
print $salt;

 

Well, try this

Link to comment
Share on other sites

Use while...

 

$query = "SELECT `salt` FROM `user` WHERE `username` = '$user'";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
while ($data = mysql_fetch_object($result))
{
echo $data->salt;
}

Link to comment
Share on other sites

its half working now

what i get

 

stdClass Object ( [salt] => akldflasjkdf ) akldflasjkdf

This is not half working, this is already working.

You first print_r the object and then print salt. They were both printed, if you leave out the print statements and insert return $salt it should work, I see point in using a loop here, as you only want one result. (if you are going to use a loop, make sure you include LIMIT 1 in your query)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.