Im having problems with nested forms - php

Hello im having some problems with my forms. It says "Saw a form start tag, but there was already an active form element. Nested forms are not allowed." but when im looking in my code the forms are not even nested in my code can i have some help.
$sql8 = 'SELECT läggtill.serier, läggtill.id, läggtill.id2, läggtill.säsonger, läggtill.betyg, kategorier.kategori from läggtill inner join'
. ' kategorier on läggtill.kategorier=kategorier.id order by läggtill.serier';
$resultat8 = $mysqli->query($sql8);
$antal8 = $resultat8->num_rows;
while ($rad8 = $resultat8->fetch_assoc()) {
echo "<li>" .$rad8['serier'] .', ' .$rad8['säsonger'] .' Säsonger, ' .$rad8['kategori'] .'<br>'.
'Betyg: ' .$rad8['betyg'] .'/10 </li>' .'<br>';
$id = $rad8['id'];
?>
<?php
echo '<form action="alla.php" method="POST">
<button name=' .$id .'>Ta bort</button>
</form>'
?>
<?php
if (isset($_POST[$id])) {
$sql9 = "Delete from läggtill where id=" . $id . " LIMIT 1";
if ($resultat9 === $mysqli->query($sql9)) {
header('location: alla.php');
} else {
echo "det misslyckades.";
}
echo "asdasd";
}
$id2 = $rad8['id2'];
echo "<div class=" . 'Update' . '>'
?>
<?php
echo "<form action='alla.php' method='POST'>
<label for='serier'>Serie: </label>
<input type='text' name='serier' id='serier'><br>";
$sql14 = 'SELECT * FROM kategorier';
$resultat14 = $mysqli->query($sql14);
$antal14 = $resultat14->num_rows;
if ($antal14 == 0) {
echo 'Inget funnet';
} else {
$sql15 = 'SELECT kategori, id FROM kategorier';
$resultat15 = $mysqli->query($sql15);
$antal15 = $resultat15->num_rows;
if ($antal15 == 0) {
echo 'Inget kategori funnen';
} else {
echo 'Kategori: <select name =kategorier>';
while ($rad15 = $resultat15->fetch_assoc()) {
echo '<option value='. $rad15['id'] . '>' . $rad15['kategori'] . '</option><br>';
}
echo '</select>';
}
}
echo '<br><button name= . $id2' . '>Uppdatera</button>';
if (isset($_POST[$id2])) {
$kategorier = $_POST['kategorier'];
$betyg = $_POST['betyg'];
$serier = $_POST['serier'];
$säsonger = $_POST['säsonger'];
if(strlen($kategorier) && strlen($säsonger) && strlen($serier) && strlen($betyg)) {
$sql12 = '"UPDATE läggtill SET kategorier="" . $kategorier . "", säsonger="" . $säsonger . "", serier="" . $serier . "","
. " betyg="" . $betyg . "" WHERE id2="" . $id2 . "";';
if($resultat9 == $mysqli->query($sql12)) {
header('location: alla.php');
} else {
echo 'Det misslyckades';
}
}
}
}
echo "</form>";
echo "</div>";`**enter code here**`

check have updated few things, hope it will work out
<?php
$sql8 = 'SELECT läggtill.serier, läggtill.id, läggtill.id2, läggtill.säsonger, läggtill.betyg, kategorier.kategori from läggtill inner join'
. ' kategorier on läggtill.kategorier=kategorier.id order by läggtill.serier';
$resultat8 = $mysqli->query($sql8);
$antal8 = $resultat8->num_rows;
while ($rad8 = $resultat8->fetch_assoc()) {
echo "<li>" . $rad8['serier'] . ', ' . $rad8['säsonger'] . ' Säsonger, ' . $rad8['kategori'] . '<br>' .
'Betyg: ' . $rad8['betyg'] . '/10 </li>' . '<br>';
$id = $rad8['id'];
?>
<?php
echo '<form action="alla.php" method="POST">
<button name=' . $id . '>Ta bort</button>
</form>'
?>
<?php
if (isset($_POST[$id])) {
$sql9 = "Delete from läggtill where id=" . $id . " LIMIT 1";
if ($resultat9 === $mysqli->query($sql9)) {
header('location: alla.php');
} else {
echo "det misslyckades.";
}
echo "asdasd";
}
$id2 = $rad8['id2'];
echo "<div class=" . 'Update' . '>'
?>
<?php
echo "<form action='alla.php' method='POST'>
<label for='serier'>Serie: </label>
<input type='text' name='serier' id='serier'><br>";
$sql14 = 'SELECT * FROM kategorier';
$resultat14 = $mysqli->query($sql14);
$antal14 = $resultat14->num_rows;
if ($antal14 == 0) {
echo 'Inget funnet';
} else {
$sql15 = 'SELECT kategori, id FROM kategorier';
$resultat15 = $mysqli->query($sql15);
$antal15 = $resultat15->num_rows;
if ($antal15 == 0) {
echo 'Inget kategori funnen';
} else {
echo 'Kategori: <select name =kategorier>';
while ($rad15 = $resultat15->fetch_assoc()) {
echo '<option value=' . $rad15['id'] . '>' . $rad15['kategori'] . '</option><br>';
}
echo '</select>';
}
}
echo '<br><button name= . $id2' . '>Uppdatera</button></form>';
if (isset($_POST[$id2])) {
$kategorier = $_POST['kategorier'];
$betyg = $_POST['betyg'];
$serier = $_POST['serier'];
$säsonger = $_POST['säsonger'];
if (strlen($kategorier) && strlen($säsonger) && strlen($serier) && strlen($betyg)) {
$sql12 = '"UPDATE läggtill SET kategorier="" . $kategorier . "", säsonger="" . $säsonger . "", serier="" . $serier . "","
. " betyg="" . $betyg . "" WHERE id2="" . $id2 . "";';
if ($resultat9 == $mysqli->query($sql12)) {
header('location: alla.php');
} else {
echo 'Det misslyckades';
}
}
}
}
echo "</div>";

Related

How can I use mysql in a better way to improve loading time?

I have a php script that is gathering information from 6 different databases. And if that list includes 50 items, than I have around 50-200 queries to get all the information for all the items in a while loop.
I have today tried different "function()" in PHP to use on all the items, and I tried to fiddel around with inner join in MySQL without any results. And all my databases have similair names, like id, device etc.
PHP code i use for viewing the page (a bit altered, but just to show my thinking):
<?php
if(!empty($_GET['tel_sort'])) {
global $conn; //SQL connection
global $device_kost;
$tel_sort = $_GET['tel_sort'];
$result = mysqli_query($conn,"SELECT * FROM $device_kost WHERE id = $tel_sort ORDER BY prod, model");
} elseif(!empty($_GET['prod_sort'])) {
global $conn; //SQL connection
global $device_kost;
$prod_sort = $_GET['prod_sort'];
$result = mysqli_query($conn,"SELECT * FROM $device_kost WHERE prod = '$prod_sort' AND priv = 1 ORDER BY prod, model");
} else {
$result = mysqli_query($conn,"SELECT * FROM $device_kost WHERE priv = 1 ORDER BY prod, model");
}
$telesort = mysqli_query($conn,"SELECT * FROM $device_kost WHERE priv = 1 ORDER BY prod, model");
$prodsort = mysqli_query($conn,"SELECT * FROM $device_kost WHERE priv = 1 GROUP BY prod ORDER BY prod");
function ab($tel) {
global $conn;
global $device_max;
$telque = mysqli_query($conn,"SELECT * FROM $device_max WHERE device = '$tel'");
$telres = mysqli_fetch_assoc($telque);
return $telres;
}
function ts($tel) {
global $conn;
global $device_ts;
$current_date = date("Y-m-d");
$telque = mysqli_query($conn,"SELECT * FROM $device_ts WHERE device = '$tel' AND date_f <= '$current_date' AND date_t >= '$current_date'");
$telres = mysqli_fetch_assoc($telque);
return $telres;
}
function device($tel) {
global $conn;
global $device_kost;
$telque = mysqli_query($conn,"SELECT * FROM $device_kost WHERE type = '1'");
$telres = mysqli_fetch_assoc($telque);
return $telres;
}
function color($price, $kost, $ukon, $ts, $ab = NULL) {
if(!isset($price)) { $priceumoms="0"; } else { $priceumoms = $price; }
$priceumoms = $priceumoms / 1.25;
if($ts=="n/a" || empty($ts)) { $ts="0"; }
$totpris = $priceumoms + $ts;
$db = $totpris - $kost;
$dg = $db * 100;
if ($totpris == 0) {
$dg = "";
} else {
$dg = $dg / $totpris;
}
$dg = round($dg, 2);
$dg = $dg . "%";
if($db>=1200) { $colors="#006600"; } elseif($db>=900) { $colors="#00AA00"; } elseif($db>=700) { $colors="#00FF00"; } elseif($db>=500) { $colors="#FFFF00"; } elseif($db>=300) { $colors="#FF6600"; } else { $colors="#FF0000"; }
if($price==NULL) { $db = "n/a"; $colors = "#888888"; $price = "n/a"; $dg = "n/a";}
$color = array(
"db" => "$db",
"color" => "$colors",
"ts" => "$ts",
"price" => "$price",
"dg" => "$dg", );
return $color;
}
?>
<p>
<table>
<thead>
<tr>
<th>Device sort</th>
</th>Prod sort</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<form action="" method="get">
<?php
if(isset($_GET['ab_sort'])) {
echo "<input type=hidden name=\"ab_sort\" value=\"" . $_GET['ab_sort'] . "\">\n";
}
?>
<select name="dev_sort" style="width: 20em;" onchange="this.form.submit()">
<option value="">Show all</option>
<?php
while($row = mysqli_fetch_array($telesort)) {
$id = $row['id'];
$prod = $row['prod'];
$model = $row['model'];
echo " <option value=\"$id\">$prod $model</option>\n";
}
?>
</select>
<input type=submit value="Update"></form></td>
<td>
<form action="" method="get">
<?php
if(isset($_GET['tel_sort'])) {
echo "<input type=hidden name=\"tel_sort\" value=\"" . $_GET['tel_sort'] . "\">\n";
}
if(isset($_GET['prod_sort'])) {
echo "<input type=hidden name=\"prod_sort\" value=\"" . $_GET['prod_sort'] . "\">\n";
}
?>
<input type=submit value="Oppdater"></form></td>
</tr>
<tr>
<td>
<form action="" method="get">
<?php
if(isset($_GET['ab_sort'])) {
echo "<input type=hidden name=\"ab_sort\" value=\"" . $_GET['ab_sort'] . "\">\n";
}
?>
<select name="prod_sort" style="width: 20em;" onchange="this.form.submit()">
<option value="">Show all</option>
<?php
while($row = mysqli_fetch_array($prodsort)) {
$id = $row['id'];
$prod = $row['prod'];
echo " <option value=\"$prod\">$prod</option>\n";
}
?>
</select>
<input type=submit value="Update"></form></td>
</tr>
</tbody>
</table>
</p>
<?php
if (is_array($ab_vis)) {
$count = count($ab_vis);
} else {
$count = 1;
}
$width = $count*130;
$width = $width+400;
echo "<table border='1' width=\"" . $width . " px\" id=\"mytable\">
<thead>
<tr>
<th><div title=\"$db_table_naming\">prod</th>
<th>model</th>\n";
if($count > 1) {
foreach($ab_vis as $ab) {
echo "<th>" . $ab . "</th>\n";
}
} else {
echo "<th>$ab_vis</th>\n";
}
echo "</tr>
</thead>\n";
$mndpr = "";
while($row = mysqli_fetch_array($result)) {
echo "<tbody>\n<tr class=\"mark\">";
$device = $row['id'];
$ab = ab($device);
$kost = $row['kost'];
$ts = ts($device);
$ukon = $row['ukon'];
if($ukon=="1") { $tdcolor = "#0099FF"; } else { $tdcolor = "#FFFFFF"; }
echo "<td bgcolor=\"" . $tdcolor . "\">" . $row['prod'] . "</td>\n";
echo "<td bgcolor=\"" . $tdcolor . "\"><div title=\"model: " . $row['model'] . " (id:" . $device . ")\">" . $row['model'] . "</a></div></td>\n";
foreach($abo_vis as $abs) {
$ab = "$abs";
$if_model_one = if_model_one($ab, $device);
if(isset($if_model_one[1])) {
$name = $if_model_one[0];
$mndpr = $if_model_one[1];
} else {
$pro = $if_model_one[0];
}
$price = $abo[$ab];
if($ts[$ab] == 1) {
$ts_sum = $ts["ts_sum"];
} else {
$ts_sum = 0;
}
$totpr = $price;
$color = color($price, $kost, $ukon, $ts_sum, $ab);
$kategori_sjekk = kategori_pris($ab);
if (is_numeric($kategori_sjekk)) {
$tellKat = count($kategori_sjekk);
} else {
$tellKat = 0;
}
if( $tellKat > 0 ) {
$deviceAboVis = "";
for ($abo_row = 0; $abo_row < $kat_count; $abo_row++) {
$abo_navn = $kategori_abo_sjekk[$abo_row][0];
$grupris = $kategori_abo_sjekk[$abo_row][1];
$mndpris = $kategori_abo_sjekk[$abo_row][2];
$totalpris = $mndpris*12+$color["pris"];
$mnduten = $grunnpris*12;
$devicepris = $totalpris-$mnduten;
if($color["pris"] == "n/a") {
$totalpris = 0;
$devicepris = 0;
} else {
$deviceAboVis .= "Abo: " . $abo_navn . "
";
$deviceAboVis .= "Mndpris: " . $mndpris . " (" . $grupris . ")
";
$deviceAboVis .= "Totalpris: " . $totalpris . "
";
$deviceAboVis .= "devicepris: " . $devicepris . "

";
}
}
echo "<td bgcolor=\"" . $color['color'] . "\"><div title=\"" . $ab . "
model: " . $row['model'] . "

Utpris: " . $color['pris'] . "
Kost: " . $kost . "
TS: " . $color['ts'] . "
DB: " . $color['db'] . "
DG: " . $color['dg'] . "

" . $deviceAboVis . "\">" . $color['pris'] . "</div></td>\n";
} else {
if (!isset($mnduten)) { $mnduten = $prov['grunnpris']*12; $devicepris = $totalpris - $mnduten; }
$abo_short = strtolower(str_replace(' ', '', $ab));
echo "<td bgcolor=\"" . $color['color'] . "\"><!-- t" . $color['tXt'] . " --><div title=\"" . $ab . "
model: " . $row['model'] . "

Utpris: " . $color['pris'] . "
Kost: " . $kost . "
Prov: " . $color['prov'] . "
IMEI: " . $color['imei'] . "
TS: " . $color['ts'] . "
DB: " . $color['db'] . "
DG: " . $color['dg'] . "

Månedspris: " . $prov['mndpris'] . "
Totalpris: " . $totalpris . "\">" . $color['pris'] . "</div></td>\n";
}
}
echo "</tr>\n</tbody>";
}
echo "</table>\n";
function kategori_sjekk($kat) {
global $conn;
global $pro;
$telque = mysqli_query($conn,"SELECT * FROM $pro WHERE abonnement = '$kat'");
$telres = mysqli_fetch_assoc($telque);
return $telres;
}
function if_model_one($ab, $device) {
$pro = pro($ab);
if(isset($navn)) {
$return = array($pro, $navn, $mndpris);
} else {
$return = array($pro);
}
return $return;
}
mysqli_close($conn);
And the MYSQL databases will be something like this:
CREATE TABLE `device_kost` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`prod` varchar(64) NOT NULL,
`model` text NOT NULL,
`kost` decimal(10,2) NOT NULL,
`ukon` int(10) NOT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `device_kost` VALUES
(1,'Samsung','Galaxy',1361.00,0),
(2,'Apple','iPhone',2510.00,0);
CREATE TABLE `device_ts` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`device` int(10) DEFAULT NULL,
`nick` varchar(32) DEFAULT NULL,
`ts_sum` int(10) DEFAULT NULL,
`date_f` date NOT NULL,
`date_t` date NOT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `device_ts` VALUES
(1,1,'gal',200,'2019-01-01','2019-02-28'),
(2,2,'ip',200,'2019-01-01','2019-02-28');
The "device_ts" tables has 3 other similair tables. And I tried to inner join them together, with no luck. First I had to set similair columnd name "as".
SELECT *
FROM
(
select a.`id` , a.`prod` , a.`model` , a.`kost` , a.`ukon` ,
b.`device` as `device_ts` , b.`ts_sum` , b.`date_f` , b.`date_t` , b.`Ub` as `ubt_ts` ,
c.`device` , c.`Ub` as `ubt_ma`
from
device_kost a
inner join device_ts b on a.`id` = b.`device`
inner join device_max c on a.`id` = c.`device`
) as T
order by T.id Desc limit 10
The page/script works great. But it takes around 30-40 seconds because there is too many devices. I think if I could create a better inner join function and then sort out the info after I would remove a lot of unneccessary sql queries.

Error on DialFuction !TypeError Object expected

I have an HTML form where I can add first name, last name and phone number. When I try to insert a value into the phone number field I get this error:
message from webpage
For the first name and last name fields it works everytime.I'm using google chrome. Could be a browser error or it is a code error?
This is the part of code which includes the form:
require('libraries/Interview.class.php');
require('libraries/PhoneBook.class.php');
require('libraries/Beneficiari.class.php');
require('libraries/Marci.class.php');
require('libraries/Modele.class.php');
require_once('connect.php');
require('libraries/Agentii.class.php');
require ("include/callcenter-header.php");
$_SESSION['username'] = 'admin';
$phone_no ="";
if (strlen($phone_no) == 9) {
$contact = PhoneBook::listBYPhoneNo($phone_no, $conn);
$selected_contact = null;
$beneficiari = Beneficiari::listAllNoOwner($db);
$content_agentii = "<option value=''>Alege agentie</option>";
$content_beneficiari = "<option value=''>Alege beneficiar</option>";
$btn_add_new = "";
$selected_bname = "";
$selected_aname = "";
if ($contact) {
if (count($contact) == 0) {
$selected_contact = $contact[0];
} else {
for ($x = 0; $x < count($contact); $x++) {
if ($contact[$x]['default'] == 0) {
$selected_contact = $contact[$x];
}
}
}
$agentii = Agentii::listAll_byBeneficiar($selected_contact['id_beneficiar'], $db);
for ($b = 0; $b < count($beneficiari); $b++) {
if ($selected_contact['id_beneficiar'] == $beneficiari[$b]['id']) {
$selected_bname = $beneficiari[$b]['nume'];
};
$selected = ($selected_contact['id_beneficiar'] == $beneficiari[$b]['id'] ? "selected = 'selected'" : '');
$content_beneficiari .= "<option " . $selected . " value='" . $beneficiari[$b]['id'] . "'>" . $beneficiari[$b]['nume'] . "</option>";
}
for ($a = 0; $a < count($agentii); $a++) {
if ($selected_contact['agency_id'] == $agentii[$a]['id']) {
$selected_aname = $agentii[$a]['nume'];
};
$selected = ($selected_contact['agency_id'] == $agentii[$a]['id'] ? "selected = 'selected'" : '');
$content_agentii .= "<option " . $selected . " value='" . $agentii[$a]['id'] . "'>" . $agentii[$a]['nume'] . "</option>";
}
$btn_upd = "<button class='upd_pb'>Actualizeaza info</button>";
} else {
for ($b = 0; $b < count($beneficiari); $b++) {
$content_beneficiari .= "<option value='" . $beneficiari[$b]['id'] . "'>" . $beneficiari[$b]['nume'] . "</option>";
}
$selected_contact = null;
$agentii = null;
$btn_add_new = "<button class='add_new_pb'>Inregistreaza contact</button>";
}
}
?>
<script>
function OnNewCall(myCallTraceId, callParams)
{
$.ajax({
type: "POST",
url: "dynamic/dynamic.functions.cc_interview.php",
data: {ck_new_call: myCallTraceId, callParams: callParams},
success: function (response) {
$('#contact_info_form').html(response);
$('#flt9_assets').val($("#res_client_company option:selected").html());
$('#flt10_assets').val($("#res_client_agency option:selected").html().split(",")[0]);
filterData(1);
}
});
}
</script>
<br/>
<div style="text-align: left" class="contact_info">
<fieldset>
<legend>Informatii client</legend>
<table id="contact_info_form">
<tr>
<td><label>Call Trace ID :</label><br/><input type="text" id="res_ctid" value="-" /></td>
</tr>
<tr>
<td><label>Nume :</label><br/><input type="text" id="res_client_firstname" value="<?php echo #$selected_contact['first_name']; ?>" /></td>
<td><label>Prenume :</label><br/><input type="text" id="res_client_lastname" value="<?php echo #$selected_contact['last_name']; ?>"/></td>
<td><label>Telefon :</label><br/><input type="text" readonly="readonly" id="res_client_phone" value="<?php echo $phone_no; ?>"/></td>
<td><label>Email :</label><br/><input type="text" id="res_client_email" value="<?php echo #$selected_contact['email']; ?>"/></td>
</tr>
<tr>
<td><label>Beneficiar :</label><br/><select id="res_client_company"><?php echo $content_beneficiari; ?></select></td>
<td><label>Agentia :</label><br/><select id="res_client_agency" ><?php echo $content_agentii; ?></select></td>
<td><label>Adresa :</label><br/><input type="text" id="res_client_address" value="<?php echo #$selected_contact['adresa_agentie']; ?>"/></td>
<td><span id="contact_info_act_btn"><?php echo $btn_add_new; ?><?php echo $btn_upd; ?></span></br><span id="btn_act_resp"></span></td>
</tr>
</table>
</fieldset>
<script>
$('#contact_info_form').on('change', '#res_client_company', function () {
$('#flt9_assets').val($("#res_client_company option:selected").html());
$('#flt10_assets').val('');
filterData(1);
$.ajax({
type: "POST",
url: "dynamic/dynamic.functions.agentii.php",
data: {req_benef: $(this).val()},
beforeSend: function () {
$('#res_client_agency').html('');
},
success: function (response) {
$('#res_client_agency').html(JSON.parse(response));
}
});
});
$('#contact_info_form').on('change', '#res_client_agency', function () {
if ($("#res_client_agency option:selected") !== null) {
$('#flt10_assets').val($("#res_client_agency option:selected").html().split(",")[0]);
filterData(1);
}
});
$('#contact_info_form').on('click', '.add_new_pb', function () {
var request = {
first_name: $('#res_client_firstname').val(),
last_name: $('#res_client_lastname').val(),
phone: $('#res_client_phone').val(),
email: $('#res_client_email').val(),
company: $('#res_client_company').val(),
agency: $('#res_client_agency').val(),
address: $('#res_client_address').val()
};
$.ajax({
type: "POST",
url: "dynamic/dynamic.functions.cc_interview.php",
data: {req_new_pb_entry: JSON.stringify(request)},
beforeSend: function () {
$('#contact_info_act_btn').html('');
},
success: function (response) {
var resp = JSON.parse(response);
if (resp['result']) {
$('#contact_info_act_btn').html(resp['html']);
$('#btn_act_resp').html("Contactul a fost inregistrat cu succes !");
} else {
$('#contact_info_act_btn').html(resp['html']);
$('#btn_act_resp').html("Contactul nu a putut fi inregistrat !");
}
}
});
});
$('#contact_info_form').on('click', '.upd_pb', function () {
var request = {
first_name: $('#res_client_firstname').val(),
last_name: $('#res_client_lastname').val(),
phone: $('#res_client_phone').val(),
email: $('#res_client_email').val(),
company: $('#res_client_company').val(),
agency: $('#res_client_agency').val(),
address: $('#res_client_address').val()
};
$.ajax({
type: "POST",
url: "dynamic/dynamic.functions.cc_interview.php",
data: {req_upd_pb_entry: JSON.stringify(request)},
beforeSend: function () {
$('#contact_info_act_btn').html('');
},
success: function (response) {
var resp = JSON.parse(response);
if (resp['result']) {
$('#contact_info_act_btn').html(resp['html']);
$('#btn_act_resp').html("Contactul a fost actualizat cu succes !");
} else {
$('#contact_info_act_btn').html(resp['html']);
$('#btn_act_resp').html("Contactul nu a putut fi actualizat !");
}
}
});
});
$('#res_client_phone').on('click', '', function () {
try
{
window.external.Dial($('#res_client_phone').val(), 0, -1);
} catch (err)
{
alert("Error on Dial Function !" + err);
}
});
</script>
</div>
And this is the dynamic.functions.cc_interview.php code:
require '../connect.php';
/*
* WHEN user selects an equipment
*/
if (isset($_POST['cci_set_et'])) {
$echipID = str_replace('act_lnk_', '', $_POST['cci_set_et']);
require '../libraries/Interview.class.php';
require '../libraries/Echipamente.class.php';
require '../libraries/Ingineri_service.class.php';
$echipament = Echip::listEchipId($echipID, $db);
$ingineri = Ingineri_service::listAllDistinct($db);
$question = Interview::listFirstQuestionByEchip($echipID, $conn);
#$answers = Interview::listAnswers($question[0]['id'], $conn);
$response = array();
$html = "";
$html .= "<tr class='qRow' id='qRow-" . $_POST['q_count'] . "'><td>" . #$question[0]['text'] . "</td>";
$html .= "<td><input type='hidden' id='qR-" . #$question[0]['id'] . "' value=''><input type='hidden' id='qRid-" . $question[0]['id'] . "' value=''>";
for ($x = 0; $x < count($answers); $x++) {
switch (#$question[0]['multiple_choice']) {
case 0 :
$name = "q" . $question[0]['id'] . "";
break;
case 1 : $name = "q" . $question[0]['id'] . "-" . $answers[$x]['id'];
break;
default : $name = "q" . $question[0]['id'] . "";
}
$html .= "<div>" . $answers[$x]['text'] . " <input class='in_qResp' name='" . $name . "' type='" . $answers[$x]['input_type'] . "' id='R-" . $answers[$x]['id'] . "-" . $answers[$x]['next_question_id'] . "' value='" . $answers[$x]['text'] . "' /> ";
if ($answers[$x]['has_hint'] == 1) {
$html .= " | <a class='ahint'>HINT</a><div class='tooltip'>content</div>";
}
$html .= "</div>";
}
$html .= "<button class='qSubmit' id='qS-" . #$question[0]['id'] . "'>Submit</buton></td></tr>";
$ingineri_html = "";
for ($i = 0; $i < count($ingineri); $i++) {
$selected = ($ingineri[$i]['inginer_service'] == $echipament[0]['inginer_service'] ? "selected='selected'" : "");
$ingineri_html .= "<option " . $selected . " value='" . $ingineri[$i]['inginer_service'] . "'>" . ucwords(str_replace('.', ' ', $ingineri[$i]['inginer_service'])) . "</option>";
}
$response['question']['id'] = $question[0]['id'];
$response['equip_class'] = $echipament[0]['categorie'];
$response['equip_mark'] = $echipament[0]['numeMarca'];
$response['equip_model'] = $echipament[0]['numeModel'];
$response['equip_serial'] = $echipament[0]['serie'];
$response['equip_cod'] = $echipament[0]['cod'];
$response['agency_id'] = $echipament[0]['agentie'];
$response['question']['text'] = $question[0]['text'];
$response['question']['response'] = "";
$response['engineer_html'] = $ingineri_html;
$response['html'] = $html;
echo json_encode($response);
}
/*
* When user submits an answer
*/
if (isset($_POST['cci_set_nq'])) {
$answer_token = explode('-', $_POST['cci_set_nq']);
$answer_id = $answer_token[1];
require '../libraries/Interview.class.php';
$selected_answer = Interview::findAnswer($answer_id, $conn);
$question = Interview::listNextQuestionByAnswer($answer_id, $conn);
$answers = Interview::listAnswers($question[0]['id'], $conn);
$response = array();
$html = "";
$html .= "<tr class='qRow'><td>" . $question[0]['text'] . "</td>";
$html .= "<td><input type='hidden' id='qR-" . $question[0]['id'] . "' value=''><input type='hidden' id='qRid-" . $question[0]['id'] . "' value=''>";
for ($x = 0; $x < count($answers); $x++) {
switch ($question[0]['multiple_choice']) {
case 0 :
$name = "q" . $question[0]['id'] . "";
break;
case 1 : $name = "q" . $question[0]['id'] . "-" . $answers[$x]['id'];
break;
default : $name = "q" . $question[0]['id'] . "";
}
$html .= "<div>" . $answers[$x]['text'] . " <input class='in_qResp' name='" . $name . "' type='" . $answers[$x]['input_type'] . "' id='R-" . $answers[$x]['id'] . "-" . $answers[$x]['next_question_id'] . "' value='" . $answers[$x]['text'] . "' /> ";
if ($answers[$x]['has_hint'] == 1) {
$html .= " | <a class='a_hint'>HINT</a><div class='tooltip'></div>";
}
$html .= "</div>";
}
$html .= "<button class='qSubmit' id='qS-" . $question[0]['id'] . "'>Submit</buton></td></tr>";
$response['question']['id'] = $question[0]['id'];
$response['question']['text'] = $question[0]['text'];
$response['question']['response'] = "";
$response['action'] = $selected_answer['action'];
$response['html'] = $html;
echo json_encode($response);
}
/*
* Function to insert new action into table actuni when agent decides so .
*/
if (isset($_POST['cci_set_aNi'])) {
require '../libraries/Actiuni.class.php';
$request = json_decode($_POST['cci_set_aNi']);
$request->equip_id = str_replace('act_lnk_', '', $request->equip_id);
$request->resolution->interview_string = "Reprezentant client : " . $request->client_first_name . " " . $request->client_last_name . " \n " .
"Telefon client : " . $request->call_id . " \n" .
"Rezultat interviu : \n" . $request->resolution->interview_string . " \n";
// $id_sesizare = Actiuni::insert('call_incident', date('Y-m-d H:i'), $request->deadline, $request->engineer, $request->equip_id, $request->resolution->interview_string, 'nevalidata', date('H:i'), $_SESSION['username'], $request->agency_id, '0', 'RON', $db);
$id_sesizare = 212312;
echo $id_sesizare;
}
/*
* Function to insert new Phone Book entry into table phone_book
*/
if (isset($_POST['req_new_pb_entry'])) {
require '../libraries/PhoneBook.class.php';
$request = json_decode($_POST['req_new_pb_entry']);
$inserted = PhoneBook::insert($request->first_name, $request->last_name, $request->phone, $request->email, $request->agency, $conn);
if ($inserted) {
$response['result'] = TRUE;
$response['html'] = "<button class='upd_pb'>Actualizeaza info</button>";
} else {
$response['result'] = FALSE;
$response['html'] = "<button class='add_new_pb'>Inregistreaza contact</button>";
}
echo json_encode($response);
}
if (isset($_POST['req_upd_pb_entry'])) {
require '../libraries/PhoneBook.class.php';
$request = json_decode($_POST['req_upd_pb_entry']);
$updated = PhoneBook::update($request->first_name, $request->last_name, $request->phone, $request->email, $request->agency, $conn);
$response = array();
if ($updated) {
$response['result'] = TRUE;
$response['html'] = "<button class='upd_pb'>Actualizeaza info</button>";
} else {
$response['result'] = FALSE;
$response['html'] = "<button class='upd_pb'>Actualizeaza info</button>";
}
echo json_encode($response);
}
if (isset($_POST['ck_new_call'])) {
$callTraceId = $_POST['ck_new_call'];
$callParams = $_POST['callParams'];
parse_str($callParams, $callParams_arr);
require('../libraries/PhoneBook.class.php');
require('../libraries/Beneficiari.class.php');
require('../libraries/Agentii.class.php');
$phone_no = intval($callParams_arr['MCC_ANI']);
if (strlen($phone_no) == 9) {
$contact = PhoneBook::listBYPhoneNo($phone_no, $conn);
$selected_contact = null;
$beneficiari = Beneficiari::listAllNoOwner($db);
$content_agentii = "<option value=''>Alege agentie</option>";
$content_beneficiari = "<option value=''>Alege beneficiar</option>";
$btn_add_new = "";
$selected_bname = "";
$selected_aname = "";
if ($contact) {
if (count($contact) == 0) {
$selected_contact = $contact[0];
} else {
for ($x = 0; $x < count($contact); $x++) {
if ($contact[$x]['default'] == 0) {
$selected_contact = $contact[$x];
}
}
}
$agentii = Agentii::listAll_byBeneficiar($selected_contact['id_beneficiar'], $db);
for ($b = 0; $b < count($beneficiari); $b++) {
if ($selected_contact['id_beneficiar'] == $beneficiari[$b]['id']) {
$selected_bname = $beneficiari[$b]['nume'];
};
$selected = ($selected_contact['id_beneficiar'] == $beneficiari[$b]['id'] ? "selected = 'selected'" : '');
$content_beneficiari .= "<option " . $selected . " value='" . $beneficiari[$b]['id'] . "'>" . $beneficiari[$b]['nume'] . "</option>";
}
for ($a = 0; $a < count($agentii); $a++) {
if ($selected_contact['agency_id'] == $agentii[$a]['id']) {
$selected_aname = $agentii[$a]['nume'];
};
$selected = ($selected_contact['agency_id'] == $agentii[$a]['id'] ? "selected = 'selected'" : '');
$content_agentii .= "<option " . $selected . " value='" . $agentii[$a]['id'] . "'>" . $agentii[$a]['nume'] . "</option>";
}
$btn_upd = "<button class='upd_pb'>Actualizeaza info</button>";
} else {
for ($b = 0; $b < count($beneficiari); $b++) {
$content_beneficiari .= "<option value='" . $beneficiari[$b]['id'] . "'>" . $beneficiari[$b]['nume'] . "</option>";
}
$selected_contact = null;
$agentii = null;
$btn_add_new = "<button class='add_new_pb'>Inregistreaza contact</button>";
}
$response = "";
$response .="<tr>";
$response .="<td colspan=\"2\"><label>CALL TRACEID :</label><br/><input type=\"text\" id=\"res_ctid\" value=\"" .$callTraceId. "\" /></td>";
$response .="</tr>";
$response .="<tr>";
$response .="<td><label>Nume :</label><br/><input type=\"text\" id=\"res_client_firstname\" value=\"" . #$selected_contact['first_name'] . "\" /></td>";
$response .="<td><label>Prenume :</label><br/><input type=\"text\" id=\"res_client_lastname\" value=\"" . #$selected_contact['last_name'] . "\"/></td> ";
$response .="<td><label>Telefon :</label><br/><input type=\"text\" id=\"res_client_phone\" value=\"" . $phone_no . "\"/></td>";
$response .="<td><label>Email :</label><br/><input type=\"text\" id=\"res_client_email\" value=\"" . #$selected_contact['email'] . "\"/></td>";
$response .="</tr>";
$response .="<tr>";
$response .="<td><label>Beneficiar :</label><br/><select id=\"res_client_company\">" . $content_beneficiari . "</select></td>";
$response .="<td><label>Agentia :</label><br/><select id=\"res_client_agency\" >" . $content_agentii . "</select></td>";
$response .="<td><label>Adresa :</label><br/><input type=\"text\" id=\"res_client_address\" value=\"" . #$selected_contact['adresa_agentie'] . "\"/></td>";
$response .="<td><span id=\"contact_info_act_btn\">" . $btn_add_new . "" . $btn_upd . "</span></br><span id=\"btn_act_resp\"></span></td>";
$response .="</tr>";
error_log($response);
echo $response;
}
}
?>

php get id to delete record

PHP beginner on line:).
I have two files (viewKands.php-listing records and izbrisi.php-for deleting records from database. I try to delete record from db(upisi). But no luck.
Here is the code...Where is my mistake?
viewKands.php:
$kon = mysqli_connect("localhost", "root", "", "upisi");
$kon->set_charset("utf8");
if (mysqli_connect_error()) {
echo "Greska pri konekcija so baza: " . mysql_error();
}
$sqlView = "SELECT idPrijava,brPrijava,jazik,struka,profil,imeKand,tatIme,"
. "prezKand from tblprijava ";
$result = mysqli_query($kon, $sqlView);
$rBr = 1;
while ($rowV = $result->fetch_assoc()) {
$id = $rowV["idPrijava"];
echo "<tr><td>" . $rBr . "</td><td>" . $rowV["brPrijava"] . "</td><td>" . $rowV["jazik"] . "</td><td>" . $rowV["struka"] .
"</td><td>" . $rowV["profil"] . "</td><td>" . $rowV["imeKand"] . " " . $rowV["tatIme"] . " " . $rowV["prezKand"] .
"</td><td><a href='uredi.php'>Уреди</a></td>" . " <td><a href='izbrisi.php?id=$id'>X</a></td>" . "</td></tr>";
$rBr++;
}
And izbrisi.php (for deleting records)
$delkon = mysqli_connect("localhost", "root","","upisi");
$delkon->set_charset("utf8");
if (isset($_GET["idPrijava"]) != "") {
$delete = $_GET["idPrijava"];
$dqry = "DELETE FROM tblprijava WHERE idPrijava='$delete'";
$delete = mysqli_query($delkon, $dqry);
if ($delkon->query($dqry) === TRUE) {
header("Location:viewKands.php");
} else {
echo mysqli_error($delete);
}
} else {
echo "ID error";
}
$delkon->close();
Change code to izbrisi.php
$delkon = mysqli_connect("localhost", "root","","upisi");
$delkon->set_charset("utf8");
if (isset($_GET["id"]) != "") {
$delete = $_GET["id"];
$dqry = "DELETE FROM tblprijava WHERE idPrijava='$delete'";
$delete = mysqli_query($delkon, $dqry);
if ($delkon->query($dqry) === TRUE) {
header("Location:viewKands.php");
} else {
echo mysqli_error($delete);
}
} else {
echo "ID error";
}
$delkon->close();

Displaying PHP results?

I need a little help here with some php.
just a little explanation:
(im trying to display 5 results using this code
$n_id = mysql_real_escape_string ($_GET['id']);
$path = '';
if(isset($n_id) && $n_id != "") {
$sql = 'SELECT * FROM test2 WHERE id="' . $n_id . '"';
$news = mysql_query($sql);
if($result = mysql_fetch_array($news)) {
$title = mysql_result($news,0,"title");
$date = mysql_result($news,0,"date");
echo '<b>' . $title . ' | ' . $date . '</b>
<br/>
<img src="images.php?id='. $n_id .'>';
} else {
header("Location: vendi.php");
}
echo '<br />Back to Archive';
}
It does display but i want that 1st result to be (image+title of the news and other results to be just title).
Hope i wrote it clearly what i needed help with.
Thank you
Your SQL statement is only fetching a single row. This isn't a complete solution, but should get you closer:
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$n_id = (int)$_GET['id'];
$path = '';
$count = 0;
$sql = 'SELECT * FROM test2 WHERE id BETWEEN ' . $n_id ' AND ' . ($n_id + 5);
$news = mysql_query($sql);
while ($result = mysql_fetch_array($news)) {
$title = $result['title'];
$date = $result['date'];
echo '<b>' . $title . ' | ' . $date . '</b>';
if ($count < 1) {
echo '<br/><img src="images.php?id='. $n_id .'>';
$count++;
}
}
if ($count == 0) { header("Location: vendi.php"); }
echo '<br />Back to Archive';
}
This should do it.
$n_id = mysql_real_escape_string ($_GET['id']);
$path = '';
if(isset($n_id) && $n_id != "") {
$sql = 'SELECT * FROM test2 WHERE id="' . $n_id . '"';
$news = mysql_query($sql);
$first = TRUE;
if($result = mysql_fetch_array($news)) {
$title = mysql_result($news,0,"title");
$date = mysql_result($news,0,"date");
if($first == TRUE) {
echo '<b>' . $title . ' | ' . $date . '</b>';
$first = FALSE;
}
else {
echo '<b>' . $title . ' | ' . $date . '</b>
<br/>
<img src="images.php?id='. $n_id .'>';
}
}
else {
header("Location: vendi.php");
}
echo '<br />Back to Archive';
}
}
While looping through your results, you can check if you are at the first result:
$counter = 0;
while ($row = mysql_fetch_array($news)) {
$title = mysql_result($news,0,"title");
$date = mysql_result($news,0,"date");
echo '<b>' . $title . ' | ' . $date . '</b>';
if ( $counter == 0 ) {
echo '<br /><img src="images.php?id='. $n_id .'>';
}
}

drropdownlist values are not shown from the database on fom load

<?php
require_once("../../db_connect/db_connect.php");
$decoded = json_decode($_GET['json']);
$ias = $decoded->{'ias'};
$ian = $decoded->{'ian'};
$select = "select iacode,ianame from isdsmot_ia_creation";
$res = mysql_query($select);
while ($row = mysql_fetch_array($res)) {
$ias = $row['iacode'];
$ian = $row['ianame'];
$ia=$ias."|".$ian;
echo "<OPTION value = \"" . $row[0] . "|" . $row[1] . "\">" . $ia . "</OPTION>";
}
$result=$ia;
if ($result) {
echo "Successful" . mysql_error();
} else {
echo "Unsuccess" . mysql_error();
}
?>
Will this help you : add around your
<?php
require_once("../../db_connect/db_connect.php");
$decoded = json_decode($_GET['json']);
$ias = $decoded->{'ias'};
$ian = $decoded->{'ian'};
$select = "select iacode,ianame from isdsmot_ia_creation";
$res = mysql_query($select);
echo '<select name="myDropDown">';
while ($row = mysql_fetch_array($res)) {
$ias = $row['iacode'];
$ian = $row['ianame'];
$ia=$ias."|".$ian;
echo "<OPTION value = \"" . $row[0] . "|" . $row[1] . "\">" . $ia . "</OPTION>";
}
echo '</select>';
$result=$ia;
if ($result) {
echo "Successful" . mysql_error();
} else {
echo "Unsuccess" . mysql_error();
}
?>

Categories