Jump to content

Recommended Posts

Good day:

 

Im trying to assign a variable to each link to get passed to another page. The variable is selected from a table in the database, and as each link is generated it has the proper variable and the next page can retrieve the correct articles type from the database. The code is not showing an error but it is not sending the variable to the other page "or the next page is not retrieving it. This is the code for both pages, the one that creates the links with the variable and the page that supposed to retrieve the articles from the database and display it.

 

<?php
   $connection = mysql_connect("localhost",
        "uername",
        "password");

    mysql_select_db("articles", $connection); 
$query="SELECT name, articlesid FROM artiles_description WHERE letter='a' AND place=1";
$result=mysql_query($query);

$num=mysql_numrows($result);


mysql_close();;
?>
<table width="300" border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">A</font></th>

</tr>

<?php
$f3='articles.php';
$i=0;
while ($i < $num) {
$backgroundclass = (($i % 2) == 0) ? 'gray' : 'white';
$f1=mysql_result($result,$i,"name");
$f2=mysql_result($result,$i,"articlesid")

?>

<tr class='<?php echo $backgroundclass ?>'>
<td align="center"><font face="Arial, Helvetica, sans-serif"><?php echo  "<a href=\"$f3\"?id='$f2' target=\"_self\">$f1</a>"; ?></font></td>

</tr>

</td>

<?php
$i++;
}
?>
</table>
<td>

 

and the second page

 

<html>
<head>
<title>Articles</title>

<style>
.gray { backgroundcolor: gray; }
.white { backgroundcolor: white; }
</style>

</head>
<body>
<?php
$_GET[‘aid’];
  $connection = mysql_connect("localhost",
        "username",
        "password");

    mysql_select_db("articles", $connection);
$query="SELECT * FROM articles WHERE id='aid'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
<table border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Article</font></th>
<th><font face="Arial, Helvetica, sans-serif">Year</font></th>
<th><font face="Arial, Helvetica, sans-serif">Description</font></th>
<th><font face="Arial, Helvetica, sans-serif">Location</font></th>

</tr>

<?php
$i=0;
while ($i < $num) {
$backgroundclass = (($i % 2) == 0) ? 'gray' : 'white';
$f1=mysql_result($result,$i,"article");
$f2=mysql_result($result,$i,"year");
$f3=mysql_result($result,$i,"description");
$f4=mysql_result($result,$i,"location");
$f5=mysql_result($result,$i,"link")
?>

<tr class='<?php echo $backgroundclass ?>'>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
<td ><font face="Arial, Helvetica, sans-serif"><?php echo  "<a href=\"$f5\" target=\"_blank\">$f4</a>"; ?></font></td>
</tr>
<tr>
</tr>

<?php
$i++;
}
?>
</body>
</html>

 

Any help will be appreciated. Thanks

Link to comment
https://forums.phpfreaks.com/topic/229770-passing-and-getting-a-variable/
Share on other sites

I just looked again, usually you assign a variable to the get and use that variable into your select statement.

 

be sure you have the correct single quotes as well, also escape bad characters from any input

$aid = mysql_real_escape_string($_GET['aid']);


$query="SELECT * FROM articles WHERE id='$aid'";

I got this error messages:

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket

 

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in

 

It connects, but the variable is not passing from the first page. The variable has to be assigned from the database into the links as the articles hyperlinks are created. That way when the user clicks on the hyperlink, it goes to a general format page but retrieves the information according to that variable that was passed.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.