insert statement not evaluating

I'm trying to run an insert then update that newly inserted row. I'm echoing the sql statements, the insert isn't getting printed out so I'm pretty sure it's not getting evaulated. The update is run fine, if the associated keyword id is in the db (not the usual case)l. I only want to do the initial insert for the first element in the keywordelement array

if(isset($_POST['keywordparam'])){
    for($no=0;$no<count($_POST['keywordparam']);$no++){
        $keywordelement = $_POST['keywordparam'][$no];
                  
                        $seltype = $_POST['selecttype'];
                  $sel = $_POST['select1'];
                        
                        if ($no == 1) {
                        $keywordelementfirst = $_POST['keywordparam'][0];
                        
                        if ($seltype == 2 ) {
                        $selecttype = 'theme';
                        }
                        else if ($seltype == 3 ) {
                        $selectttype = 'place';
                        }
                        
                        if ($sel == 3) {
                        $select1 = 'SDS';
                        echo select1;
                        }
                        $updateq = "insert into k3gisdcp.keywords (keyword_id, keyword, author, type) values ('$findkwresult', '$keywordelementfirst', '$select1', '$selecttype')";
                      echo $updateq;
                        $s2 = OCIParse($c1, $updateq) or die("update error : $updateq");
                        OCIExecute($s2);
                        $committed2 = ocicommit($c1);
      }
      //Add selected keywords to newly added record
      
      
      //update k3gisdcp.keywords set keyword = keyword ||  'keyword: " . $keywordelement . "' where keyword_id = '{$findkwresult[$no]}'";
      //$updatek = "update k3gisdcp.keywords set keyword = keyword || 'keyword: . $keywordelement . "' where keyword_id = '$findkwresult'";
      $updatek = "update k3gisdcp.keywords set keyword = keyword ||  '" . $keywordelement . ",' where keyword_id = '$findkwresult'";
    $s2 = OCIParse($c1, $updatek) or die("update error : $updatek");
                  OCIExecute($s2);
                  echo $updatek;
                  $committed2 = ocicommit($c1);
   }
  }

}
?>
//here's my html

<form name="form1" method="post" action="">
  <table width="694" border="0">
    <tr>
      <td width="121">Current type: <?php $c1 = ocilogon("K3GISDCP", "K3GISDCP", "GIS");
$query = "select k.type as TYPE, k.keyword_id, dckw.keywords_id, dckw.dc_id from keywords k, dc_kw dckw where k.keyword_id = dckw.keywords_id and dckw.keywords_id ='$id1'";
$statement = OCIParse ($c1, $query);
OCIExecute ($statement);
       while (OCIFetchInto ($statement, $row, OCI_ASSOC)) {
        
         ?><b><?php echo $row['TYPE'];?></b> <?php
            } ?>
</td>
      <td width="256"><select name="selecttype" onChange='OnChangeFunc();'>
        <option value="1">Choose</option>
            <option value="2">theme</option>
        <option value="3">place</option>
      </select>
      Select the type for this item.</td>
      <td width="303">&nbsp;</td>
    </tr>
    <tr>
      <td>Current authority: <?php $c1 = ocilogon("K3GISDCP", "K3GISDCP", "GIS");
$query = "select k.author as AUTHOR, k.keyword_id, dckw.keywords_id, dckw.dc_id from keywords k, dc_kw dckw where k.keyword_id = dckw.keywords_id and dckw.keywords_id ='$id1'";
$statement = OCIParse ($c1, $query);
OCIExecute ($statement);
       while (OCIFetchInto ($statement, $row, OCI_ASSOC)) {
        
         ?><b><?php echo $row['AUTHOR']; ?></b><?php
            } ?></td>
      <td><select name="select1" onChange='OnChangeFunc();'>
        <option value="1">Choose</option>
            <option value="2">blank</option>
        <option value="3">SDS</option>
            <option value="4">FIPS</option>
      </select>
Select the authority for this item.</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Current Keywords:<br><?php $c1 = ocilogon("K3GISDCP", "K3GISDCP", "GIS");
$query = "select k.keyword as KEYWORD, k.keyword_id, dckw.keywords_id, dckw.dc_id from keywords k, dc_kw dckw where k.keyword_id = dckw.keywords_id and dckw.keywords_id ='$id1'";
$statement = OCIParse ($c1, $query);
OCIExecute ($statement);
       while (OCIFetchInto ($statement, $row, OCI_ASSOC)) {
        
         ?><b><?php echo $row['KEYWORD']; ?></b><?php } ?> </td>
      <td align="center" valign="top"><div align="left">
        <select name="keywordparam[]" size="25" multiple>
            <option value="1">auditory</option>
            <option value="2">boundary</option>
            <option value="3">buildings</option>
            <option value="4">cadastre</option>
            <option value="5">climate</option>
            <option value="6">common</option>
            <option value="7">communications</option>
            <option value="8">cultural</option>
            <option value="9">demographics</option>
            <option value="10">ecology</option>
            <option value="11">environmental_hazards</option>
            <option value="12">flora</option>
            <option value="13">future_projects</option>
            <option value="14">geodetic</option>
            <option value="15">geology</option>
            <option value="16">hydrography</option>
            <option value="17">improvement</option>
            <option value="18">land_status</option>
            <option value="19">landform </option>
            <option value="20">military_operations</option>
            <option value="21">olfactory</option>
            <option value="22">soil</option>
            <option value="23">transportation</option>
            <option value="24">utilities</option>
            <option value="25">visual</option>
        </select>
      </div></td>
      <td align="center" valign="middle">
        <div align="left">
          <p>Add keyword(s) to this item.<br>
            (<span class="style1">Hold down control key while clcicking to select multiple keywords) </span></p>
          <p>&nbsp;</p>
        </div></td>
    </tr>
  </table>
  <p>
    <input type="submit" name="submit" value="submit">
</p>
  <p>&nbsp;</p>
  <p>&nbsp;    </p>
  <p>&nbsp;    </p>
  <p>&nbsp;</p>
</form>
</body>
TIA

Dinesh
dprasadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BatalfCommented:
What's the purpose of these lines?

if ($no == 1) {
                    $keywordelementfirst = $_POST['keywordparam'][0];

Shouldn't the ending bracket be right after it:

if ($no == 1) {
                    $keywordelementfirst = $_POST['keywordparam'][0];
}

and not at the end of the update insert block?




0
dprasadAuthor Commented:
hmm yes you are right, but when I end that if like that, the query tries to insert a null for the $keywordelementfirst argument

insert into k3gisdcp.keywords (keyword_id, keyword, author, type) values ('5', '', 'SDS', 'theme')
Warning: ociexecute(): OCIStmtExecute: ORA-01400: cannot insert NULL into ("K3GISDCP"."KEYWORDS"."KEYWORD") in /var/www/html/dc/dc/keywordedit5.php on line 107
0
BatalfCommented:
Do you need the $keywordelementfirst at all?

Maybe it could be like this:

if(isset($_POST['keywordparam'])){
      $seltype = $_POST['selecttype'];      
      $sel = $_POST['select1'];
    if ($seltype == 2 ) {
        $selecttype = 'theme';
    }
    else if ($seltype == 3 ) {
        $selectttype = 'place';
    }
   
    if ($sel == 3) {
        $select1 = 'SDS';
        echo $select1;
    }
                  
    for($no=0;$no<count($_POST['keywordparam']);$no++){
        $keywordelement = $_POST['keywordparam'][$no];
       

            $updateq = "insert into k3gisdcp.keywords (keyword_id, keyword, author, type) values ('$findkwresult', '$keywordelement', '$select1', '$selecttype')";
           echo $updateq."<br>";
                    $s2 = OCIParse($c1, $updateq) or die("update error : $updateq");
                    OCIExecute($s2);
                    $committed2 = ocicommit($c1);
     }
     //Add selected keywords to newly added record
}
     
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

dprasadAuthor Commented:
Well the thing is, I only want to insert this record once, not $no<count($_POST['keywordparam']) times..
That's why I was trying to access only the first element of the array. I know its weird, the DB is denoarmalized and will have a some repeating data in it.
0
dprasadAuthor Commented:
the update query handles multiple selections from a multi select html box
0
BatalfCommented:
Maybe you could drop the for-loop and just have:


        $keywordelement = $_POST['keywordparam'][0];
            $updateq = "insert into k3gisdcp.keywords (keyword_id, keyword, author, type) values ('$findkwresult', '$keywordelement', '$select1', '$selecttype')";
           echo $updateq."<br>";
                    $s2 = OCIParse($c1, $updateq) or die("update error : $updateq");
                    OCIExecute($s2);
                    $committed2 = ocicommit($c1);
     
0
dprasadAuthor Commented:
ok, no that doesnt seem to work
0
dprasadAuthor Commented:
I may just try to do the insert the two drop down select fields and insert a dummy value for the keyword. then, delete that value and do the update from another page
0
BatalfCommented:
It should work without the for-loop or as an alternative with a for loop which only loops through the first item:

if(isset($_POST['keywordparam'])){
     $seltype = $_POST['selecttype'];    
     $sel = $_POST['select1'];
    if ($seltype == 2 ) {
        $selecttype = 'theme';
    }
    else if ($seltype == 3 ) {
        $selectttype = 'place';
    }
   
    if ($sel == 3) {
        $select1 = 'SDS';
        echo $select1;
    }
                 
    for($no=0;$no<1;$no++){
        $keywordelement = $_POST['keywordparam'][$no];
       

            $updateq = "insert into k3gisdcp.keywords (keyword_id, keyword, author, type) values ('$findkwresult', '$keywordelement', '$select1', '$selecttype')";
           echo $updateq."<br>";
                    $s2 = OCIParse($c1, $updateq) or die("update error : $updateq");
                    OCIExecute($s2);
                    $committed2 = ocicommit($c1);
     }
     //Add selected keywords to newly added record
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dprasadAuthor Commented:
Ok, I changed another page and made this an update instead of an insert, seems to work. god I wish they would let me alter the DB to add more tables...they need to read a book on DB normalization and apply it! grr
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.