找到你要的答案

Q:ORA-01722 error message

Q:ora-01722错误消息

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

我试着输入一些数据到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() [功能]:ora-01722。OCI执行:在19线recipesql.php无效号码

answer1: 回答1:

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.

认为应该:

$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和插入一列原因ora-01722。

php  oracle