database error.....undefined index

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anfetienne
    Contributor
    • Feb 2009
    • 424

    database error.....undefined index

    i take information from a database and then have the collected values entered into a form with hidden fields.

    Code:
      <input type="hidden" name="returnURL" id="returnURL" value="<?php print $returnURL;?>"/>      
      <input type="hidden" name="tempID" id="tempID" value='<?php print $random_digit;?>'/> 
      <input type="hidden" name="htmlcss" id="htmlcss" value='<?php print $htmlcss;?>'/>      
      <input type="hidden" name="header" id="header" value='<?php print $header;?>'/>
      <input type="hidden" name="nav" id="nav" value='<?php print $nav;?>'/>      
      <input type="hidden" name="titleWrap01" id="titleWrap01" value='<?php print $titleWrap01;?>'/> 
      <input type="hidden" name="titleWrap02" id="titleWrap02" value='<?php print $titleWrap02;?>'/>      
      <input type="hidden" name="subheadWrap01" id="subheadWrap01" value='<?php print $subheadWrap01;?>'/>
      <input type="hidden" name="subheadWrap02" id="subheadWrap02" value='<?php print $subheadWrap02;?>'/>      
      <input type="hidden" name="flashWrap01" id="flashWrap01" value='<?php print $flashWrap01;?>'/> 
      <input type="hidden" name="flashWrap02" id="flashWrap02" value='<?php print $flashWrap02;?>'/>      
      <input type="hidden" name="flash01" id="flash01" value='<?php print $flashURL;?>'/>
      <input type="hidden" name="flashVar" id="flashVar" value='<?php print $flashVar;?>'/>      
      <input type="hidden" name="flash02" id="flash02" value='<?php print $flash02;?>'/> 
      <input type="hidden" name="flashWrap03" id="flashWrap03" value='<?php print $flashWrap03;?>'/>      
      <input type="hidden" name="descriptionWrap01" id="descriptionWrap01" value='<?php print $descriptionWrap01;?>'/>
      <input type="hidden" name="descriptionWrap02" id="descriptionWrap02" value='<?php print $descriptionWrap02;?>'/>      
      <input type="hidden" name="generalWrap01" id="generalWrap01" value='<?php print $generalWrap01;?>'/> 
      <input type="hidden" name="generalWrap02" id="generalWrap02" value='<?php print $generalWrap02;?>'/>      
      <input type="hidden" name="aboutWrap01" id="aboutWrap01" value='<?php print $aboutWrap01;?>'/>
      <input type="hidden" name="aboutWrap02" id="aboutWrap02" value='<?php print $aboutWrap02;?>'/>      
      <input type="hidden" name="paymentWrap01" id="paymentWrap01" value='<?php print $paymentWrap01;?>'/> 
      <input type="hidden" name="paymentWrap02" id="paymentWrap02" value='<?php print $paymentWrap02;?>'/>
      <input type="hidden" name="termsWrap01" id="termsWrap01" value='<?php print $termsWrap01;?>'/>      
      <input type="hidden" name="termsWrap02" id="termsWrap02" value='<?php print $termsWrap02;?>'/>
      <input type="hidden" name="footer" id="footer" value='<?php print $footer;?>'/>
    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....."unde fined index" although i only have 1 index set.

    Code:
    <?PHP error_reporting(E_ALL);
    $username="tempsUser";
    $password="auction";
    $database="auctionTemps";
    
    $returnURL = $_POST['returnURL'];
    
    $tempID=$_POST['tempID'];
    $htmlcss=$_POST['htmlcss'];
    $header=$_POST['header'];
    $nav=$_POST['nav'];
    $titleWrap01=$_POST['titleWrap01'];
    $title=$_POST['title'];
    $titleWrap02=$_POST['titleWrap02'];
    $subheadWrap01=$_POST['subheadWrap01'];
    $subheading=$_POST['subheading'];
    $subheadWrap02=$_POST['subheadWrap02'];
    $flashWrap01=$_POST['flashWrap01'];
    $flashWrap02=$_POST['flashWrap02'];
    $flash01=$_POST['flash01'];
    $flashVar=$_POST['flashVar'];
    $flash02=$_POST['flash02'];
    $flashWrap03=$_POST['flashWrap03'];
    $descriptionWrap01=$_POST['descriptionWrap01'];
    $description=$_POST['description'];
    $descriptionWrap02=$_POST['descriptionWrap02'];
    $generalWrap01=$_POST['generalWrap01'];
    $general=$_POST['general'];
    $generalWrap02=$_POST['generalWrap02'];
    $aboutWrap01=$_POST['aboutWrap01'];
    $about=$_POST['about'];
    $aboutWrap02=$_POST['aboutWrap02'];
    $paymentWrap01=$_POST['paymentWrap01'];
    $payment01=$_POST['payment01'];
    $payment02=$_POST['payment02'];
    $paymentWrap02=$_POST['paymentWrap02'];
    $termsWrap01=$_POST['termsWrap01'];
    $terms=$_POST['terms'];
    $termsWrap02=$_POST['termsWrap02'];
    $footer=$_POST['footer'];
    ?>
    
    <?
    
    // OPEN CONNECTION ---> 
    $connection=mysql_connect("localhost" ,"$username", "$password") or die("Unable to connect!");
    
    mysql_select_db("$database") or die("Unable to select database!");
    
    // Select column 1 from table name where column name = $your_var.
    $sql = "SELECT tempID FROM savedTemps WHERE tempID = '{$tempID}'";
    // If mysql_query returns false, we'll die with the error.
    $res = mysql_query( $sql ) or die( mysql_error() );
     
    // If a there is a match
    if ( mysql_num_rows( $res ) > 0 )
    {
    //  EXECUTE QUERY ---> 
    $qry="UPDATE savedTemps 
    
    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'";
    		     
    $res=mysql_query($qry) or die("Error in query:".mysql_error());
     
    }
    else
    {
    //  EXECUTE QUERY ---> 
    $query="INSERT savedTemps (
    
    		    tempID, 
    		    htmlcss, 
                header, 
                nav, 
                titleWrap01, 
                title,
    			titleWrap02,
                subheadWrap01, 
                subheading,
    			subheadWrap02, 
                flashWrap01, 	
                flashWrap02, 
                flash01, 
                flashVar,
                flash02, 
                flashWrap03,
    			descriptionWrap01,
                description, 
                descriptionWrap02,
    			generalWrap01, 
                general, 
                generalWrap02, 
    			aboutWrap01,
                about, 
                aboutWrap02,
    			paymentWrap01, 
                payment01, 
                payment02, 
                paymentWrap02,
                termsWrap01, 
                terms, 
                termsWrap02,
    			footer)
    
            VALUES(	
    		    '$tempID', 
    		    '$htmlcss', 
                '$header', 
                '$nav.', 
                '$titleWrap01', 
                '$title',
    			'$titleWrap02',
                '$subheadWrap01', 
                '$subheading',
    			'$subheadWrap02', 
                '$flashWrap01', 	
                '$flashWrap02', 
                '$flash01', 
                '$flashVar', 
                '$flash02', 
                '$flashWrap03',
    			'$descriptionWrap01',
                '$description', 
                '$descriptionWrap02',
    			'$generalWrap01', 
                '$general', 
                '$generalWrap02', 
    			'$aboutWrap01',
                '$about', 
                '$aboutWrap02',
    			'$paymentWrap01', 
                '$payment01', 
                '$payment02', 
                '$paymentWrap02',
                '$termsWrap01', 
                '$terms', 
                '$termsWrap02',
    			'$footer')";
    			$result=mysql_query($query) or die("Error in query:".mysql_error()); 
    }
    
    //  CLOSE CONNECTION ---> 
    mysql_close($connection); 
    
    //
    
    ?>
    <script language="JavaScript">
    <!--
    window.location="<? print $returnURL?>";
    //-->
    </SCRIPT>
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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.

    Comment

    Working...