Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi all
my problem is abroblem with php
i wrote a code to do this
1-take the value of $_GET["id] from the link
2- bring the the that had the same id in the database
here is the code
HTML
<html>
<meta charset="utf-8">
</html>
include ('config.php');
$id=$_get["id"];
if (!$result) {
    die('Query failed: ' . mysql_error());
}
$sql = ('SELECT id as id, filename, link 
        FROM   link
        WHERE  id =$id');
$result = mysql_query ($sql);
if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
//       then create $userid, $fullname, and $userstatus
while ($row = mysql_fetch_assoc($result)) {
    echo $row["id"];
    echo $row["filename"];
    echo $row["link"];
}

mysql_free_result($result);

?> 

my problem is that $id in the line 12 doesn't give value because it is wrote in string
what can i do
Posted

Hi.....

Replace your code

$sql = ('SELECT id as id, filename, link 
        FROM   link
        WHERE  id =$id');



by

$sql = ("SELECT id as id, filename, link 
        FROM   link
        WHERE  id ='".$id."'");


Above code produce output as....


SQL
SELECT id as id, filename, link
        FROM   link
        WHERE  id = '$id value'
 
Share this answer
 
Convert the string to int - use intval. For more information, see here[^].
 
Share this answer
 
I know nothing about PHP but I believe you should replace
PHP
$sql = ('SELECT id as id, filename, link 
        FROM   link
        WHERE  id =$id');
with
PHP
$sql = ('SELECT id as id, filename, link 
        FROM   link
        WHERE  id = ' . $_get["id"]);
This assumes that $_get["id"] returns a string.
 
Share this answer
 
Comments
[no name] 16-Oct-11 8:07am    
I tried and it did't work
André Kraak 16-Oct-11 8:11am    
So what is the value of the $sql?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900