Reputation: 149
I'm trying to input some data into oracle tables and i'm receiving error code ORA-01722. I believe its because of the Trader ID which is a number but its saying it can't convert a string to a number. Code below.
Form
<form method="post" action="recipesql.php" >
<table align="center">
<tr>
<td align="right">Recipe Name:</td>
<td align="left"><input type="text" name="RecipeName"></td>
</tr>
<tr>
<td align="right">Media Type:</td>
<td align="left"><input type="text" name="MediaType"></td>
</tr>
<tr>
<td align="right">Recipe:</td>
<td align="left"><input type="text" name="Recipe" /></td>
</tr>
<tr>
<td align="right">Video Link (e.g /embed/12345):</td>
<td align="left"><input type="text" name="Link"></td>
</tr>
<tr>
<td align="right">Trader ID:</td>
<td align="left"><input type="number" name="TraderID"></td>
</tr>
</table>
<input type="submit" value="Submit" name="Submit">
</form>
PHP
//include connection
include ('PHP/connection.php');
//has form been submitted?
if(isset($_POST['Submit'])){
$RecipeName=$_POST['Name'];
$MediaType=$_POST['MediaType'];
$Recipe=$_POST['Recipe'];
$Link=$_POST['Video_Link'];
$TraderID=$_POST['Trader_ID'];
//Insert data
$query = "INSERT INTO MEDIA
(Media_Id, Name, MediaType, Recipe, Video_Link, Trader_ID)
VALUES
('MEDIA_seq.nextval','$RecipeName','$MediaType','$Recipe','$Link','$TraderID')";
$runquery = oci_parse($connection,$query);
oci_execute($runquery);
}
//to check if the if statement is working
else
{
echo "Error";
}
Error code Warning: oci_execute() [function.oci-execute]: ORA-01722: invalid number in recipesql.php on line 19
Upvotes: 1
Views: 1467
Reputation: 13967
Think it should be:
$query = "INSERT INTO MEDIA (Media_Id, Name, MediaType, Recipe, Video_Link, Trader_ID)
VALUES (MEDIA_seq.nextval,'$RecipeName','$MediaType','$Recipe','$Link','$TraderID')";
i.e. MEDIA_seq.nextval
not enclosed in ''
. Otherwise it is interpreted as a VARCHAR2
and inserting it into a NUMBER
column causes an ORA-01722
.
Upvotes: 2