?
Solved

insert statement not evaluating

Posted on 2005-03-28
10
Medium Priority
?
296 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:dprasad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 13644273
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
 

Author Comment

by:dprasad
ID: 13644333
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
 
LVL 32

Expert Comment

by:Batalf
ID: 13644348
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:dprasad
ID: 13644396
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
 

Author Comment

by:dprasad
ID: 13644420
the update query handles multiple selections from a multi select html box
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13644435
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
 

Author Comment

by:dprasad
ID: 13644485
ok, no that doesnt seem to work
0
 

Author Comment

by:dprasad
ID: 13644505
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
 
LVL 32

Accepted Solution

by:
Batalf earned 2000 total points
ID: 13644524
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
 

Author Comment

by:dprasad
ID: 13644749
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question