link problem

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!

Moderator: General Moderators

Post Reply
lala
Forum Commoner
Posts: 27
Joined: Mon Jul 26, 2010 7:56 pm

link problem

Post by lala »

Hi, I'm newbie here. I would like to ask about link page problem in PHP.

Below is page.php
I want to link to mode 1 in page.php
so i state the link as 'page.php?mode=1', It doesn't work
This method is work in php 5.0.5, but i don't know why newer version of php cannot work.
Can anyone help me, thanks.

Code: Select all

<html>
<head><title>page</title></head>
<body>
<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
{
 die('Could not connect: ' . mysql_error());
}
mysql_select_db("db", $con);


  if($mode=='1')
{

$result = mysql_query( "SELECT field1, field2 FROM table" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
}
else if($mode=="2")
{
 $result = mysql_query( "SELECT name, address FROM table" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}

?>
</body>
</html>
Last edited by lala on Sun Aug 01, 2010 8:40 pm, edited 1 time in total.
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: link problem

Post by Grizzzzzzzzzz »

This method is work in php 5.0.5
really?

this line

Code: Select all

if($mode=='1')
you're checking if an unassigned, previously never mentioned before variable has a value, so it's going to fail regardless.

if you're after using the value in the url, i assume you're after the variable $_GET["mode"] instead.

so

Code: Select all

if($_GET["mode"] == 1)
would give better results. I'd recommend checking isset aswell
lala
Forum Commoner
Posts: 27
Joined: Mon Jul 26, 2010 7:56 pm

Re: link problem

Post by lala »

Hi Grizzzzzzzzzz, thanks for your reply.
I'm so happy, finally it's work.
Thank you very much.
Grizzzzzzzzzz wrote:
This method is work in php 5.0.5
really?
yes, It can work. But after I upgrade XAMPP to latest version, all tables cannot be displayed. I think all about pass values problem.
I still not sure how to add $_GET or $_REQUEST to switch case function, hope you can help me solve the next problem. But before that i have to rearrange my code before post here. Thanks again :D
Post Reply