By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

database error.....undefined index

anfetienne
100+
P: 424
i take information from a database and then have the collected values entered into a form with hidden fields.

Expand|Select|Wrap|Line Numbers
  1.   <input type="hidden" name="returnURL" id="returnURL" value="<?php print $returnURL;?>"/>      
  2.   <input type="hidden" name="tempID" id="tempID" value='<?php print $random_digit;?>'/> 
  3.   <input type="hidden" name="htmlcss" id="htmlcss" value='<?php print $htmlcss;?>'/>      
  4.   <input type="hidden" name="header" id="header" value='<?php print $header;?>'/>
  5.   <input type="hidden" name="nav" id="nav" value='<?php print $nav;?>'/>      
  6.   <input type="hidden" name="titleWrap01" id="titleWrap01" value='<?php print $titleWrap01;?>'/> 
  7.   <input type="hidden" name="titleWrap02" id="titleWrap02" value='<?php print $titleWrap02;?>'/>      
  8.   <input type="hidden" name="subheadWrap01" id="subheadWrap01" value='<?php print $subheadWrap01;?>'/>
  9.   <input type="hidden" name="subheadWrap02" id="subheadWrap02" value='<?php print $subheadWrap02;?>'/>      
  10.   <input type="hidden" name="flashWrap01" id="flashWrap01" value='<?php print $flashWrap01;?>'/> 
  11.   <input type="hidden" name="flashWrap02" id="flashWrap02" value='<?php print $flashWrap02;?>'/>      
  12.   <input type="hidden" name="flash01" id="flash01" value='<?php print $flashURL;?>'/>
  13.   <input type="hidden" name="flashVar" id="flashVar" value='<?php print $flashVar;?>'/>      
  14.   <input type="hidden" name="flash02" id="flash02" value='<?php print $flash02;?>'/> 
  15.   <input type="hidden" name="flashWrap03" id="flashWrap03" value='<?php print $flashWrap03;?>'/>      
  16.   <input type="hidden" name="descriptionWrap01" id="descriptionWrap01" value='<?php print $descriptionWrap01;?>'/>
  17.   <input type="hidden" name="descriptionWrap02" id="descriptionWrap02" value='<?php print $descriptionWrap02;?>'/>      
  18.   <input type="hidden" name="generalWrap01" id="generalWrap01" value='<?php print $generalWrap01;?>'/> 
  19.   <input type="hidden" name="generalWrap02" id="generalWrap02" value='<?php print $generalWrap02;?>'/>      
  20.   <input type="hidden" name="aboutWrap01" id="aboutWrap01" value='<?php print $aboutWrap01;?>'/>
  21.   <input type="hidden" name="aboutWrap02" id="aboutWrap02" value='<?php print $aboutWrap02;?>'/>      
  22.   <input type="hidden" name="paymentWrap01" id="paymentWrap01" value='<?php print $paymentWrap01;?>'/> 
  23.   <input type="hidden" name="paymentWrap02" id="paymentWrap02" value='<?php print $paymentWrap02;?>'/>
  24.   <input type="hidden" name="termsWrap01" id="termsWrap01" value='<?php print $termsWrap01;?>'/>      
  25.   <input type="hidden" name="termsWrap02" id="termsWrap02" value='<?php print $termsWrap02;?>'/>
  26.   <input type="hidden" name="footer" id="footer" value='<?php print $footer;?>'/> 
  27.  
when i submit the form with all the other text fields filled out......then in the file to save it to a database it brings up the error....."undefined index" although i only have 1 index set.

Expand|Select|Wrap|Line Numbers
  1. <?PHP error_reporting(E_ALL);
  2. $username="tempsUser";
  3. $password="auction";
  4. $database="auctionTemps";
  5.  
  6. $returnURL = $_POST['returnURL'];
  7.  
  8. $tempID=$_POST['tempID'];
  9. $htmlcss=$_POST['htmlcss'];
  10. $header=$_POST['header'];
  11. $nav=$_POST['nav'];
  12. $titleWrap01=$_POST['titleWrap01'];
  13. $title=$_POST['title'];
  14. $titleWrap02=$_POST['titleWrap02'];
  15. $subheadWrap01=$_POST['subheadWrap01'];
  16. $subheading=$_POST['subheading'];
  17. $subheadWrap02=$_POST['subheadWrap02'];
  18. $flashWrap01=$_POST['flashWrap01'];
  19. $flashWrap02=$_POST['flashWrap02'];
  20. $flash01=$_POST['flash01'];
  21. $flashVar=$_POST['flashVar'];
  22. $flash02=$_POST['flash02'];
  23. $flashWrap03=$_POST['flashWrap03'];
  24. $descriptionWrap01=$_POST['descriptionWrap01'];
  25. $description=$_POST['description'];
  26. $descriptionWrap02=$_POST['descriptionWrap02'];
  27. $generalWrap01=$_POST['generalWrap01'];
  28. $general=$_POST['general'];
  29. $generalWrap02=$_POST['generalWrap02'];
  30. $aboutWrap01=$_POST['aboutWrap01'];
  31. $about=$_POST['about'];
  32. $aboutWrap02=$_POST['aboutWrap02'];
  33. $paymentWrap01=$_POST['paymentWrap01'];
  34. $payment01=$_POST['payment01'];
  35. $payment02=$_POST['payment02'];
  36. $paymentWrap02=$_POST['paymentWrap02'];
  37. $termsWrap01=$_POST['termsWrap01'];
  38. $terms=$_POST['terms'];
  39. $termsWrap02=$_POST['termsWrap02'];
  40. $footer=$_POST['footer'];
  41. ?>
  42.  
  43. <?
  44.  
  45. // OPEN CONNECTION ---> 
  46. $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
  47.  
  48. mysql_select_db("$database") or die("Unable to select database!");
  49.  
  50. // Select column 1 from table name where column name = $your_var.
  51. $sql = "SELECT tempID FROM savedTemps WHERE tempID = '{$tempID}'";
  52. // If mysql_query returns false, we'll die with the error.
  53. $res = mysql_query( $sql ) or die( mysql_error() );
  54.  
  55. // If a there is a match
  56. if ( mysql_num_rows( $res ) > 0 )
  57. {
  58. //  EXECUTE QUERY ---> 
  59. $qry="UPDATE savedTemps 
  60.  
  61. SET htmlcss='$htmlcss', header='$header', nav='$nav.', titleWrap01='$titleWrap01', title='$title', titleWrap02='$titleWrap02', subheadWrap01='$subheadWrap01', subheading='$subheading', subheadWrap02='$subheadWrap02', flashWrap01='$flashWrap01', flashWrap02='$flashWrap02', flash01='$flash01', flashVar='$flashVar', flash02='$flash02', flashWrap03='$flashWrap03', descriptionWrap01='$descriptionWrap01', description='$description',  descriptionWrap02='$descriptionWrap02', generalWrap01='$generalWrap01', general='$general',  generalWrap02='$generalWrap02', aboutWrap01='$aboutWrap01', about='$about',  aboutWrap02='$aboutWrap02', paymentWrap01='$paymentWrap01',  payment01='$payment01', payment02='$payment02', paymentWrap02='$paymentWrap02', termsWrap01='$termsWrap01', terms='$terms',  termsWrap02='$termsWrap02', footer='$footer'";
  62.  
  63. $res=mysql_query($qry) or die("Error in query:".mysql_error());
  64.  
  65. }
  66. else
  67. {
  68. //  EXECUTE QUERY ---> 
  69. $query="INSERT savedTemps (
  70.  
  71.             tempID, 
  72.             htmlcss, 
  73.             header, 
  74.             nav, 
  75.             titleWrap01, 
  76.             title,
  77.             titleWrap02,
  78.             subheadWrap01, 
  79.             subheading,
  80.             subheadWrap02, 
  81.             flashWrap01,     
  82.             flashWrap02, 
  83.             flash01, 
  84.             flashVar,
  85.             flash02, 
  86.             flashWrap03,
  87.             descriptionWrap01,
  88.             description, 
  89.             descriptionWrap02,
  90.             generalWrap01, 
  91.             general, 
  92.             generalWrap02, 
  93.             aboutWrap01,
  94.             about, 
  95.             aboutWrap02,
  96.             paymentWrap01, 
  97.             payment01, 
  98.             payment02, 
  99.             paymentWrap02,
  100.             termsWrap01, 
  101.             terms, 
  102.             termsWrap02,
  103.             footer)
  104.  
  105.         VALUES(    
  106.             '$tempID', 
  107.             '$htmlcss', 
  108.             '$header', 
  109.             '$nav.', 
  110.             '$titleWrap01', 
  111.             '$title',
  112.             '$titleWrap02',
  113.             '$subheadWrap01', 
  114.             '$subheading',
  115.             '$subheadWrap02', 
  116.             '$flashWrap01',     
  117.             '$flashWrap02', 
  118.             '$flash01', 
  119.             '$flashVar', 
  120.             '$flash02', 
  121.             '$flashWrap03',
  122.             '$descriptionWrap01',
  123.             '$description', 
  124.             '$descriptionWrap02',
  125.             '$generalWrap01', 
  126.             '$general', 
  127.             '$generalWrap02', 
  128.             '$aboutWrap01',
  129.             '$about', 
  130.             '$aboutWrap02',
  131.             '$paymentWrap01', 
  132.             '$payment01', 
  133.             '$payment02', 
  134.             '$paymentWrap02',
  135.             '$termsWrap01', 
  136.             '$terms', 
  137.             '$termsWrap02',
  138.             '$footer')";
  139.             $result=mysql_query($query) or die("Error in query:".mysql_error()); 
  140. }
  141.  
  142. //  CLOSE CONNECTION ---> 
  143. mysql_close($connection); 
  144.  
  145. //
  146.  
  147. ?>
  148. <script language="JavaScript">
  149. <!--
  150. window.location="<? print $returnURL?>";
  151. //-->
  152. </SCRIPT>
  153.  
Mar 28 '09 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hi.

An "undefined index" warning means that you tried to get an array element that does not exist.

Simply look through your code and find the array element the warning specified.
Make sure the spelling is correct and that the element is properly initialized.

If you are getting the elements from an outside source (HTML forms, XML, etc...), make sure that the array element actually does exists before you use it.
The isset function is great for that.

Also.
Using the short-tag syntax (<? ... ?>) to open a PHP block is a very very bad habit. They are disabled by default, so you are practically asking for future compatibility issues when using them.

It's always best to use <?php ... ?>. They always work, on all PHP servers.
Apr 8 '09 #2

Post your reply

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