franknu Posted November 14, 2006 Share Posted November 14, 2006 ok, I want to create a link to another page within the database same table( all the info is on the same row)the problem that i am having is undefine index:[code=php:0]$BusinessName = ($_POST['BusinessName']);$Keyword =($_POST['Keyword']); $Picture1 = ($_POST['Picture1']); $Headline = ($_POST['Headline']); $Slogan2 = ($_POST['Slogan2']); $Description1 =($_POST['Description1']); $Description2 = ($_POST['Description2']); $Description3= ($_POST['Description3']); $Contact2 = ($_POST['Contact2']); $Picture2 = ($_POST['Picture2']); $Picture3 = ($_POST['Picture3']); [/code] if i add isset it would work but i was told that isset would only return true or false value. when i add isset works but dont return any value..[code=php:0]Here is my link:$bn = $row['BusinessName'];echo "<a href=\"bizwebpage2.php?BusinessName=$bn\">$bn</a>";[/code]here is the page where it takes me[code=php:0]<?php $host = "localhost"; $username = "localhost"; $password = "abc123"; $database = "contacts"; $db = mysql_connect($host, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $BusinessName = ($_POST['BusinessName']);$Keyword =($_POST['Keyword']); $Picture1 = ($_POST['Picture1']); $Headline = ($_POST['Headline']); $Slogan2 = ($_POST['Slogan2']); $Description1 =($_POST['Description1']); $Description2 = ($_POST['Description2']); $Description3= ($_POST['Description3']); $Contact2 = ($_POST['Contact2']); $Picture2 = ($_POST['Picture2']); $Picture3 = ($_POST['Picture3']); if($BusinessName) { $query = "SELECT * FROM business_info WHERE `BusinessName`= '$BusinessName' ";$result = mysql_query($query) or die (mysql_error()); }?> <table> <tr> <td> <table> <tr> <td valign="top"> <table> <tr> <td valign="top"> <table> <tr> <td><?php echo"$Logo"; ?></td> </tr> <tr> <td valign="top"><h2><?php echo "<h2>$BusinessName</h2>"; ?></h2></td> </tr> <tr> <td valign="top"><?php echo "$Description1"; ?></td> </tr> <tr> <td valign="top"><?php echo "$Description2"; ?></td> </tr> <tr> <td valign="top"><?php echo "$Description3"; ?></td> </tr> <tr> <td valign="top"><?php echo "$Contact2"; ?></td> </tr> </table> </td> </tr> </table> </td> <td valign="top"> <table> <tr> <td> </td> </tr> <tr> <td valign="top"><?php echo"<img src='$Picture2' width='200' height='250'>"; ?> </td> </tr> <tr> <td valign="top"> <?php echo "<img src='$Picture3' width='200' height='250'>"; ?> </td> </tr> </table> </td> </tr> </table> <table border='1'> <tr> <td> </td> </tr> </table> </td> </tr> </table> <?php ?> [/code] Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/ Share on other sites More sharing options...
Jenk Posted November 14, 2006 Share Posted November 14, 2006 It means the index does not exist, ergo the POST field was not submitted.Use an if statement to check your requested fields are there.[code]<?phpif (!isset($_POST['field'])) die('You must provide a value for \'field');?>[/code] Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124468 Share on other sites More sharing options...
CheesierAngel Posted November 14, 2006 Share Posted November 14, 2006 if you do not want to test if they all are set and you dont wanna quit your script you could also use:[code]<?php$BusinessName = @$_POST['BusinessName'];$Keyword =@$_POST['Keyword']; $Picture1 = @$_POST['Picture1']; $Headline = @$_POST['Headline']; $Slogan2 = @$_POST['Slogan2']; $Description1 =@$_POST['Description1']; $Description2 = @$_POST['Description2']; $Description3= @$_POST['Description3']; $Contact2 = @$_POST['Contact2']; $Picture2 = @$_POST['Picture2']; $Picture3 = @$_POST['Picture3']; ...?>[/code]If the var was not submitted and/or an error occurs then the @$var will be null, else the $var value will be assignedMODIFICATION:You can work even alot shorter if you want:[code]<?php$submittedVars = array();foreach($_POST as $key => $value) { $submittedVars[$key] = $value;}?>[/code]Now you can print your table something like:[code] ...<td><?php echo @$submittedVars['DescriptionA']; ?></td><td><?php echo @$submittedVars['DescriptionB']; ?></td>...[/code] Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124474 Share on other sites More sharing options...
Jenk Posted November 14, 2006 Share Posted November 14, 2006 'Angel, you first problem is poor programming (sweeping errors under the carpet does not make them go away.) and the second is only hindering.. if you are going to transfer from $_POST to $submittedVars you can just do $submittedVars = $_POST, or just plain use @$_POST on every line, which leads me back to my first point. Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124491 Share on other sites More sharing options...
CheesierAngel Posted November 14, 2006 Share Posted November 14, 2006 It's indeed sweeping the errors under the carpet but alot shorter to write.Using the @ in your code means you know there can be an error and if so use null instead of terminating the script.The transfer from $_POST to $submittedVars is indeed unusefull in this example. But when the vars are hoovering around different functions and classes it's more obvious to make a copy of the $_POST variables. Therefor i mostly copy the array even when i don't use these in vars in other functions and or classes. (kind of a 'bad' habbit) Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124506 Share on other sites More sharing options...
franknu Posted November 14, 2006 Author Share Posted November 14, 2006 make sense now, i am not submitting the these variables, i have a page call bizwebpage2.php when the user submit their search criteria a list of business display if they want to know more about that particular business they clink on the link [code=php:0] $bn = $row['BusinessName'];echo "<a href=\"bizwebpage2.php?BusinessName=$bn\">$bn</a>"; [/code], maybe i am doing the whole thing wrong Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124507 Share on other sites More sharing options...
franknu Posted November 14, 2006 Author Share Posted November 14, 2006 i already tried $BusinessName = @$_POST['BusinessName'];and i got the same problem. i just realized, is because i am not submitting the variables, they are in another page i just need to use them to display the data tha it is in those colums in another page any advise please Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124512 Share on other sites More sharing options...
Jenk Posted November 14, 2006 Share Posted November 14, 2006 Advice: Be more clear and descriptive with your questions.. Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124526 Share on other sites More sharing options...
franknu Posted November 14, 2006 Author Share Posted November 14, 2006 Ok, when the user click on the link which is on a page call business_display.php[code=php:0]this is the link on page business_display.php$bn = $row['BusinessName'];echo "<a href=\"bizwebpage2.php?BusinessName=$bn\">$bn</a>";[/code]user click on the link and it takes them to pagebizwebpage2.phphere is the code for bizwebpage2.php[code=php:0]<?php $host = "localhost"; $username = "localhost"; $password = "abc123"; $database = "contacts"; $db = mysql_connect($host, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $BusinessName = ($_POST['BusinessName']);$Keyword =($_POST['Keyword']); $Picture1 = ($_POST['Picture1']); $Headline = ($_POST['Headline']); $Slogan2 = ($_POST['Slogan2']); $Description1 =($_POST['Description1']); $Description2 = ($_POST['Description2']); $Description3= ($_POST['Description3']); $Contact2 = ($_POST['Contact2']); $Picture2 = ($_POST['Picture2']); $Picture3 = ($_POST['Picture3']); if($BusinessName) { $query = "SELECT * FROM business_info WHERE `BusinessName`= '$BusinessName' ";$result = mysql_query($query) or die (mysql_error()); }?> <table> <tr> <td> <table> <tr> <td valign="top"> <table> <tr> <td valign="top"> <table> <tr> <td><?php echo"$Logo"; ?></td> </tr> <tr> <td valign="top"><h2><?php echo "<h2>$BusinessName</h2>"; ?></h2></td> </tr> <tr> <td valign="top"><?php echo "$Description1"; ?></td> </tr> <tr> <td valign="top"><?php echo "$Description2"; ?></td> </tr> <tr> <td valign="top"><?php echo "$Description3"; ?></td> </tr> <tr> <td valign="top"><?php echo "$Contact2"; ?></td> </tr> </table> </td> </tr> </table> </td> <td valign="top"> <table> <tr> <td> </td> </tr> <tr> <td valign="top"><?php echo"<img src='$Picture2' width='200' height='250'>"; ?> </td> </tr> <tr> <td valign="top"> <?php echo "<img src='$Picture3' width='200' height='250'>"; ?> </td> </tr> </table> </td> </tr> </table> <table border='1'> <tr> <td> </td> </tr> </table> </td> </tr> </table> <?php ?> [/code]so how can i display the info that it is on Description1, Description2, ect that matched BusinessName which is on the same row on the table name business_info Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124536 Share on other sites More sharing options...
Jenk Posted November 14, 2006 Share Posted November 14, 2006 $_GET['BusinessName'] Link to comment https://forums.phpfreaks.com/topic/27223-undefine-index/#findComment-124539 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.