Connecting Tech Pros Worldwide Forums | Help | Site Map

multiple pages linked by hyperlink mysql query

Member
 
Join Date: Sep 2007
Posts: 49
#1: Sep 16 '07
Hi All,
I have a mysql database and 3 pages which queries and returns the data.
1st page(main.html) is just a form in html which takes query from the user and is connected to "form action="index.php"".
2nd page(index.php) has the mysql queries and gives a brief information(one line) about the user query. Now the index.php has a hyperlink to the third page(summary.php) which gives detailed information about the user query.
3rd page(summary.php) has detailed mysql statements.
all the three pages have
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2. $_SESSION['field'] = $_POST['keyword'];
  3. echo session_id();
and the session ids are identical for the pages.

Problem: when I provides the query term in the text box of the html page(main.html) and click on submit button, it directs me to the index.php page which provides me the one line information.....till here it goes fine, but when I click the hyperlink on the index.php page it does takes me to the summary.php page but there is information fetched from the mysql database, means the tables are empy.
It seems that its not fetching the data.

Any help.

thanks
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: Sep 17 '07

re: multiple pages linked by hyperlink mysql query


Heya, Kumar.

Sounds like you might be hitting a MySQL error.

Try adding this line after relevant queries:
Expand|Select|Wrap|Line Numbers
  1. echo mysql_error();
  2.  
Member
 
Join Date: Sep 2007
Posts: 49
#3: Sep 17 '07

re: multiple pages linked by hyperlink mysql query


Hi
thanks for the reply but I already inserted the error statement after each mysql statement like this:
$result2 = mysql_query($query2) or die('Query failed: ' . mysql_error());

do i need to again post the request from index.php to summary.php??

kumar
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#4: Sep 17 '07

re: multiple pages linked by hyperlink mysql query


Heya, Kumar.

$_POST will be empty unless you are submitting a form (and even then, you have to set method="post").

Did you mean to use $_GET['keyword'] instead?
Member
 
Join Date: Sep 2007
Posts: 49
#5: Sep 18 '07

re: multiple pages linked by hyperlink mysql query


hi pdmods...

sorry for the late reply...was busy with something...
yes , can I use the $_GET to retrieve the records from the third page...

if its possible(for guidance and suggestions) then I can send u my scripts through e-mail ....

thanks
kumar
Member
 
Join Date: Sep 2007
Posts: 49
#6: Sep 18 '07

re: multiple pages linked by hyperlink mysql query


Hi Pbmods,

this is my url string on the page index.php which collects the id and hyperlinks it to the summary.php.
Expand|Select|Wrap|Line Numbers
  1. while ($line1 = mysql_fetch_array($result1, MYSQL_ASSOC))
  2.         {
  3.             echo "<tr>";
  4.             echo "<td><center> <a href=\"summary.php?ID=".$line1['gene_id']."\">".$line1['gene_id']."</a></center></td>";    
  5.             echo "</tr>\n";
  6.         }
  7.  
  8.  
and now the summary.php has the following code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. print_r($_GET);
  3.  
  4. $link = @mysql_connect('localhost','root','xxxxxxxx');
  5.     if(!$link)
  6.     {
  7.         echo("<p>Unable to connect to the database server at this time.</p>");
  8.         exit();
  9.     }
  10.     else
  11.     {
  12.         //echo "Connected successfully\n";
  13.     }
  14.  
  15.     if(! @mysql_select_db('biology'))
  16.     {
  17.         echo("<p>Unable to locate the biology " .
  18.                  "database at this time.</p>");
  19.         exit();
  20.     }
  21.  
  22.  
  23.         $classi="select classification.c_group,classification.c_family,classification.c_subfamily from gene, classification where gene.gene_id=classification.gene_id and gene.gene_id='$keyword'";
  24.         $res_classi=mysql_query($classi) or die('Query failed: ' . mysql_error());
  25.         echo "<div align=\"center\"> <b>REPORT</b><br><br></div>";
  26.         echo "<table align=\"center\" border=\"1\" width=\"69%\" bgcolor=\"#FFFFFF\" cellspacing=\"1\" cellpadding=\"1\">\n";
  27.         while ($res_line = mysql_fetch_array($res_classi, MYSQL_ASSOC))
  28.         {
  29.             echo "<tr>";
  30.                 echo "<td width=\"30%\" bgcolor=\"#CCFF66\"><left><b>Group</b></left></td>";
  31.                 echo "<td><center>{$res_line['c_group']}</td>";
  32.                 echo "</tr>";
  33.             echo "<tr>";
  34.                 echo "<td width=\"30%\" bgcolor=\"#CCFF66\"><left><b>Family</b></left></td>";
  35.                 echo "<td><center>{$res_line['c_family']}</td>";
  36.                 echo "</tr>";
  37.             }
  38. echo "</table>";
  39.  
when i clicked on the hyperlink from index.php it echoed the "print_r($_GET)" = Array ( [ID] => 25 ) that means it is getting the gene id from the index.php but I am not able to pass the Array value to the below $keyword variable.
when I tried to assign this value of Array to the variable no sql wuery was executed and the tables were empty.
I am first time writing the code in php and i might be missing some very important points.
any suggestions
kumar
Member
 
Join Date: Sep 2007
Posts: 49
#7: Sep 19 '07

re: multiple pages linked by hyperlink mysql query


Hey pbmods,
I think I have solved the problem, what I did just added a foreach loop for the $_GET,
Expand|Select|Wrap|Line Numbers
  1. foreach ( $_GET as $keyword => $value ) {
  2. $keyword = $value;
  3. }
  4.  
and the value in $keyword is being passed to the sql statements......well its working now, but is this the right way to access the value of the array in $_GET??

read around 150 posts on this forum to get it working and cleared some of my basics too.......
Site ROCKS !!!!!!!!!!!!

kumar
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#8: Sep 19 '07

re: multiple pages linked by hyperlink mysql query


Heya, Kumar.

That will work. The idea though is to perform at least some kind of validation on your inputs before you use them.

Even something as simple as:
Expand|Select|Wrap|Line Numbers
  1. foreach( $_GET as $keyword => $value )
  2. {
  3.     $$keyword = mysql_real_escape_string($value, $dbConn);
  4. }
  5.  
where $dbConn is your MySQL connection resource.
Member
 
Join Date: Sep 2007
Posts: 49
#9: Sep 19 '07

re: multiple pages linked by hyperlink mysql query


Thanks for this valuable suggestion.

If i face any any other problems, then will mail u.

thanks
kumar
Reply