0

I'm using the following snippet:

mysql_connect($host,$user,$password);
$sql = "SELECT FROM ec_opps WHERE id=" . $_GET["UPDATE"];
$item = mysql_query($sql);
mysql_close();
print_r($item);

To try and retrieve data based on the UPDATE value. This value prints to the page accurately, and I know the IDs I'm requesting exist in the database. The print_r($item) function returns no result, not even an empty array, so I'm confused as to where I'm going wrong.

I know it isn't best practise to use MySQL like this, but I'm doing it for a reason.

ES-AKF
  • 103
  • 1
  • 2
  • 5

4 Answers4

0

Replace with this code

 $sql = "SELECT * FROM ec_opps WHERE id=" . $_GET["UPDATE"];
vignesh.D
  • 766
  • 4
  • 18
0

You are missing * in your query.

You need to use: SELECT * FROM instead of SELECT FROM

Muhammad Bilal
  • 2,106
  • 1
  • 15
  • 24
0

There is a syntax error in the query. It is missing *. Try with -

$sql = "SELECT * FROM ec_opps WHERE id='" . $_GET["UPDATE"] . "'";

Please avoid using mysql. Try to use mysqli or PDO. mysql is deprecated now.

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
0

You're missing columns to be selected in your SELECT query, or you can select all by putting *, which means selecting all column.

$sql = "SELECT * FROM ec_opps WHERE id='" . $_GET["UPDATE"]."'";

Your query is very prone to SQL injections.

You should refrain from using MySQL. It's deprecated already. You should be at least using MySQLi_* instead.

<?php
/* ESTABLISH CONNECTION */
$mysqli = new mysqli($host, $user, $password, $database);

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT column1, column2 FROM ec_opps WHERE id=?"; /* REPLACE NEEDED COLUMN OR ADD/REMOVE COLUMNS TO BE SELECTED */

if ($stmt = $mysqli->prepare($query)) {

    $stmt->bind_param("s", $_GET["UPDATE"]); /* BIND GET VALUE TO THE QUERY */
    $stmt->execute(); /* EXECUTE QUERY */
    $stmt->bind_result($column1,$column2); /* BIND RESULTS */

    while ($stmt->fetch()) { /* FETCH RESULTS */
        printf ("%s (%s)\n", $column1, $column2);
    }

    $stmt->close();
}

$mysqli->close();

?>
Community
  • 1
  • 1
Logan Wayne
  • 6,001
  • 16
  • 31
  • 49