PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
When you browse my website I liked to have this while browsing domain.com/index.php?id=1
When accessing id?=1 it will give me the url from the table ‘2k5’ defined by the id. So when the page has generated I can just use this <? echo $print_id ?> to display the url for id?=1.
$connection = mysql_pconnect("$host","$username","$password") or die ("Error Connecting the Database ".mysql_error."");
$db = mysql_select_db("$database", $connection) or die("Could not select the SQL Database.");
//connects to database
$result = mysql_query("SELECT url FROM 2k5 WHERE id='$_GET[id]'");
if (!$result) {
die('Error:' . mysql_error());
}
while ($result=mysql_fetch_array($result)){
$print_id = $result[????];
}
Can anyone please give me some advice? Please note that im not a hardcore coder!
Please, can you make a little code for me, I've had looked at this code for some while, and now im really sick and tired of it, if you now what i mean?
// you don't need double quotes to expand variables, also mysql_error is a function so it needs to be mysql_error()
$connection = mysql_pconnect($host,$username,$password) or die ("Error Connecting the Database ".mysql_error());
// You do not need quotes on the variable again
$db = mysql_select_db($database, $connection) or die("Could not select the SQL Database.");
//connects to database
// You need to do it like this:
$result = mysql_query('SELECT url FROM 2k5 WHERE id=\''.(int)$_GET['id'].'\' limit 1');
if (!$result) {
die('Error:' . mysql_error());
}
while ($result=mysql_fetch_array($result)){
$print_id = $result[????];
}
Please use [php] tags from now on
Last edited by josh on Wed Feb 15, 2006 12:28 pm, edited 2 times in total.
// you don't need double quotes to expand variables, also mysql_error is a function so it needs to be mysql_error()
$connection = mysql_pconnect($host,$username,$password) or die ("Error Connecting the Database ".mysql_error());
// You do not need quotes on the variable again
$db = mysql_select_db($database, $connection) or die("Could not select the SQL Database.");
//connects to database
// You need to do it like this:
$result = mysql_query('SELECT url FROM 2k5 WHERE id=\''.(int)$_GET['id'].'\' limit 1');
if (!$result) {
die('Error:' . mysql_error());
}
while ($result=mysql_fetch_array($result)){
$print_id = $result[????];
}