473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

multiple pages linked by hyperlink mysql query

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
Sep 16 '07 #1
8 2323
pbmods
5,821 Expert 4TB
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.  
Sep 16 '07 #2
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
Sep 16 '07 #3
pbmods
5,821 Expert 4TB
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?
Sep 17 '07 #4
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
Sep 18 '07 #5
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
Sep 18 '07 #6
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
Sep 18 '07 #7
pbmods
5,821 Expert 4TB
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.
Sep 18 '07 #8
Thanks for this valuable suggestion.

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

thanks
kumar
Sep 19 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bob Hotschins | last post by:
I've joined several columns from several tables, and I would like to perform a relevance match against these multiple columns. It looks something like this: SELECT * FROM table1 LEFT JOIN...
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
19
by: davidgordon | last post by:
Hi, I need some pointers/help on how to do the following if it possible: In my access db, I have the following: Tables: Products, Sub-Assembly, Product-Pack Table, Products
7
by: Bob Sanderson | last post by:
I have a php page which contains the code: echo "<tr>"; echo "<th>$JobNumber</th>"; echo "<td>$Description</td>"; echo "<td>$NSN</td>"; echo "<td>$Manufacturer</td>"; echo...
9
chumlyumly
by: chumlyumly | last post by:
Hello - Please help! I'm creating search pages using Dreamweaver 8, PHP, and MySQL database with Mac OS X. I think my code is good, but when I run my query, I come up with no data, even though...
0
chumlyumly
by: chumlyumly | last post by:
Hello scripters - OS: Mac OSX Language: PHP w/ MySQL database I've created an insert page where a user inputs his info, which then goes to four different tables in a MySQL database. The...
5
by: mramsay | last post by:
HI, I'm having alot of problems trying to figure out how to create drop down links from a hyperlink on my homepage. I have a hyperlink called Programs (this is for a community centre) When...
1
by: mramsay | last post by:
Hi there, I have a dynamic hyperlink Baseball. When the user select the hyperlink they are redirected to another page. After that I want to display information on the page from my linkstbl. ...
4
by: cjacks | last post by:
I have 2 tables linked by a common field. users ------ id ....more columns users_profiles -------------- users_id
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.