-2

I am trying to send selected check-box data through mail in the tables structure but getting below error:

implode(): Invalid arguments passed

static function mcontent($chkbox){
    $sql = "SELECT station,reach,language,rate FROM `radio_city` where chkid in (".implode(',', $chkbox).")";
    return DB::select($sql);
}

Please help. Thanks Jyoti

View1: this is used while sending data through mail

<input type="hidden" name="checkbox" id="checkbox" >
              <input type="hidden" name="hiddamount" id="hiddamount">
              <input type="email" name="email" id="email">&nbsp;&nbsp;
              <input type="submit" id="submit" class="button" style="box-shadow: 5px 5px 3px #888888;" value="Email Plan" onsubmit="return validateForm();checkbox();"/>

function checkbox(){
  if (document.myForm.checkbox.checked){
    document.getElementById("error").innerHTML = "";
    return true;
  }
  else {
    document.getElementById("error").innerHTML = "Select your Plans";
  }
}

View2: this is used while selecting checkboxes

<td onchange="Process(this.options[this.selectedIndex].value)" class="chart_row" align="center" >
    <input type="checkbox" name="checkbox[<?php echo $i; ?>]" id="checkbox" value="<?php echo $chkid; ?>" data-price="<?php echo $total; ?>" onChange="updateTotal(this);">
</td>
<td id="station" class="chart_row" align="center"><?= $result->station ?></td>
<td id="reach" class="chart_row" align="center"><?= $result->reach ?></td>
<td id="language" class="chart_row" align="center"><?= $result->language ?></td>
<td id="rate" class="chart_row" align="center">Rs <?= $result->rate ?>/-</td>
<td id="duration" class="chart_row" align="center"><?= $duration ?></td>
<td id="frequency" class="chart_row" align="center"><?= $frequency ?></td>
<td id="hours" class="chart_row" align="center"><?= $hours ?></td>
<?php $totals += ($result->rate) * $duration * $frequency * $hours * $days/10; ?></div>
</tr>

Controller:

function mail() {
    $input = Input::get();
    if (isset($_GET['checkbox'])){
        $city = $_GET['city'];
        $duration = $_GET['duration'];
        $frequency = $_GET['frequency'];
        $hours = $_GET['hours'];
        $days = $_GET['days'];
        $total = $_GET['hiddamount'];
        $chkbox = $_GET['checkbox'];
        $mailrslt = Radio::mcontent($chkbox); 
        $cityname = Radio::getall($input);
        foreach($cityname as $cities){
            //modify table ans add css here if you want.
            $html_table ="<table><caption>City: ".$cities->city."</caption><thead style='color:A0A0A0'><th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Station</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Reach</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Language</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Rate</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Jingle Lenght</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Frequency</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Hours/Day</th>
                                <th width='200' align='center' class='tabledata' style='background: #f9f9f9;color: #000000;;border-bottom: 1px solid #d6d6d6;border-right: 1px solid #d6d6d6;padding: 5px 10px;'>Days/Week</th></thead><tbody style='color: #000000;'>";}
                //whole query result is here
                                foreach($mailrslt as $key=>$row) {
                                $html_table .= "<tr>";
                //Iterate your data for table data.
                                foreach($row as $key2=>$row2){                    
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $row2 . "</td>";
                                        }
                //Database data ends here
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $duration . "</td>";
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $frequency . "</td>";
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $hours . "</td>";
                                $html_table .= "<td width='200' align='center' class='tabledata'>" . $days . "</td>";
                                        } //table rows ends here for displaying data
                                $html_table .= "</tr></tbody></table>";
                //contact details and total calculation done here
                                $html_table .= "<p>The total negotiable cost for your activity is <b>Rs ".$total."/-</b></p><div float='right'></p><u><b>For Best Rates</b></u></br> Call: Samir-+919686595443</br>Email: samir@themediaant.com</p></div>";
                                $to = $input['email'];//user email id from form.
            $from = 'help@themediaant.com';//from email ID
            $subject = 'Self Help Radio Planner';//subject
            $totals = 0;

            $message = $html_table;//assigning html_table variable to message.
            $contact_enquiry = new ContactEnquiry;
            $contact_enquiry->email = $from;
            $contact_enquiry->message = $message;
            $contact_enquiry->save();
//final mail function goes here
            $mail = Mail::send('emails.media_option_assistance', ['msg' => $message], function ($msg) use ($from, $to, $subject) {
                $msg->from($from, 'The Media Ant');
                $msg->to($to)->subject($subject);//->cc('servicing@themediaant.com');
            });
        //after successful mail redirect user to same page.
            return Redirect::to('/radio-plan/radioplan')->with('message','<b>Congratulations! You have succesfully sent the email');
    }       

}

Model:

static function mcontent($chkbox){
    $sql = "SELECT station,reach,language,rate FROM `radio_city` where chkid in (".implode(',', $chkbox).")";
    return DB::select($sql);
}
tereško
  • 58,060
  • 25
  • 98
  • 150
Jyoti Duhan
  • 988
  • 1
  • 16
  • 26

1 Answers1

0

Your problem is here

$chkbox = $_GET['checkbox'];
$mailrslt = Radio::mcontent($chkbox); 

implode requires the second parameter (or the first if only one is supplied) to be an array. You are providing mcontent with a string that you get from the input. So when you reach implode inside mcontent, you are trying to convert a string to a string.

So you must either create an array with one or more variables to be passed to your function, or remove the implode from the function.

I would try to help more but honestly I don't understand much from your code and it would be a guessing game.

  • now i m trying as $chkbox = array($_GET['checkbox']); but its showing new error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1 (SQL: SELECT station,reach,language,rate FROM `radio_city` where chkid in ()) (Bindings: array ( )) – Jyoti Duhan May 22 '14 at 06:50
  • @user3660137 can you take a look at your mysql log to see the query that is being run ? – Catalin Deaconescu May 22 '14 at 07:01
  • there is nothing much info under mysql logs. but when i am trying with var_dump, atleast mail functionality is working but no data is going in table – Jyoti Duhan May 22 '14 at 07:48
  • Ok, so I just noticed that your error message ended with `where chkid in ()`. Do you didn't receive the `$chkbox` at that time. And your last comment confused me. Are you still getting the error? Is the email being sent? How exactly are you adding data to the DB ? – Catalin Deaconescu May 22 '14 at 08:00
  • mail is being sent through var_dump but table in the mail body is going without checked data and that data should be sent as a result of model i have listed above in question – Jyoti Duhan May 22 '14 at 09:33
  • Have you tested out the query to see if it returns any data ? Also, have you checked that `$_GET['checkbox']` isn't empty / is set ? – Catalin Deaconescu May 22 '14 at 12:05