0

Hie,
I'm trying to first pass a variable in a link from index.php to a page template.php. This variable is holding a table name of a data-base. Now my problem is to get this passed variable (which is a table name) from index.php to template.php and use the same to form the FROM parameter statement in the SELECT statement.

First the code in index.php page :

<meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
  <body background="b.jpg">
  <center>  <font color="#ffgg00" size="7">About dogs</font>  </center>
     <b>  <center>Click this link to go to <a href= "template.php?table_name=shepard">Shepard Dogs</a> Page </center> <br /><br />
 <center>Click this link to go to <a href= "template.php?table_name=comman">Comman Dogs</a> Page  </center>
   </b>
    </body>
</html>

Now, the code in template.php page :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=windows-1250">
  <meta name="generator" content="PSPad editor, www.pspad.com">
  <title></title>
  </head>
  <body background="b.jpg">
  <center>  <font color="#ffgg00" size="7">About dogs</font>  </center>
   <center>   <p>
<?php
       
include('db_login.php');
$connection = mysql_connect( $db_host, $db_username, $db_password );
if (!$connection){
   die ("Could not connect to the database1: <br />". mysql_error( ));
}

$db_select=mysql_select_db($db_database);
if (!$db_select){
   die ("Could not select the database2: <br />". mysql_error( ));
}

$query = "SELECT HEAD,DESCRIPTION FROM $table_name ";


$result = mysql_query( $query );
if (!$result){
   die ("Could not query the database3: <br />". mysql_error( ));
}  
while ($result_row = mysql_fetch_array(($result))){ 
       echo '<p>'.$result_row['HEAD'].'</p><p align="justify">'.$result_row['DESCRIPTION'].'</p>';
           
} 
mysql_close($connection);
?>

          </p>   </center>

  </body>
</html>

The code in db_login.php page:

<?php
$db_host='localhost';
$db_database='php_test';
$db_username='root';
$db_password='';
?>

But After clicking (any) link in index.php the page that occurs says :

Could not query the database3: 
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

I would be very obliged to receive help running this up !

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by paulrajj
0

Hi,

Though u r sending the values to template.php through url, u need to get and assign the values to variable $table_name in template.php.

Assign the url value to the varible $table_name through $_GET or $_REQUEST.

Try like this,

$table_name = $_REQUEST['table_name'];
   $query = "SELECT HEAD,DESCRIPTION FROM $table_name ";

Just echo the $query variable to check the value is assigned or not.

Hope this helps.

Edited by paulrajj: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.