• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Value Not Matching

#1
Hello

I seem to be having a problem which I just cannot understand.

I have 1 text input I am using to get an ID for an Event. For some reason which I just cannot understand, the value is not matching.

Code:
<form action="searchevent" method="post">
    <div class="row" style="margin-top: 20px;">
        <div class="col-md-2">
            <label style="font-size: 20px;">Event ID: </label>
        </div>
        <div class="col-md-6">
            <input type="text" class="form-control" name="eventid" placeholder="Enter the ID for the Event">
        </div>
        <input type="submit" name="getevent" value="Search">
    </div>
</form>
 Above is the simple form I have to get the ID

And below is the function which checks the value

Code:
public function searchevent() {
    $data = array();
    $eventid = $this->input->post('eventid');
    $dbname = $this->session->userdata("dbname");
    $this->db->db_select($dbname);

    $events = $this->callAPI('eventlist');

    foreach ($events['Records']['Record'] as $record) {
        if ($record['EventID'] == $eventid) {
        $fields = array(
                'displayname' => array(
                'type' => 'VARCHAR',
                'constraint' => 255,
                 'null' => FALSE
            ),
            ..... cut off for brevity
For some reason which I just cannot understand the $record['EventID'] does not match the $eventid!?  I have no clue why. This SHOULD match. I KNOW the EventID does exist in a record, I have seen it in the records. the ID is 4683. Even if I put "4683" instead of $eventid, there is no match. I have been sitting for over an hour trying to figure out why this is not matching even with the hard coded value instead of $eventid. And as I said I know the ID exists I can see it in the records.

I would be very gratefull if anyone have any ideas as to why this happening?
Reply

#2
Is the EventID in the record numeric or varchar? Sounds like a character miss-match to me.

Make sure that the recoed EventID and the $eventid are both the same type numeric or string.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(02-20-2020, 04:50 PM)InsiteFX Wrote: Is the EventID in the record numeric or varchar? Sounds like a character miss-match to me.

Make sure that the recoed EventID and the $eventid are both the same type numeric or string.


Hi!
Thanks for trying to help. I thought the same initially as well They are both strings. But even if I try:

Quote:if ($record['EventID'] == 4683)

 or
Code:
if ($record['EventID'] == "4683")
The result is the same. I truly cannot understand why this does not work.

Here is the a sample of the record:

Code:
"Date": "23-02-2020 00:00:00",
        "EventID": "4683",
        "EventSplashTime": "0",

That is why I say the record does exist.
Reply

#4
The data may be in the database but is the call to $this->callAPI('eventlist') returning that record? Try adding var_dump($events) after the $this->callAPI('eventlist'); call and see what you are actually working with.
Reply

#5
(02-21-2020, 02:32 PM)dave friend Wrote: The data may be in the database but is the call to $this->callAPI('eventlist') returning that record? Try adding var_dump($events) after the $this->callAPI('eventlist'); call and see what you are actually working with.


Hi Dave.

I have done a var dump and can see the call is returning the record and it a string.
Reply

#6
Then my next suggested debug idea is

PHP Code:
foreach ($events['Records']['Record'] as $record
{
    
var_dump($record);

Reply

#7
Here is a nice var_debug helper method to format the output, just place the code
into your own helper load and call it.

PHP Code:
// -----------------------------------------------------------------------

/**
 * varDebug () - Add this method to a CodeIgniter Helper.
 * -----------------------------------------------------------------------
 *
 * Formatted output of var_dump() etc;
 */
if ( ! function_exists('varDebug'))
{
    /**
     * Debug Helper
     * -------------------------------------------------------------------
     * Outputs the given variable(s) with color formatting and location
     *
     * @param    mixed    - variables to be output
     */
    function varDebug()
    {
        list($callee) = debug_backtrace();

        $arguments func_get_args();

        $total_arguments func_num_args();

        echo '<div><fieldset style="background: #fefefe !important; border:1px red solid; padding:15px">';
        echo '<legend style="background:lightgrey; padding:5px;">'.$callee['file'].' @line: '.$callee['line'].'</legend><pre><code>';

        $i 0;
        foreach ($arguments as $argument)
        {
            echo '<strong>Debug #'.++$i.' of '.$total_arguments.'</strong>: '.'<br>';
            var_dump($argument);
        }

        echo "</code></pre></fieldset><div><br>";

        exit;
    }

What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#8
Hello

I apologize for the late reply, work has been crazy lately.

I have done a var dump and I can see that record with the correct ID is in the Records that are returned.

I have attached a TXT file that contains the var_dump.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.