Jump to content

Possible ISSET coding error


aztec

Recommended Posts

Hello

 

This is some code I have been working on for some while.

 

The first part works fine and puts up the select box, allows you to select and to submit. After pressing submit the page refreshes and put the ?select=XX&select=submit into the URL.

 

The first select in the URL is equal to the ID from the database of the selected person.

 

The second isset is returning nothing so the second part is never being executed even after the select button is pressed.

 

I think I have an error in the second isset code.

 

Any help would be appreciated

 

Kind Regards

 

<?
// Connect database
mysql_connect("localhost","XXXX","");
mysql_select_db("YYY"); 

// If submitted, check the value of "select". If its not blank value, get the value and put it into $select.
if(isset($select)&&$select!=""){
$select=$_GET['select'];
}
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
</head>
<body>
<form id="form1" name="form1" method="get" action="<? echo $PHP_SELF; ?> ">
PERSON :
<select name="select">
<option value="">--- Select ---</option>
<?
// Get records from database (table "name_list").
$list=mysql_query("select * from name_list order by id asc");

// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?>
<option value="<? echo $row_list['id']; ?>" <? if($row_list['id']==$select){ echo "selected"; } ?>><? echo $row_list['name']; ?></option>
<?
// End while loop.
}
?>
</select> 
<input type="submit" name="Submit" value="Select" />

</form>
<hr>
<p>
<?
// If you have selected from list box.
if(isset($select)&&$select!="")
{
// Get records from database (table "name_list").
$result=mysql_query("select * from name_list where id='$select'");
$row=mysql_fetch_assoc($result);
?>
Information about <strong><? echo $row['name']; ?></strong> FAMILY...</p>
<p>........................................<br>
........................................<br>
........................................
<?
// End if statement. 
}

// Close database connection.
mysql_close();
?>
</p>
</body>
</html>

Link to comment
Share on other sites

Hello

 

Thanks for your response but if you look at the seventh line of the code it is set to $_Get, or are you referring to somewhere else in the code.

 

I have take on board your comments about updating the code to superglobals once I get it working.

 

Regards

Link to comment
Share on other sites

Tidied up your code a bit, try:

<?php
// Connect database
mysql_connect("localhost","XXXX","");
mysql_select_db("YYY");


if(isset($_GET['select']) && !empty($_GET['select']))
{
    $select = $_GET['select'];

    // Get records from database (table "name_list").
    $result = mysql_query("select * from name_list where id='$select'");
    $row    = mysql_fetch_assoc($result);

    $content = 'Information about <strong>' . $row['name'] . '</strong> FAMILY...</p>
<p>........................................<br>
........................................<br>
........................................';

}
else
{
    $content = 'No Name Selected';
}
?>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form id="form1" name="form1" method="get" action="<? echo $_SERVER['PHP_SELF']; ?> ">
PERSON :
<select name="select">
<option value="">--- Select ---</option>
<?php
// Get records from database (table "name_list").
$list = mysql_query("select * from name_list order by id asc");

// Show records by while loop.
while($row_list = mysql_fetch_assoc($list))
{
    $opt = '<option value="' .$row_list['id'] . '"';

    if($row_list['id'] == $select)
    {
        $opt .= ' selected="selected"';
    }

    $opt .= '>' . $row_list['name'] . "</option>\n";

    echo $opt;
}
?>
</select>
<input type="submit" name="Submit" value="Select" />

</form>
<hr>
<p><?php echo $conent; ?></p>
</body>
</html>

Link to comment
Share on other sites

Hello

 

I have finally got wildtenn88's code to work.

 

There are still some associated problems that I am working on. But for now I will mark this topic as solved.

 

BUT THE SOLVED TAG AS DISAPPEARED

 

Many thanks to wildteen88 for the help provided.

 

Kind Regards

Link to comment
Share on other sites

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.