Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
450 views
in Technique[技术] by (71.8m points)

php - 整数的无效输入语法:“”(Invalid input syntax for integer: “”)

I have a problem, to build INSERT PHP file with HTML form code.

(我有一个问题,用HTML表单代码构建INSERT PHP文件。)

When I drop from HTML form, then this error pops out ""invalid input syntax for integer: "" LINE 2:""

(当我从HTML表单中删除时,此错误弹出“”“无效的整数输入语法:”“第2行:””)

in all code, I comment every single line and nothing.

(在所有代码中,我注释每一行,什么也没有。)

There is my PHP script

(有我的PHP脚本)

`

(`)

$order_nr = pg_escape_string($_POST['order_nr']);
$date = pg_escape_string($_POST['date']);
$place = pg_escape_string($_POST['place']);
$service = pg_escape_string($_POST['service']);
$Vards = pg_escape_string($_POST['vards']);
$Uzvards = pg_escape_string($_POST['uzvards']);
$phone = pg_escape_string($_POST['phone']);
$email = pg_escape_string($_POST['email']);
$veids = pg_escape_string($_POST['veids']);
$passw = pg_escape_string($_POST['passw']);
$papildaprikojums = pg_escape_string($_POST['papildaprikojums']);
$save_info = pg_escape_string($_POST['save_info']);
$defekts = pg_escape_string($_POST['defekts']);

$query = " INSERT INTO serviss (order_nr, place, service, vards, uzvards, email, veids, passw, save_info, papildaprikojums, defekts)
                       VALUES ('$order_id', '$place', '$service', '$vards', '$uzvards', '$email', '$veids', '$passw', '$papildaprikojums', '$save_info', '$defekts') " ;
$result = pg_query($query);
if (!$result) {
    $errormessage = pg_last_error();
    echo "Error with query: " . $errormessage;
    exit();
}
printf ("These values were inserted into the database - %s %s %s", $order_id);
pg_close();

There is my HTML form code

(有我的HTML表单代码)

<form action="serviss.php" method="post" >
            <div class="ievade">
    Pasūtijuma numurs : <input type="text" size="5" name="order_id"> <br><br> 
Pie?em?anas datums : <input type="date" data-date="" data-date-format="DD MMMM YYYY" value="2015-08-09" name="date"> <br><br> 
    Pie?em?anas vieta : <select name="place">
                           <option value="Ausek?a_iela_9"> Ausek?a iela 9 </option>
                        </select>  <br><br>
    Pie?ēma : <select >
                <option value="service" name="Maris"> Māris </option>
                <option value="service name="Toms"> Toms </option>          
              </select>    <br> <br>
    Klienta vārds : <input type="text"  name="vards" size="5"> <br><br> 
    Klienta uzvārds : <input type="text" name="uzvards" size="5">  <br><br>
    Klienta tel.nr.: <input type="tel" id="phone" size="6"> <br><br> 
    Klienta e-pasts: <input type="text" value="[email protected]" name="email"> 

    <br><br>

    Iekārtas veids: <input type="text" value="iekārta" name="veids" size="5"> <br><br>
    Parole: <input type="text" name="passw" size="5"> <br><br> 
</div>
<div class="checkbox">
    Garantija: <br>
     Ir
    <input type="radio" name="garantija" value="Ir"> <br>
               Nav <input type="radio" name="garantija" value="Nav"> 
               <br> <br>
</div>
<div class="ievade">

    Papildaprīkojums: <input type="text" name="papildaprikojums" >   <br><br>
    Papildus informācija: <input type="text" name="informacija">
     <br> <br>
    Saglabājamā informācija: <input type="text" name="save_info"> 
    <br> <br>
    Defekta apraksts: <input type="text" name="defekts">        
</div>
    </div>
<input type="submit" value="Submit">
</form>

I hope you can help me.

(我希望你能帮助我。)

I use PostgreSQL 10.10

(我使用PostgreSQL 10.10)

  ask by Henrijs Soltums translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's like you have mixed up the 'order_id' with 'order_nr'.

(就像您将'order_id'与'order_nr'混淆了一样。)

The name value attribute is 'order_id' so when you try to get it it is

(名称值属性是“ order_id”,因此当您尝试获取它时)

$_POST['order_id'] not `$_POST['order_nr']`

It means that either you should say

(这意味着您应该说)

$order_nr = pg_escape_string($_POST['order_id']);

In order to use the variable into the insert statement and then

(为了将变量使用到插入语句中,然后)

$query = " INSERT INTO serviss (order_nr, place, service, vards, uzvards, email, veids, passw, save_info, papildaprikojums, defekts)
                   VALUES ('$order_nr', '$place', '$service', '$vards', '$uzvards', '$email', '$veids', '$passw', '$papildaprikojums', '$save_info', '$defekts') " ;

or you shoud say

(否则你应该说)

$order_id = pg_escape_string($_POST['order_id']);

And then

(然后)

$query = " INSERT INTO serviss (order_nr, place, service, vards, uzvards, email, veids, passw, save_info, papildaprikojums, defekts)
                   VALUES ('$order_id', '$place', '$service', '$vards', '$uzvards', '$email', '$veids', '$passw', '$papildaprikojums', '$save_info', '$defekts') " ;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...