dpoh61610 2019-01-10 00:47 采纳率: 100%
浏览 48
已采纳

在PHP中使用If语句但不起作用

enter image description here

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";
      }

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)

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

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

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);

enter image description here

<?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';
?>
  • 写回答

1条回答 默认 最新

  • doskmc7870 2019-01-10 02:17
    关注

    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... }
    

    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.

    For instance:

    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, "'", " ");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?