0

I am trying to display or return the Date value from a selected user

function mysql_select_one_data($database, $table, $data, $country, $phone){  
$conn = mysql_connect("localhost", "root", "test123");

    mysql_select_db($database, $conn) or die (mysql_error());
    $query = "SELECT DATE FROM Temp_Users WHERE Country = '+94' AND Phone = '1234539543';";

    $result = mysql_query($query) or die (mysql_error());

    if (mysql_num_rows($result) > 0) {
        // output data of each row
        while($row = mysql_fetch_assoc($result)) {
            echo "Date: " . $row["Date"]. "<br>";
        }
    } else {
        echo "0 results";
    }

    return $result;
    }

result:

Date:
Resource id #5

but when I do the query in phpmyadmin it returns

enter image description here enter image description here

I am new in Php and I Don't know what I am doing wrong, Thanks for your help.

kobbycoder
  • 682
  • 2
  • 10
  • 33
  • why marked as duplicated? this question is not linked to "Can I use MySQL and MySQLI together [closed] " – kobbycoder Apr 08 '15 at 22:07
  • *"I am new in Php and I Don't know what I am doing wrong"* - You're right. The duplicate stands. – Funk Forty Niner Apr 08 '15 at 22:18
  • i have edited my content and the result changed but still not displaying – kobbycoder Apr 08 '15 at 22:23
  • I need to see what you're using above `mysql_select_db($database, $conn) or die (mysql_error());` that you're not showing us. – Funk Forty Niner Apr 08 '15 at 22:24
  • I adjusted my answer – RST Apr 08 '15 at 22:26
  • and `$database` is defined as? including others. – Funk Forty Niner Apr 08 '15 at 22:27
  • `mysql_select_one_data` Edit: Oh, it's a custom function. Why don't you start by reading the manuals on both mysql and mysqli, setup your db connection correctly then try again. http://php.net/manual/en/function.mysql-connect.php and http://php.net/manual/en/function.mysqli-connect.php - Your code makes no sense. – Funk Forty Niner Apr 08 '15 at 22:29
  • Sorry, but your code makes no sense at all. Run it without the custom function and read up on the links I've given you above and don't mix MySQL APIs. – Funk Forty Niner Apr 08 '15 at 22:31
  • I just wanted to make a custom function bro to select data, I am new in php I just started yesterday and I dont know how to call data from page to page – kobbycoder Apr 08 '15 at 22:32
  • I don't even know how you're using `mysql_select_one_data()`. Instead of jumping into the deep end right away, get to learn how an MySQL API works. Use http://php.net/manual/en/function.mysqli-connect.php `mysqli_` setup the connection as they have it in there, query http://php.net/manual/en/mysqli.query.php and pass db connection to the query. Once you've done that, then you setup a custom function. – Funk Forty Niner Apr 08 '15 at 22:34
  • Thanks for your advice I will start reading it. <3 and I didnt notice it was mysqli_ i didnt see it though. – kobbycoder Apr 08 '15 at 22:37
  • You're welcome. I've reopened the question since you've changed everything to a single MySQL API. `mysql_` and `mysqli_` don't mix together, same for PDO, remember that ;-) – Funk Forty Niner Apr 08 '15 at 22:38

1 Answers1

0

change this

$query = "SELECT DATE FROM Temp_Users WHERE Country = \"+94\" AND Phone = \"1234539543\";";

to this

$query = "SELECT DATE FROM Temp_Users WHERE Country = '+94' AND Phone = '1234539543';";

Change the echo command to echo "Date: $row['DATE']<br>"

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
RST
  • 3,899
  • 2
  • 20
  • 33