簡體   English   中英

我的語法有什么問題?

[英]What is wrong in my syntax?

所以我有這個簡單的do_signup.php部分代碼:

<?php
$conn=oci_connect('system', 'user');
if(!$conn){
echo 'Can not connect';
}

$uname=$_POST['username'];
$pass=$_POST['password'];
$pstmt1="select * from admin where username='$uname'";
$stdi1=oci_parse($conn, $pstmt1);
oci_execute($stdi1);
oci_fetch($stdi1);
$numrow=oci_num_rows($stdi1);

if($numrow==0){
    $pstmt2="insert into admin(username,password) values('$uname', '$pass')";
    $stdi2=oci_parse($conn, $pstmt2);
    oci_execute($stdi2);

    oci_close($conn);
    header('Location: signup_success.php');
}else{
    oci_close($conn);
    header('Location: signup_fail.php');
}

?>

當我的表為空時,我總是被重定向到signup_fail.php。 同樣,為什么呢?

$stdi1=oci_parse($conn, $pstmt1);

您的變量名稱是: $ stdi1

然后執行: $ stdi

oci_execute($stdi);中用$stdi1替換$stdi oci_execute($stdi);

編輯:看看php manuel: http : //php.net/manual/fr/function.oci-num-rows.php

您必須獲取結果才能使用oci_num_rows函數返回獲取的行(選擇),而不是像DML查詢那樣返回受影響的行。

喜歡:

oci_execute($stdi1); 
oci_fetch($stdi1);
$numrow=oci_num_rows($stdi1);

第一個錯誤:

$pstmt1="select * from admin where username='$uname'";//remove extra semicolon

第二個錯誤:

$pstmt2="insert into admin(username,password) values('$uname', '$pass')"; //刪除多余的分號並以正確的方式編寫插入語法

您可以嘗試以下

oci_define_by_name($stmt, 'NUMBER_OF_ROWS', $number_of_rows);
oci_execute($stmt);
oci_fetch($stmt);
echo $number_of_rows;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM