ORA-01722错误消息

时间:2015-05-03 19:19:38

标签: php oracle

我正在尝试将一些数据输入到oracle表中,并且我收到错误代码ORA-01722。我相信它是因为交易者ID是一个数字,但它说它不能将字符串转换为数字。代码如下。

表格

<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";
}

错误代码警告:oci_execute()[function.oci-execute]:ORA-01722:第19行recipesql.php中的数字无效

1 个答案:

答案 0 :(得分:1)

认为应该是:

$query = "INSERT INTO MEDIA (Media_Id, Name, MediaType, Recipe, Video_Link, Trader_ID) 
VALUES (MEDIA_seq.nextval,'$RecipeName','$MediaType','$Recipe','$Link','$TraderID')";

即。 MEDIA_seq.nextval未附加''。否则,它被解释为VARCHAR2并将其插入NUMBER列会导致ORA-01722