Jump to content

[SOLVED] variables in SELECT statement


DeFActo

Recommended Posts

that is what i got:

<?php
$link = mysql_connect(' ', ' ', ' ');
mysql_select_db('kolekcijos');
function pirma(){
$query = "SELECT * FROM gylis WHERE id= ";
$result=mysql_fetch_assoc($query);
if ($result) {
$a=$result['gylis4'];
echo "$a";
}
    else{
    echo "There is no such a record.";
}
}
if (isset($_GET["name"])) $name = mysql_real_escape_string($_GET["name"]) or die ("nera");
if (isset($name)) echo "$name";
if (isset($name)) pirma();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ">
<html xmlns=" ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
<style type="text/css">
</style>
</head>

<body>
<table width="300px">
<tr>
<td width="100px"><a href="result2.php?name=Capsa">Capsa</a>
</td>
<td></td>
</tr>
<tr>
<td width="100px">Capsa1</td>
<td></td>
</tr>
<tr>
<td width="100px">Capsa2</td>
<td></td>
</tr>
</table>
</body>
</html>

but i need somehow to put that $name here:

$query = "SELECT * FROM gylis WHERE id=  ";

and result $a here:

<td width="100px">Capsa</td>
<td> result </td>

Any hint, please?

i've found some mistakes and updated the code:

<?php
$link = mysql_connect(' ', ' ', ' ');
mysql_select_db(' ');
if (isset($_GET["name"])) $name = mysql_real_escape_string($_GET["name"]) or die ("nera");
if (isset($name)) echo "$name";
if (isset($name)) {
$sql = "SELECT * FROM gylis WHERE id='$name'";
$query = mysql_query($sql);
$result=mysql_fetch_assoc($query);
if ($result) {
$a=$result['gylis4'];
echo "$a";
}
    else{
    echo "There is no such a record.";
};
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ">
<html xmlns=" ">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
<style type="text/css">
</style>
</head>

<body>
<table width="300px">
<tr>
<td width="100px"><a href="result2.php?name=capsa">Capsa</a>
</td>
<td></td>
</tr>
<tr>
<td width="100px">Capsa1</td>
<td></td>
</tr>
<tr>
<td width="100px">Capsa2</td>
<td></td>
</tr>
</table>
</body>
</html>

only thing i need is to get result $a in here:

<tr>
<td width="100px"><a href="result2.php?name=Capsa">Capsa</a>
</td>
<td> result </td>
</tr>

help please, because i am out of imagination  :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.