How to avoid code being inserted into database - php

How to avoid code being inserted into database(Eg: ) while still maintaining the css applied on the div's from a textbox. Please see the image below and look for column openletter you will see html code is being inserted into this column. There are div's along with css being inserted. I know it sounds silly but how to avoid these codes being inserted into db. I have attached my model,view and controller codes below.
My model code is (student.php):
public function updatestudent($open_id, $from, $to, $openletter, $featured, $title, $archieve, $latest, $sponsor, $image, $category)
{
$data = array('open_id'=>$open_id, 'from'=>$from, 'to'=>$to, 'openletter'=>$openletter, 'featured'=>$featured, 'title'=>$title, 'archieve'=>$archieve, 'latest'=>$latest, 'sponsor'=>$sponsor, 'image'=>$image, 'category'=>$category);
$this->db->where('open_id', $open_id);
return($this->db->update('country',$data));
}
My controller code is(home.php):
public function editstudent($open_id)
{
$query['data']=$this->student->showstudentCon($open_id);
if (isset($_POST['submit']))
{
$this->form_validation->set_rules('open_id', 'open_id', 'required');
$this->form_validation->set_rules('from', 'from', 'required');
$this->form_validation->set_rules('to', 'to', 'required');
$this->form_validation->set_rules('openletter', 'openletter', 'required');
$this->form_validation->set_rules('featured', 'featured', 'required');
$this->form_validation->set_rules('title', 'title', 'required');
$this->form_validation->set_rules('archieve', 'archieve', 'required');
$this->form_validation->set_rules('latest', 'latest', 'required');
$this->form_validation->set_rules('sponsor', 'sponsor', 'required');
$this->form_validation->set_rules('image', 'image', 'required');
$this->form_validation->set_rules('category', 'category', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('file/header');
$this->load->view('file/menu');
$this->load->view('form', $query);
$this->load->view('file/footer');
}
else {
$open_id=$_POST['open_id'];
$from=$_POST['from'];
$to=$_POST['to'];
$openletter=$_POST['openletter'];
$featured=$_POST['featured'];
$title=$_POST['title'];
$archieve=$_POST['archieve'];
$latest=$_POST['latest'];
$sponsor=$_POST['sponsor'];
$image=$_POST['image'];
$category=$_POST['category'];
$result=$this->student->updatestudent($open_id, $from, $to, $openletter, $featured, $title, $archieve, $latest, $sponsor, $image, $category);
if($result)
{
$this->load->view('file/header');
$this->load->view('file/menu');
echo "<div class='success'>";
echo "Successfully Updated";
echo "</div>";
$this->load->view('file/footer');
}
else {
$this->load->view('file/header');
$this->load->view('file/menu');
echo "<div class='error'>";
echo "Somthins Is Missing";
echo "</div>";
$this->load->view('file/footer');
}
}
}
else {
$this->load->view('file/header');
$this->load->view('file/menu');
$this->load->view('form', $query);
$this->load->view('file/footer');
}
}
My view Code is (demoview.php):
<script>
$(document).ready(function() {
$('#datatable').DataTable();
} );
</script>
<div class="content">
<h2>Welcome Back, <?php echo $name=$this->session->userdata('username'); ?>!</h2>
<h2>Open Letters</h2>
<div class="divider"></div>
<br/>
<?php
echo "<table style='border: 1px solid black' id='datatable' class='display' cellspacing='0' width='100%'>";
$head="<thead>
<tr style='border: 1px solid black'>
<th>From</th>
<th>To</th>
<th>Title</th>
<th>open_id</th>
<th>archieve</th>
<th>latest</th>
<th>sponsor</th>
<th>Image</th>
<th>category</th>
</tr>
</thead>";
$foot="<tfoot>
<tr style='border: 1px solid black'>
<th>From</th>
<th>To</th>
<th>Title</th>
<th>open_id</th>
<th>archieve</th>
<th>latest</th>
<th>sponsor</th>
<th>Image</th>
</tr>
</tfoot>";
echo $head;
echo $foot;
echo "<tbody>";
foreach($query as $row)
{
echo "<tr style='border: 1px solid black'>";
echo "<td style='border: 1px solid black'>";
echo $row->from;
echo "</td><td style='border: 1px solid black'>";
echo $row->to;
echo "</td><td style='border: 1px solid black'>";
echo $row->title;
echo "</td><td style='border: 1px solid black'>";
echo $row->open_id;
echo "</td><td style='border: 1px solid black'>";
echo $row->archieve;
echo "</td><td style='border: 1px solid black'>";
echo $row->latest;
echo "</td><td style='border: 1px solid black'>";
echo $row->sponsor;
echo "</td><td style='border: 1px solid black'>";
echo $row->image;
echo "</td><td style='border: 1px solid black'>";
echo $row->category;
echo "</td><td style='border: 1px solid black'>";
echo "<a href='".base_url('index.php/home/editstudent').'/'.$row->open_id."'>Edit </a><a href='".base_url('index.php/home/deletestudent').'/'.$row->open_id."'>Delete</a>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
<h4><?php echo anchor('home/logout', 'Logout'); ?></h4>
</div><!--<div class="content">-->

First in your Model you don't need to return an update simply do
public function updatestudent($open_id, $from, $to, $openletter, $featured, $title, $archieve, $latest, $sponsor, $image, $category)
{
$data = array('open_id'=>$open_id, 'from'=>$from, 'to'=>$to, 'openletter'=>$openletter, 'featured'=>$featured, 'title'=>$title, 'archieve'=>$archieve, 'latest'=>$latest, 'sponsor'=>$sponsor, 'image'=>$image, 'category'=>$category);
$this->db->where('open_id', $open_id);
$this->db->update('country',$data);
}
Secondly it is engouh to just do $openletter = strip_tags($_POST['openletter']);
And the html will be gone. please see strip_tags

strip_tags — Strip HTML and PHP tags from a string
string strip_tags ( string $str [, string $allowable_tags ] )
SOURCE: Official Documentation
So, using strip_tags your controller will have:
$openletter=strip_tags($_POST['openletter']);

You can use strip_tags in your model file :-
public function updatestudent($open_id, $from, $to, $openletter, $featured, $title, $archieve, $latest, $sponsor, $image, $category)
{
$openletter = strip_tags($openletter);
$data = array('open_id'=>$open_id, 'from'=>$from, 'to'=>$to, 'openletter'=>$openletter, 'featured'=>$featured, 'title'=>$title, 'archieve'=>$archieve, 'latest'=>$latest, 'sponsor'=>$sponsor, 'image'=>$image, 'category'=>$category);
$this->db->where('open_id', $open_id);
return($this->db->update('country',$data));
}
It may help you.

Related

Add Input Text Field in the php form and store data in file also show that text in Dynamic Table

I Have created a Program (Doctors on Leave Add/Remove Dynamically) which selects the dates from the user then select which doctor to leave and Now I want to add text input field for remarks & also show it in a table from the file I'm saving the content in..
Can Anyone help me with that please
This is my code
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$data = $_POST["doctorName"].";".$_POST["leaveFrom"].";".$_POST["leaveTo"].";";
$fp = fopen('file-path', 'a');
fwrite($fp, $data);
fclose($fp);
header("Location: #");
exit();
}
if ($_SERVER["REQUEST_METHOD"] == "GET") {
if(array_key_exists("n", $_GET)){
$newNames = "";
$filename = "file-path";
$lines = file($filename, FILE_IGNORE_NEW_LINES);
$arr_del = explode(";", $lines[0]);
for($i = 0; $i < count($arr_del)-1; $i++){
if($arr_del[$i] == $_GET["n"]){
$i = $i+2;
} else {
$newNames .= $arr_del[$i].";";
}
}
$fp = fopen('file-path', 'w');
fwrite($fp, $newNames);
fclose($fp);
header("Location: #");
exit();
}
}
?>
<html>
<body>
<center><h2>Doctor on Leave</h2></center>
<?php
$data = file_get_contents("file-path");
$arr = explode(";", $data);
echo "<table style=\"border: 1px solid black;\">";
echo "<thead>";
echo "<tr style=\"border: 1px solid black;\">";
echo "<th style=\"border: 1px solid black;\">Doctor Name</th>";
echo "<th style=\"border: 1px solid black;\">Delete</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
for($value = 0; $value < count($arr)-1; $value=$value+3) {
echo "<tr style=\"border: 1px solid black;\">";
echo "<td style=\"border: 1px solid black;\">".$arr[$value]."</td>";
echo "<td style=\"border: 1px solid black;\">"."<button id=\"".$arr[$value]."\"
onclick=\"deleteDoctor(this.id)\" style=\"background-color: red;
color:white\">Delete</button>"."</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
<form action="/" method="POST">
<label>Select the Doctor </label><br>
<select name="doctorName" style="width:300px;">
<option value="Dr. Ankur Mittal">Dr. Ankur Mittal</option>
<option value="Dr. Anooj Chatley">Dr. Anooj Chatley</option>
<option value="Dr. Arti Gupta Tuli">Dr. Arti Gupta Tuli</option>
<option value="Dr. Ashok Goyal">Dr. Ashok Goyal</option>
<option value="Dr. H.S. Bindra">Dr. H.S. Bindra</option>
</select>
<br><br>
<p>From</p>
<input type="text" onfocus="(this.type='date')" id="leaveFrom" name="leaveFrom"
placeholder="DD-MM-YYYY" style="width:fit-content;">
<br><br>
<p>To</p>
<input type="text" onfocus="(this.type='date')" id="leaveTo" name="leaveTo"
placeholder="DD-MM-YYYY" style="width:fit-content;">
<br><br><input type="submit">
</form>
<script>
function deleteDoctor(name){
location.href= "#?n="+name;
}
</script>
</body>
</html>
Please check this code, It should work.
Changes I have done
Append $_POST['remarks'] in $data at line 3
Changed $i = $i+2; to $i = $i+3; at line 18, to remove newly added field. If you plan to add more fields in future, just increment this number by 1 every time
Added 3 columns in html table head (From, To and Remarks)
Printed values of From, To and Remarks on line 52, 53 and 54.
echo '<td style="border: 1px solid black;">'.$arr[$value+1].'</td>';
echo '<td style="border: 1px solid black;">'.$arr[$value+2].'</td>';
echo '<td style="border: 1px solid black;">'.$arr[$value+3].'</td>';
When you add more fields, just do it by incrementing 1
Lastly added a new input box at bottom <input type="text" id="remarks" name="remarks" placeholder="Remarks" style="width:fit-content;">
Feel free to comment if any problem with the updated code
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$data = $_POST["doctorName"].";".$_POST["leaveFrom"].";".$_POST["leaveTo"].";".$_POST["remarks"].";";
$fp = fopen('file-path', 'a');
fwrite($fp, $data);
fclose($fp);
header("Location: #");
exit();
}
if ($_SERVER["REQUEST_METHOD"] == "GET") {
if(array_key_exists("n", $_GET)){
$newNames = "";
$filename = "file-path";
$lines = file($filename, FILE_IGNORE_NEW_LINES);
$arr_del = explode(";", $lines[0]);
for($i = 0; $i < count($arr_del)-1; $i++){
if($arr_del[$i] == $_GET["n"]){
$i = $i+3;
} else {
$newNames .= $arr_del[$i].";";
}
}
$fp = fopen('file-path', 'w');
fwrite($fp, $newNames);
fclose($fp);
header("Location: #");
exit();
}
}
?>
<html>
<body>
<center><h2>Doctor on Leave</h2></center>
<?php
$data = file_get_contents("file-path");
$arr = explode(";", $data);
echo '<table style="border: 1px solid black;">';
echo '<thead>';
echo '<tr style="border: 1px solid black;">';
echo '<th style="border: 1px solid black;">Doctor Name</th>';
echo '<th style="border: 1px solid black;">From</th>';
echo '<th style="border: 1px solid black;">To</th>';
echo '<th style="border: 1px solid black;">Remarks</th>';
echo '<th style="border: 1px solid black;">Delete</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
for($value = 0; $value < count($arr)-1; $value=$value+4) {
echo '<tr style="border: 1px solid black;">';
echo '<td style="border: 1px solid black;">'.$arr[$value].'</td>';
echo '<td style="border: 1px solid black;">'.$arr[$value+1].'</td>';
echo '<td style="border: 1px solid black;">'.$arr[$value+2].'</td>';
echo '<td style="border: 1px solid black;">'.$arr[$value+3].'</td>';
echo '<td style="border: 1px solid black;">'.'<button id="".$arr[$value].""
onclick="deleteDoctor(this.id)" style="background-color: red;
color:white">Delete</button>'.'</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
?>
<form action="asd.php" method="POST">
<label>Select the Doctor </label><br>
<select name="doctorName" style="width:300px;">
<option value="Dr. Ankur Mittal">Dr. Ankur Mittal</option>
<option value="Dr. Anooj Chatley">Dr. Anooj Chatley</option>
<option value="Dr. Arti Gupta Tuli">Dr. Arti Gupta Tuli</option>
<option value="Dr. Ashok Goyal">Dr. Ashok Goyal</option>
<option value="Dr. H.S. Bindra">Dr. H.S. Bindra</option>
</select>
<br><br>
<p>From</p>
<input type="text" onfocus="(this.type='date')" id="leaveFrom" name="leaveFrom" placeholder="DD-MM-YYYY" style="width:fit-content;">
<br><br>
<p>To</p>
<input type="text" onfocus="(this.type='date')" id="leaveTo" name="leaveTo" placeholder="DD-MM-YYYY" style="width:fit-content;">
<br><br>
<p>Remarks</p>
<input type="text" id="remarks" name="remarks" placeholder="Remarks" style="width:fit-content;">
<br><br><input type="submit">
</form>
<script>
function deleteDoctor(name){
location.href= "#?n="+name;
}
</script>
</body>
</html>

How do i put a <td> in my <table> with php?

I’m working on a php snippet and i made a table. I tried putting a td tag inside but when i do this, a lot disappears. This is a piece of my code:
//Use the functions of the client, the params of the function are in
//the associative array
$params = array('customerid' => '1532');
$response = $soapclient->ca_customer_products($params);
echo '<table><tbody><tr><th>Product</th><th>Naam</th> <th>Prijs</th><th>Qte</th></tr>';
echo '<table style="border-style: solid; border-width:1px;">';
foreach($response->list->element as $product) {
if($product->stock > 0) {
echo '<tr>';
echo '<td style="display: flex; border: 1px solid black;">';
//echo '<td>';
echo '<img src="' . $product->url . '" class="php_image" style="width: 15%; height: 15%;"/>';
//echo '<img style="width: 15%;">';
//echo '</td>';
print_r($product->description);
echo "<p style='color:green;'>".$product->price1."</p>";
echo "<p style='color:red; text-decoration: line-through'>".$product->price2."</p>";
print_r($product->price1);
print_r($product->price2);
print_r($product->stock);
echo '</tr>';
}
}
echo '</tbody></table>';
The code behind the // is where i tried to put the td tag but when i put it there, the images that normally appear go blank and when i inspect my code there is a lot of other code that also disappears. What am i doing wrong here?
Thank you for your help!
First I can see a problem with these lines :
echo '<table><tbody><tr><th>Product</th><th>Naam</th> <th>Prijs</th><th>Qte</th></tr>';
echo '<table style="border-style: solid; border-width:1px;">';
Because you just close your first TABLE at the end, but not the other inside :
echo '</tbody></table>';
There are some inconsistency of your <td> to <th>. You can have a look below
$params = array('customerid' => '1532');
$response = $soapclient->ca_customer_products($params);
echo '<table style="border-style: solid; border-width:1px;">
<thead>
<tr>
<th>Product</th>
<th>Naam</th>
<th>Prijs</th>
<th>Qte</th>
</tr>
</thead><tbody>';
foreach($response->list->element as $product) {
if($product->stock > 0) {
echo "<tr>
<td style='display: flex; border: 1px solid black;'>
<img src='$product->url' class='php_image' style='width: 15%; height: 15%;'/>
</td>
<td>Your product name</td>
<td>$product->description</td>
<td>
<p style='color: green;'>$product->price1</p>
<p style='color: red;'>$product->price</p>
</td>
<td>$product->stock</td>
</tr>";
}
}
echo '</tbody></table>';
?>
There's a lot problems with the code. From what i can see in your code, you have a table inside a tbody and at the end closed only one table.
Secondly you're also trying to put a td inside another td which is not the right thing to do. Check out mozilla developer website for more information on using HTML tables.
//Use the functions of the client, the params of the function are in
//the associative array
$params = array('customerid' => '1532');
$response = $soapclient->ca_customer_products($params);
echo '<table style="border-style: solid; border-width:1px;"><tbody><tr><th>Product</th><th>Naam</th> <th>Prijs</th><th>Qte</th></tr>';
foreach($response->list->element as $product) {
if($product->stock > 0) {
echo '<tr>';
echo '<td style="display: flex; border: 1px solid black;">';
//echo '<td>';
echo '<img src="' . $product->url . '" class="php_image" style="width: 15%; height: 15%;"/>';
//echo '<img style="width: 15%;">';
//echo '</td>';
print_r($product->description);
echo "<p style='color:green;'>".$product->price1."</p>";
echo "<p style='color:red; text-decoration: line-through'>".$product->price2."</p>";
print_r($product->price1);
print_r($product->price2);
print_r($product->stock);
echo '</td></tr>';
}
}
echo '</tbody></table>';
You are not closing your tags correctly. Also checkout the docs just as #christopher_bincom has mentioned.

insert in sql with mysqli and cookie in php

I have two files: Studio.php and Principale.php
In the first one i want insert in my database some values and add them also in a table of Principale.php
With the first row of the table in Principale.php and the first add in the table of my database it works, after no.
I thought to use a for loop to create more rows in the table of Principale.php
It shows me also this error : Notice: Undefined index: titolo1 in C:\xampp\htdocs\Progetto\Principale.php on line 47
I think $res2 return a value different than TRUE but i don't know why.
Code of Principale.php :
$n=$_COOKIE['idstudio'];
for ($i=1;$i<$n;$i++) {
echo "<table style='border: 1px solid black; margin-left:auto; margin-
right:auto;'><caption> <p>Esperienze di Studio</p>
</caption> <thead style='color:green;'> <tr>";
echo "<th style='border: 1px solid black;'> Titolo </th><th
style='border: 1px solid black;'> Anno </th><th style='border: 1px solid
black;'> Luogo </th> ";
echo "</tr> </thead> <tbody style='color:blue'> <tr>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["titolo$i"]."
</td>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["anno$i"]."</td>";
echo "<td style='border: 1px solid black;'>".$_COOKIE["luogo$i"]."
</td>";
echo "</tr></tbody</table><br><br>";
}
echo "</div>";
Code of Studio.php :
$luogo = $_POST["luogo"];
$anno = $_POST["anno"];
$titolo = $_POST["titolo"];
$sql6="SELECT education_experience_id FROM education_experience ORDER BY
education_experience_id DESC LIMIT 1;";
$result2=mysqli_query($connessione,$sql6);
$row2=mysqli_fetch_array($result2,MYSQLI_NUM);
$last_id2=$row2[0];
$id2 = $last_id2+1;
$eeid=$_COOKIE['id'];
$sql9="INSERT into EDUCATION_EXPERIENCE
(education_experience_id,title,year,place,user_id) VALUES
('$id2','$titolo','$anno','$luogo','$eeid')";
$res2=mysqli_query($connessione,$sql9);
echo "<br>";
mysqli_error($connessione);
if($res2 ==TRUE) {
setcookie("luogo$id2", $luogo, strtotime("+1 month"));
setcookie("anno$id2", $anno, strtotime("+1 month"));
setcookie("titolo$id2", $titolo, strtotime("+1 month"));
setcookie("idstudio",$id2,strtotime("+1 month"));
header("Location: Principale.php");
}
else
{
echo "Impossibile aggiungere Esperienza<br>";
echo "<a href='Principale.php'>Clicca Qui</a> per tornare alla pagina
principale.";
}

sending checkbox data in table through mail

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

PHP: working with tr and td with while()

<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
while ($pF = mysql_fetch_array($stringVisits)) {
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if (checkStatus($BuID) == 1) {
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if (!empty($getByProfile["photo_thumb"])) {
echo $getByProfile["photo_thumb"];
} else {
echo "noPhoto_thumb.jpg";
}
echo "'>";
?>
</a>
</td>
<?php } ?>
</tr>
</table>
This is what i have right now it displays the visiter´s profileimage. Now i would like to have their name under the image too.. but then i need to create another <tr> after this one, and add their name in each <td>. But how can i do that, if i have this while? Should i run another while, to get the names or can i do something smart with this?
Why not just stick the name in the same cell as the image? After you close the image tag, just echo $getByProfile["username"], or whatever?
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
while($pF = mysql_fetch_array($stringVisits)){
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if(checkStatus($BuID) == 1){
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if(!empty($getByProfile["photo_thumb"])) { echo $getByProfile["photo_thumb"]; }else{
echo "noPhoto_thumb.jpg";
}
echo "'><br/>";
?>
</a>
<br/><?php echo $getByProfile['username']; ?>
</td>
<?php } ?>
</tr>
</table>
Here's a way to do it with minimal changes to your existing code:
<?php
<table border="0" cellspacing="0" cellpadding="0" >
<tr>
<?php
$names = array(); // ADDITION #1
while($pF = mysql_fetch_array($stringVisits)){
$names[] = // ADDITION #2 - ADD NEW USER NAME HERE;
?>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<?php
echo "<a href='profil.php?id=".$BuID."'>";
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'";
if(checkStatus($BuID) == 1){
echo 'class="onlineBorder" ';
} else {
echo 'class="image-xxsmall-border" ';
}
echo " src='images/profilePhoto/thumbs/";
if(!empty($getByProfile["photo_thumb"])) { echo $getByProfile["photo_thumb"]; }else{
echo "noPhoto_thumb.jpg";
}
echo "'>";
?>
</a>
</td>
<?php }
// ADDITION #3:
echo "</tr>
<tr>";
foreach ($names as $username)
echo "<td class=\"username\"><p>$username</p></td>";
?>
</tr>
</table>
Also note that the way you had your code, the </tr> was inside the while loop.
this might not look nice but it should work why do you want 2 loops?
<?php
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >";
while($pF = mysql_fetch_array($stringVisits)){
echo "
<tr>
<td class="viewercell" style="color: #CCC; font-size: 10px;">
<a href='profil.php?id=".$BuID."'> <img /> </a>
</td>
</tr>
<tr><td> " . $getByProfile['username'] . " </td></tr>";
}
echo "</table>";
?>

Categories