Jump to content

retreiving data and maintaining data. !!!URGENT!!!


gaffer

Recommended Posts

I am trying to add data to a table in oracle but get

 

Warning: ociexecute(): OCIStmtExecute: ORA-00936: missing expression in /homedir/ilex-s02/mrace/public_html/addnewemp.php on line 18

 

here is the PHP script i am working with,

 

Can anyone see any faults with it?

 

many thanks

 

Gaff.

 

 

<!--addnewemp.php-->

<html><body>

<?php

putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");

$conn = OCILogon("UUUUU","PPPPP", "LLLLL");

 

$StaffNo = $_POST["StaffNo"];

$Firstname = $_POST["Firstname"];

$Surname = $_POST["Surname"];

$Rank = $_POST["Rank"];

 

$sql = "insert into Staff values (";

$sql = $sql . $Staffno . ",'" . $Firstname . "','" . $Surname . "'," . $Rank . ",'";

$sql = $sql . ")";

$stmt = ociparse($conn, $sql);

ociexecute($stmt);

 

?>

Link to comment
Share on other sites

Yes, at the end where you are (I'm assuming) trying to set $sql, don't use that method, use the append equals method:

 

$sql = "insert into Staff values (";
$sql .= $Staffno . ",'" . $Firstname . "','" . $Surname . "','" . $Rank . "'";
$sql .= ")";
$stmt = ociparse($conn, $sql);
ociexecute($stmt);

 

Or just do this:

 

$sql = "insert into Staff values (" . $Staffno . ",'" . $Firstname . "','" . $Surname . "','" . $Rank . "')";
$stmt = ociparse($conn, $sql);
ociexecute($stmt);

 

Then try it out.

Link to comment
Share on other sites

basically, we are trying to add 4 values that have been inputted from a previous html page into an oracle database.

 

the html is as follows:

 

<!--- addnewemp.htm --->

<html>

<head>

<title>Add a new employee </title>

</head>

<body>

<H1>The Personnel System using PHP</H1>

Please fill out the form and submit the new employee details:-

<hr>

<FORM action="addnewemp.php" method="post">

 

<br>First Name : <input type="text" size="15" name="Firstname">

<br>Surname : <input type="text" size="15" name="Surname">

<br>Staff Number : <input type="text" size="4" name="staffno">

<br>Rank : <input type="text" size="8" name="Rank">

 

<input type="reset" value="Clear the form">

<input type="submit" value="Submit - enter the data">

</FORM>

<hr>

</body></html>

 

 

 

can you suggest a piece of php script that will allow us to import the input into the oracle database!

 

My life depends on it  :'(

Link to comment
Share on other sites

Uhm...I already told you what was wrong with your code, just change what I told you to and try it out.

 

<?php
putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");
$conn = OCILogon("UUUUU","PPPPP", "LLLLL");

$Staffoo = $_POST["staffno"];
$Firstname = $_POST["Firstname"];
$Surname = $_POST["Surname"];
$Rank = $_POST["Rank"];

$sql = "insert into Staff values (" . $Staffno . ",'" . $Firstname . "','" . $Surname . "','" . $Rank . "')";
$stmt = ociparse($conn, $sql);
ociexecute($stmt);

?>

 

And btw, unless your life does truly depend on doing this, don't try to increase the urgency of your request by saying it does, its actually annoying, since people will respond to your question on their own time, no matter how urgent it seems.

Link to comment
Share on other sites

addnewemp.php should be this:

 

<?php
putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");
$conn = OCILogon("UUUUU","PPPPP", "LLLLL");

$Staffno = $_POST["staffno"];
$Firstname = $_POST["Firstname"];
$Surname = $_POST["Surname"];
$Rank = $_POST["Rank"];

$sql = "insert into Staff values ('" . $Staffno . "','" . $Firstname . "','" . $Surname . "','" . $Rank . "')";
$stmt = ociparse($conn, $sql);
ociexecute($stmt);
?>

 

Please try that.

Link to comment
Share on other sites

thanks from all your help so far....

 

Part 2

 

<!--- addnewbook.htm --->

<html>

<head>

<title>Add a new Book </title>

</head>

<body>

<H1>The Book records System using PHP</H1>

Please fill out the form and submit the new Book details:-

<hr>

<FORM action="addnewbook.php" method="post">

 

<br>ISBN : <input type="Number" size="11" name="ISBN">

<br>Title : <input type="text" size="15" name="Title">

<br>Author : <input type="text" size="15" name="Author">

<br>Barcode : <input type="Number" size="13" name="Barcode">

<br>PublicationDate : <input type="DATE" size="10" name="PublicationDate">

<br>Publisher : <input type="text" size="20" name="Publisher">

 

<input type="reset" value="Clear the form">

<input type="submit" value="Submit - enter the data">

</FORM>

<hr>

</body></html>

 

 

<!--addnewbook.php-->

<html><body>

<?php

putenv("TNS_ADMIN=/u1/oracle/Products/shu10g/network/admin");

$conn = OCILogon("UUUUU","PPPPP", "LLLLL");

 

$ISBN = $_POST["ISBN"];

$Title = $_POST["Title"];

$AUthor = $_POST["Author"];

$Barcode = $_POST["Barcode"];

$PublicationDate = $_POST["PublicationDate"];

$Publisher = $_POST["Publisher"];

 

$sql = "insert into Book values ('" . $ISBN . "','" . $Title . "','" . $AUthor . "','" . $Barcode . "','" . $PublicationDate . "','" . $Publisher . "')";

$stmt = ociparse($conn, $sql);

ociexecute($stmt);

?>

 

</body></html>

 

 

i have an error with the date...

 

Warning: ociexecute(): OCIStmtExecute: ORA-01843: not a valid month in /homedir/ilex-s02/public_html/addnewbook.php on line 16

 

Does the error stat on the html page here

 

<br>PublicationDate : <input type="DATE" size="10" name="PublicationDate">

 

 

or is it within the php?

Link to comment
Share on other sites

I've never heard of the DATE value for the type attribute in input tags, and I messed around in HTML for about 2 years.  I could be wrong though.  Why not just do a drop down box with the months as the values?  Example:

 

<input type="text" size="5" name="PublicationDay" maxlength="2" />
<select name="PublicationMonth">
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select>
<input type="text" size="5" name="PublicationYear" maxlength="4" />

 

Then pass this to PHP and convert it to a timestamp using strtotime:

 

<?php
$day = $_POST['PublicationDay'];
$month = $_POST['PublicationMonth'];
$year = $_POST['PublicationYear'];

$PublicationDate = strtotime($day . $month . $year);
?>

 

Then pass $PublicationDate to your oracle query, and make sure the table you are inputting to is in either text or date format, though idk if oracle uses the same types as mySQL.

 

Hope this helped.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.