NameSilo

What's wrong with this? (Searching database for specific id)

Spaceship Spaceship
Watch
Impact
11
This is the code which im having problems with (its not all the code, so i am not missing the <?php, or a })

Code:
    $sql_query = "SELECT * FROM links WHERE id='$id'";
    //store the SQL query in the result variable
    $result = mysql_query($sql_query);

    if(mysql_num_rows($result))
    {
    //output as long as there are still available fields
    while($row = mysql_fetch_array($result))
    {
        $title = $row["title"];
        $url = $row["url"];
        $id = $row["id"];
        $status = $row["status"];
		$email = $row["email"];
   }


Im trying to get it to let you edit the information in the 'links' part of the database. The page before has this code:

Code:
<a href=\"editlink.php?id=$id\">Edit</a>

The id is right and everything, but the page always shows it as blank. I had it working a long time ago, then kind of forgot about it and now it doesnt work.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
Try this:

<a href=\"editlink.php?id=<?= $id ?>\">Edit</a>
 
0
•••
aren't you forgetting to get the id from the link?
try this query
PHP:
SELECT * FROM links WHERE id='".$_GET['id']."'";

or you shloud define your variable id before executing the query
PHP:
$id = $_GET['id'];

    $sql_query = "SELECT * FROM links WHERE id='$id'";
    //store the SQL query in the result variable
    $result = mysql_query($sql_query);

    if(mysql_num_rows($result))
    {
    //output as long as there are still available fields
    while($row = mysql_fetch_array($result))
    {
        $title = $row["title"];
        $url = $row["url"];
        $id = $row["id"];
        $status = $row["status"];
		$email = $row["email"];
   }
 
1
•••
Slewey said:
aren't you forgetting to get the id from the link?
try this query
PHP:
SELECT * FROM links WHERE id='".$_GET['id']."'";


Haha, thanks slewey, i knew it was something to do with that line.

Rep added. I see the rep also got you another green bar ;)
 
0
•••
Please remember to validate and secure your inputs folks, killaklown remember that is extremely insecure as it is right now :)

Just my piece of advice although the problem is solved :)

Matt
 
1
•••
killaklown said:
Haha, thanks slewey, i knew it was something to do with that line.

Rep added. I see the rep also got you another green bar ;)

np :tu:
 
0
•••
Appraise.net

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back