dprasad
asked on
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['keywordpa ram'])){
for($no=0;$no<count($_POST ['keywordp aram']);$n o++){
$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"> </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> </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</optio n>
<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</op tion>
<option value="10">ecology</option >
<option value="11">environmental_h azards</op tion>
<option value="12">flora</option>
<option value="13">future_projects </option>
<option value="14">geodetic</optio n>
<option value="15">geology</option >
<option value="16">hydrography</op tion>
<option value="17">improvement</op tion>
<option value="18">land_status</op tion>
<option value="19">landform </option>
<option value="20">military_operat ions</opti on>
<option value="21">olfactory</opti on>
<option value="22">soil</option>
<option value="23">transportation< /option>
<option value="24">utilities</opti on>
<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> </p>
</div></td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="submit">
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</form>
</body>
TIA
Dinesh
if(isset($_POST['keywordpa
for($no=0;$no<count($_POST
$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"> </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> </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</optio
<option value="4">cadastre</option
<option value="5">climate</option>
<option value="6">common</option>
<option value="7">communications</
<option value="8">cultural</option
<option value="9">demographics</op
<option value="10">ecology</option
<option value="11">environmental_h
<option value="12">flora</option>
<option value="13">future_projects
<option value="14">geodetic</optio
<option value="15">geology</option
<option value="16">hydrography</op
<option value="17">improvement</op
<option value="18">land_status</op
<option value="19">landform </option>
<option value="20">military_operat
<option value="21">olfactory</opti
<option value="22">soil</option>
<option value="23">transportation<
<option value="24">utilities</opti
<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> </p>
</div></td>
</tr>
</table>
<p>
<input type="submit" name="submit" value="submit">
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</form>
</body>
TIA
Dinesh
ASKER
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"."KE YWORD") in /var/www/html/dc/dc/keywor dedit5.php on line 107
insert into k3gisdcp.keywords (keyword_id, keyword, author, type) values ('5', '', 'SDS', 'theme')
Warning: ociexecute(): OCIStmtExecute: ORA-01400: cannot insert NULL into ("K3GISDCP"."KEYWORDS"."KE
Do you need the $keywordelementfirst at all?
Maybe it could be like this:
if(isset($_POST['keywordpa ram'])){
$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 ['keywordp aram']);$n o++){
$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
}
Maybe it could be like this:
if(isset($_POST['keywordpa
$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
$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
}
ASKER
Well the thing is, I only want to insert this record once, not $no<count($_POST['keywordp aram']) 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.
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.
ASKER
the update query handles multiple selections from a multi select html box
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);
$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);
ASKER
ok, no that doesnt seem to work
ASKER
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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?