解析字符串“1”在wordpress上的php中返回0

时间:2018-04-27 06:08:09

标签: php wordpress

对于我的生活,我无法弄清楚为什么会这样。我试过类型转换我尝试过使用内置的解析函数(intval),我尝试过使用字符串替换方法,但不管我做什么,我的$ AccountNum returns "1"和“解析”之后变成了0.

我没有太多关于WordPress自定义编程的经验,我希望有人知道这个问题所在。下面是我试图实现的WordPress页面,下面是我添加的functions.php部分,正在实现,最后一部分是我的输出。

请帮忙!

[vc_row][vc_column][vc_column_text][insert_php]

if ($_POST['submit']) {

saveAccountNum($_POST['email'], $_POST['password']);

echo $AccountNum;

get_all_user_info((int)$AccountNum);


}

[/insert_php][/vc_column_text][/vc_column][/vc_row]

第2部分(functions.php脚本)

function get_all_user_info($AccountNumber){

    global $AccountNum;

    $dbhost = "localhost";
    $dbuser = "#######";
    $dbpass = "#######";
    $db = "#######";
    $conn = new mysqli($dbhost, $dbuser, $dbpass,$db) or die("Connect failed: %s\n". $conn -> error);


    echo $AccountNumber;
    $userData = "CALL get_all_user_info("+$AccountNumber+")";
    $sql = mysqli_query($conn, $userData);

    global $First_Name;

        if(!$sql){
          die("Didn't work, here's why: " . mysql_error());
        }
        else{
         $object = $sql->fetch_object();
         $First_Name = $object->First_Name;
         echo "All variables made: " .$First_Name;
        }
$conn->close();
 }

第3部分(输出)

Changed variable name: ‘1”1’0All variables made:

正如您所看到的,它不会给我任何错误,但是当我尝试从字符串解析为int时会出现错误。无论我是尝试进行类型转换,还是调用函数,都会发生这种情况,说实话,我对于为什么没有想法。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:-1)

试试此参考链接

Private Sub cmdImport_Click()
Dim intDocCount As Integer
Dim wdApp As Word.Application, wdDoc As Word.Document, xlWb As Excel.Workbook, xlWs As Excel.Worksheet
Dim BookmarkText As String

On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
On Error GoTo 0

If wdApp Is Nothing Then
    MsgBox "There are no MS Word Documents open.", vbInformation, "No Word Documents open"
    Exit Sub
End If

Set xlWb = ThisWorkbook 'Edited from ActiveWorkbook
Set xlWs = ActiveWorkbook.Sheets("Sheet1")
intDocCount = wdApp.Documents.Count

If intDocCount > 1 Then
    MsgBox "There are " & intDocCount & " Word Documents open." & vbNewLine & vbNewLine & _
    "Please close the additional MS Word Documents", vbCritical, "Too many Word Documents open!"
    Set wdApp = Nothing
    Exit Sub
End If


With wdApp
    Set wdDoc = wdApp.ActiveDocument
    wdDoc.Activate
    BookmarkText = wdDoc.Bookmarks("test").Range.Text
End With

xlWs.Cells(2, 1) = BookmarkText

End Sub