在PHP中使用If语句但不起作用 [英] Using an If statement in PHP but not working

查看:176
本文介绍了在PHP中使用If语句但不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是,当我输入所有信息时(对于图中的客户ID 199),在我提交的帐户中,该信息将进入数据库.但是我想将其更改为某些内容,所以我添加了一个if语句

What I want to do is When I enter all my information (for client ID 199 in the picture) In my account being submit it, it goes into the database. BUT I want it to change to something and so i added an if statement

此处代码已添加到代码底部的现有代码中

Here the code im adding to the existing code already at the BOTTOM of the code

if ($vpr_clid == 199) {
        $vpr_cl_name = "Shelley Madsen And Associates";
      }

如果($ vpr_clid = 199) 我希望该名称为"Shelley Madsen And Associates",然后在下表中显示而不是"Nice and White Smiles"(结果示例如下)

if the ($vpr_clid = 199) i want the clname to be "Shelley Madsen And Associates" then what is show in the table below instead of "Nice and White Smiles" (that an example of the results look like)

但是当我选择数据库时,它没有更改,仍然显示"Nice and White Smiles:(

but when i chcek the database it not changing it and still show "Nice and White Smiles :(

我没有看到任何错误,所以可能是我必须将IF语句放入巨大的php文件中的代码的位置?不知道如何解决此问题

I dont see any error, so it might be the placement of the code i have to put the IF statement in the huge php file? Dont know how to fix this issue

谢谢(下面的代码是我添加If语句之前的基本代码) 我还在函数调用之前插入了if语句,但仍然无法正常工作示例

Thanks (the code below is the base code before i added the If statement) I also insert the if statement before the function were called but still didnt work example

if ($vpr_clid == 199) {
            $vpr_cl_name = "Shelley Madsen And Associates";
          }

  $result = InsertIntoPayReminder($link, $vars);
  $result = GetVpr_Id($link, $vars);

<?php 
session_start();

if ($_SESSION['company'] != "ACB") {    
         // redirect to the logout page
       $redirect = 'logout.php';
       include  './includes/redirect.php';
    }

class variables_obj {
    var $vpr_plan = '';
    var $vpr_id = '';
    var $vpr_clid = '';
    var $vpr_cl_name = '';
    var $vpr_cl_phone = '';
    var $vpr_call_start_date = '';

    var $vpr_db_account = '';

    var $vpr_db_fname = '';
    var $vpr_db_mname = '';
    var $vpr_db_lname = '';

    var $vpr_rp_fname = '';
    var $vpr_rp_mname = '';  
    var $vpr_rp_lname = ''; 

    var $vpr_rp_address = '';
    var $vpr_rp_city = '';
    var $vpr_rp_state = '';
    var $vpr_rp_zipcode = '';

    var $vpr_rp_phonenum = '';
    var $vpr_rp_phonetype = '';

    var $vpr_date_entered = '';
    var $newrecdt = '';

    var $vpl_day_offset = '';
    var $vpl_action = '';       

    var $vpr_promocode = '';

}
function ScrubPhone($old_phone_num) {
    $phone_length = strlen($old_phone_num);
    $new_phone_num = "";

    for($i = 0; $i < $phone_length; $i = $i + 1) {
        if(is_numeric($old_phone_num[$i])) {
            $new_phone_num .= $old_phone_num[$i];
        }
    }
    return $new_phone_num;
}

function ScheduleCreated($link, $vars) {

    $query = "UPDATE v_payreminder SET vpr_schedule_created = '1' WHERE vpr_id='".$vars->vpr_id."'";

    if (!mysql_query($query,$link)) {
        die('Error: ' . mysql_error());
    }

    return true;    
}


function CreateScheduleRow($link, $vars){

//  echo "vpl_day_offset: ".$vars->vpl_day_offset."<br>";
//  echo "vpl_action: ".$vars->vpl_action."<br>";

    $plus_days = " +".$vars->vpl_day_offset." days";

//  echo "plus days: ".$plus_days."<br>";

    $date_offset = strtotime(date("Y-m-d", strtotime($vars->vpr_date_entered)).$plus_days);
    $date_offset = date("Y-m-d", $date_offset);
//  echo "date_offset: ".$date_offset."<br>";


//  $date_offset = strtotime(date("Y-m-d",strtotime($vars->vpr_date_entered))." +".$vars->vpl_day_offset." days");
//  $date_offset = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");  

//  echo "date_offset: ".$date_offset."<br>";   

    $query = "INSERT INTO   v_pr_schedule (
                                    vpr_id, 
                                    vsc_plan, 
                                    vsc_date_entered, 
                                    vsc_action, 
                                    vsc_action_date, 
                                    vsc_status
                                    ) VALUES (
                                    '$vars->vpr_id',
                                    '$vars->vpr_plan',
                                    '$vars->vpr_date_entered',
                                    '$vars->vpl_action',
                                    '$date_offset',
                                    'VACT')";

//echo "query: ".$query."<br>"; 

    if (!mysql_query($query,$link)) {
        die('Error: ' . mysql_error());
    }

    return true;    
}

function CreateSchedule($link, &$vars) {
//  CREATE SCHEDULE

    $query = "  SELECT  vpl_day_offset, vpl_action, vpl_condition 
                    FROM        v_plan 
                    WHERE       vpl_plan = '".$vars->vpr_plan."'"; 

//  echo "query: ".$query."<br>";

    $qresult = mysql_query($query);

    if (!$qresult) {
        print(mysql_error());
    }

    if ($qresult && mysql_num_rows($qresult) > 0 ) {
        while ($row = mysql_fetch_array($qresult, MYSQL_ASSOC)) {
            $vars->vpl_day_offset = $row['vpl_day_offset'];
            $vars->vpl_action = $row['vpl_action'];
            if ($row['vpl_condition'] == 'OO') {        
                CreateScheduleRow($link, $vars);
            }
        }
    }
    return true;
}

function InsertIntoPayReminder($link, &$vars) {     

$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");

//echo "Client Name: ".$vars->vpr_cl_name."<br><br>";
//exit();

    $sql="INSERT INTO v_payreminder (
                            vpr_clid,
                            vpr_cl_name,
                            vpr_cl_phone,
                            vpr_call_start_date,
                            vpr_db_account,
                            vpr_db_fname,
                            vpr_db_mname,
                            vpr_db_lname,
                            vpr_rp_fname,
                            vpr_rp_mname,
                            vpr_rp_lname,
                            vpr_rp_phonenum,
                            vpr_rp_phonetype,
                            vpr_rp_address,
                            vpr_rp_city,
                            vpr_rp_state,
                            vpr_rp_zipcode,
                            vpr_promo,
                            vpr_date_entered) VALUES (
                            '$vars->vpr_clid', 
                            '$vars->vpr_cl_name',
                            '$vars->vpr_cl_phone',
                            '$vars->vpr_call_start_date',
                            '$vars->vpr_db_account',
                            '$vars->vpr_db_fname',
                            '$vars->vpr_db_mname',
                            '$vars->vpr_db_lname',
                            '$vars->vpr_rp_fname',
                            '$vars->vpr_rp_mname',
                            '$vars->vpr_rp_lname',
                            '$vars->vpr_rp_phonenum',
                            '$vars->vpr_rp_phonetype',
                            '$vars->vpr_rp_address',
                            '$vars->vpr_rp_city',
                            '$vars->vpr_rp_state',
                            '$vars->vpr_rp_zipcode',
                            '$vars->vpr_promocode',
                            '$vars->vpr_date_entered')";

    if (!mysql_query($sql,$link)) {
        die('Error2: ' . mysql_error());
    }

    return true;
}

function GetVpr_Id($link, &$vars) {

    // Find out what vpr_id is
    $query = "SELECT vpr_id FROM v_payreminder ";
    $query .= "WHERE vpr_clid = '".$vars->vpr_clid."' AND vpr_date_entered = '".$vars->vpr_date_entered."'";

    $qresult = mysql_query($query);

    if (!$qresult) {
        print(mysql_error());
    }

    if ($qresult && mysql_num_rows($qresult) > 0 ) {
        $row = mysql_fetch_array($qresult, MYSQL_ASSOC);
        $vars->vpr_id = $row['vpr_id'];
    }
}

function InsertInActivity($link, $vars) {
// ENTER INTO ACTIVITY

    $vaction_desc = 'PATIENT ENTERED';

     $sql = "INSERT INTO    v_pr_activity (
                                    vpr_id, 
                                    va_plan, 
                                    va_action_dttm, 
                                    va_action_code, 
                                    va_action_desc,
                                va_disposition_code,
                                    va_disposition_desc,
                                    va_status_code,
                                va_status_desc 
                                    ) VALUES (
                                    '$vars->vpr_id',
                                    '$vars->vpr_plan',
                                    '$vars->vpr_date_entered',
                                'VINIT',
                                    '$vaction_desc', 
                                    'SUCCESS',
                                    'SUCCESS',
                                    'VACT',
                                    'ACTIVE' 
                                    )";

    if (!mysql_query($sql,$link)) {
        die('Error: ' . mysql_error());
    }

}

include './includes/dblogin.php';

$vars = new variables_obj(); 

    $vars->vpr_plan = 'VP01';
    $vars->vpr_clid = $_SESSION['userid'];


//-------------------------------------------------------
// No commas can be in client name or they will
// mess up the Global Connect CSV file.
//-------------------------------------------------------
    $vpr_cl_name = $_SESSION['username'];
    $vpr_cl_name = str_replace(",", " ", $vpr_cl_name);

    $vars->vpr_cl_name = $vpr_cl_name;      
//-------------------------------------------------------
//-------------------------------------------------------

    $vars->vpr_cl_phone = ScrubPhone($_SESSION['uphone']);
    $vars->vpr_call_start_date = '0000-00-00';

    $vars->vpr_db_account = $_POST['ndaccnum'];

    $vars->vpr_db_fname = $_POST['ndfreqname'];
    $vars->vpr_db_mname = $_POST['ndmname'];
    $vars->vpr_db_lname = $_POST['ndlreqname'];

    $vars->vpr_rp_fname = $_POST['ndrfreqname'];
    $vars->vpr_rp_mname = $_POST['ndrmname'];  
    $vars->vpr_rp_lname = $_POST['ndrlreqname']; 

    $vars->vpr_rp_address = '';
    $vars->vpr_rp_city = '';
    $vars->vpr_rp_state = $_POST['ndrstatereqname'];
    $vars->vpr_rp_zipcode = $_POST['ndrreqzipcode'];

    $phonenumber = $_POST['1ndrreqphone'].$_POST['2ndrreqphone'].$_POST['3ndrreqphone'];

    $vars->vpr_rp_phonenum = $phonenumber;
    $vars->vpr_rp_phonetype = $_POST['treqphone'];

    $vars->vpr_date_entered = date('Y-m-d H:i:s');
    $vars->newrecdt = date('Ymd');

    $vars->vpr_promocode = $_POST['promocode'];


//  echo "vpr_plan: ".$vars->vpr_plan."<br>";
//  echo "vpr_date_entered: ".$vars->vpr_date_entered."<br>";
//  echo "newrecdt: ".$vars->newrecdt."<br>";
//  echo "vpr_clid: ".$vars->vpr_clid."<br>";
//  echo "vpr_id: ".$vars->vpr_id."<br>";

    $result = InsertIntoPayReminder($link, $vars);
    $result = GetVpr_Id($link, $vars);
    $result = InsertInActivity($link, $vars);
    $result = CreateSchedule($link, $vars); 
    $result = ScheduleCreated($link, $vars);

//  echo "vpr_id: ".$vars->vpr_id."<br>";

    mysql_close($link);     

 // redirect       
   $redirect = 'vpayremind.php';   
    include  './includes/redirect.php';
?>

推荐答案

好的,请参考以下几行.

okay referencing the following lines..

if ( $vpr_clid == 199 ) {

    $vpr_cl_name = "Shelley Madsen And Associates";
}

$result = InsertIntoPayReminder($link, $vars);


...and then:

function InsertIntoPayReminder($link, &$vars) {     

    $vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");

so on and so forth... }

好像没有在实际设置类对象的值.您似乎在将一些任意的php变量设置为所需的名称,然后将一个完全不同的'$ vars'对象传递给该函数.我看不出有任何理由相信传递给函数调用的'$ vars'包含要包含的名称值.在传递值之前,应先分配"$ vars"的值.

it doesnt seem as if you are actually setting the value of the class object. You seem to be setting some arbitrary php variable to the name you want, and then passing a totally different ' $vars ' object into the function. I don't see any reason to believe that the ' $vars ' you are passing into the function call contains the name value you want it to contain. You should be assigning the value of ' $vars ' before passing it in.

例如:

if ( $vpr_clid == 199 ) {

    $vars[ 'vpr_cl_name' ] = "Shelley Madsen And Associates";
}

然后您可以一起摆脱此行:

then you can get rid of this line all together:

$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");

这篇关于在PHP中使用If语句但不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆