Hi,
My script lets you choose if you want to view table 1 or table 2 in mysql after you selected 1 or 2 from the drop down menu and press submit.
The problem is if you run the script for the very first time it gives an error at the query. cause no one has told the code where to go and look.
How can I make it so it does not run the script before you click submit or have it select and display the first table until your select?
Here my script I have marked the section that is giving the problem.. with *********my text*********** ********
Thanks
[PHP]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>view</title>
</head>
<body>
<?PHP
$self = $_SERVER['PHP_SELF'];
$table = $_POST['table'];
?>
<form action="<?php echo( $self ); ?>" method="post">
<select name="table">
<option value="my_table ">1</option>
<option value="my_table 2">2</option>
</select>
<label></label>
<br>
<input type="submit" value="submit"> </form>
<?php
If( $self)
{
$conn=@mysql_co nnect( "localhost" , "design", "superdesig n")
or die( "Err:Conn") ;
$rs= @mysql_select_d b ( "gptesting_co_z a_-_italchamdir", $conn )
or die ( "Err:Db");
# Create the query ************ How do I select a row? I tried stuff and codes but
#cannot get it to work*********** **What happen here is because $table is not
#specified the very first time you come to the page it gives an error..I just need to #somehow do like a "else if select first_name from a ************
$sql="select first_name from $table";
# this is what i tried $sql="select first_name from $table" else if ("select first_name from $table");
#execute
$rs = mysql_query( $sql, $conn );
#write data
While( $row = mysql_fetch_arr ay( $rs ) )
{
echo( "ID: " . $row["first_name "] );
echo(" - First Name: " . $row["first_name "] . "<br>") ;
}
}
?>
</body>
</html>
[/PHP]
My script lets you choose if you want to view table 1 or table 2 in mysql after you selected 1 or 2 from the drop down menu and press submit.
The problem is if you run the script for the very first time it gives an error at the query. cause no one has told the code where to go and look.
How can I make it so it does not run the script before you click submit or have it select and display the first table until your select?
Here my script I have marked the section that is giving the problem.. with *********my text*********** ********
Thanks
[PHP]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>view</title>
</head>
<body>
<?PHP
$self = $_SERVER['PHP_SELF'];
$table = $_POST['table'];
?>
<form action="<?php echo( $self ); ?>" method="post">
<select name="table">
<option value="my_table ">1</option>
<option value="my_table 2">2</option>
</select>
<label></label>
<br>
<input type="submit" value="submit"> </form>
<?php
If( $self)
{
$conn=@mysql_co nnect( "localhost" , "design", "superdesig n")
or die( "Err:Conn") ;
$rs= @mysql_select_d b ( "gptesting_co_z a_-_italchamdir", $conn )
or die ( "Err:Db");
# Create the query ************ How do I select a row? I tried stuff and codes but
#cannot get it to work*********** **What happen here is because $table is not
#specified the very first time you come to the page it gives an error..I just need to #somehow do like a "else if select first_name from a ************
$sql="select first_name from $table";
# this is what i tried $sql="select first_name from $table" else if ("select first_name from $table");
#execute
$rs = mysql_query( $sql, $conn );
#write data
While( $row = mysql_fetch_arr ay( $rs ) )
{
echo( "ID: " . $row["first_name "] );
echo(" - First Name: " . $row["first_name "] . "<br>") ;
}
}
?>
</body>
</html>
[/PHP]
Comment