0

I'm trying to extract a string field, under a column called "whenadded", of a mysql table (called "values") with a php script. I'm using this code:

<?php
  include("common.php");
  $link=dbConnect();
  $name = safe($_POST['name']);
  $mysqldate = mysql_query("SELECT `whenadded` FROM `values` WHERE `name`= `$name`");
?>

In this table I have only two columns: name and whenadded. Both are strings. If I try to display the result of $mysqldate, I don't see anything (white field).


[SOLVED] At the end I solved using this:

include("common.php");
    $link=dbConnect();
    $name = safe($_POST['name']);

    $query = mysql_query("SELECT * FROM $dbName . `valorigps` WHERE name = '$name'");

    while($row = mysql_fetch_array($query))
    {
        echo  $row['whenadded'];      
    }
  • How do you try to display? – u_mulder Oct 09 '14 at 18:48
  • 1
    `$name` should be in single quotes, '$name' – Funk Doc Oct 09 '14 at 18:48
  • Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide. – Jay Blanchard Oct 09 '14 at 18:50
  • How do you display the result? Please write full code! – akshaynagpal Oct 09 '14 at 18:56

1 Answers1

0

your query string shoud be this:

$mysqldate = mysql_query("SELECT whenadded FROM values WHERE name= '$name'");

or

$mysqldate = mysql_query("SELECT whenadded FROM values WHERE name= '{$name}'");

no need of quote for table columns!

Peyman.H
  • 1,819
  • 1
  • 16
  • 26