PHP code Still not updating SQL - php

Relating to a previous question i had
SQL not Updating from PHP form
I have changed and played with the code but am getting the following errors.
Query was emptyArray ( [imei] => 1 [serial] => 1 [status] => 1 [msisdn_no] => 0827910119
[card_no] => 89604900000001868482 [client_name] => 1 [inst_date] => 2013-09-10 [tech] => 1
[inst_cert] => 1 [isp] => Vodacom [account] => 1 [account_price] => 1 [deposit] => 1
[cont_start] => 1 [cont_end] => 1 [rica] => 1 [date_rica] => 1 [prod] => 1 [active] => 1
[suspended] => 1 [loaded_by] => 1 [send] => Submit ) : mysql err no : 1065 Your Number has
been registered and Location has been Captured. Please click here for your Map and
Location
This is my update PHP code
//Drawn from Form Information used to Update Database
$imei = $_POST['imei'];
$serial = $_POST['serial'];
$status = $_POST['status'];
$msisdn_no = $_POST['msisdn_no'];
$card_no = $_POST['card_no'];
$client_name = $_POST['client_name'];
$inst_date = $_POST['inst_date'];
$tech = $_POST['tech'];
$inst_cert = $_POST['inst_cert'];
$isp = $_POST['isp'];
$account = $_POST['account'];
$account_price = $_POST['account_price'];
$deposit = $_POST['deposit'];
$cont_start = $_POST['cont_start'];
$cont_end = $_POST['cont_end'];
$rica = $_POST['rica'];
$date_rica = $_POST['date_rica'];
$prod = $_POST['prod'];
$suspended = $_POST['suspended'];
$loaded_by = $_POST['loaded_by'];
$id =$_POST['id'] ;
//update database
update_lbs($msisdn, $reqby1, $reqdate, $reqtime, $client, $clientcase, $saps, $cas,
$reason, $reqby, $long, $lat, $msisdn, $dist, $response);
//update database
function update_lbs($imei, $serial, $status, $msisdn_no, $card_no, $client_name,
$inst_date, $tech, $inst_cert, $isp, $account, $account_price, $deposit, $cont_start,
$cont_end, $rica, $date_rica, $prod, $suspended, $loaded_by)
{ global $host;
global $username;
global $password;
global $db_name;
date_default_timezone_set('Africa/Johannesburg');
$today = date("Y-m-d H:i:s");
$date = date("Y-m-d") ;
$time = date("H:i:s");
$insertSuccessful = false;
if ($con = mysql_connect($host, $username, $password)) {
if (mysql_select_db($db_name)) {
$query = "UPDATE tracking_sim SET
imei = '$imei',
serial = '$serial',
status = '$status',
msisdn_no = '$msisdn_no',
card_no = '$card_no',
client_name = '$client_name',
tech = '$tech',
inst_cert = '$inst_cert',
isp = '$isp',
account = '$account',
account_price = '$account_price',
deposit = '$deposit',
cont_start = '$cont_start',
cont_end = '$cont_end',
rica = '$rica',
date_rica = '$date_rica',
prod = '$prod',
date_rica = '$date_rica',
suspended = '$suspended',
loaded_by = '$loaded_by'
WHERE id = '$id';";
if (mysql_query($sql, $con)) {
$insertSuccessful = true;
} else {
echo mysql_error ();
echo $sql;
print_r($_POST);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
echo "mysql err no : " . mysql_errno($con);
}
return $insertSuccessful;
}
}
}
?>
My form has the following
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM tracking_sim WHERE id='$id'");
$rows = mysql_fetch_array($result);
?>
<form id="form1" method="post" action="../control_tracking/tracking_sim_updated.php">
I have tried the form action with both GET and POST same error also I have changed $_POST to $_REQUEST and tried it that way as well with no avail

you are use different sql variable,
$query and $sql,
"if (mysql_select_db($db_name)) {
**$query =** "UPDATE tracking_sim SET "
if (mysql_query(**$sql**, $con)) {

Try removing the semi-colon at the end of your update statement. The one after WHERE id='$id'.

Related

Warning: mysqli::reap_async_query(): Connection not opened, clear or has been closed

I'm trying to do some testing with async queries. I'm getting this result:
Array ( [0] => 2017-11-28 11:34:01 [1] => 50 )
Warning: mysqli::reap_async_query(): Connection not opened, clear or has been closed in /var/www/testasync.php on line 24.
I haven't been able to find anything about this warning anywhere. I don't close my connection until the very end of my code. What does it mean?
Here's my code:
<?php
$connect = mysqli_connect("localhost", "user", "password", "test");
if (!$connect) {
die('Could not connect: ' . mysqli_error($connect));
}
// Queries
$sql0 = "SELECT * FROM flow01 where datetime = (select min(datetime) from flow01)";
mysqli_query($connect, $sql0, MYSQLI_ASYNC);
$sql1 = "SELECT * FROM flow01 where datetime = (select max(datetime) from flow01)";
mysqli_query($connect, $sql1, MYSQLI_ASYNC);
$sql2 = "SELECT * FROM hum01 where datetime = (select min(datetime) from hum01)";
mysqli_query($connect, $sql2, MYSQLI_ASYNC);
$sql3 = "SELECT * FROM hum01 where datetime = (select max(datetime) from hum01)";
mysqli_query($connect, $sql3, MYSQLI_ASYNC);
// Results
$i = 0;
foreach ($connect as $result) {
if ($result = $connect->reap_async_query()) {
print_r($result->fetch_row());
mysqli_free_result($result);
$i++;
}
}
mysqli_close($connect);
?>
Just in case someone else comes looking for an answer I'm posting the code I made using mysqli_poll.
<?php
// Queries
$sql0 = "SELECT * FROM flow01 where datetime = (select min(datetime) from flow01)";
$sql1 = "SELECT * FROM flow01 where datetime = (select max(datetime) from flow01)";
$sql2 = "SELECT * FROM hum01 where datetime = (select min(datetime) from hum01)";
$sql3 = "SELECT * FROM hum01 where datetime = (select max(datetime) from hum01)";
$all_links = array();
for($i=0; $i<=3; $i++) {
$connect = mysqli_connect("localhost", "user", "password", "test");
mysqli_query($connect, ${'sql' . $i}, MYSQLI_ASYNC);
$all_links[] = $connect;
}
$processed = 0;
do {
$links = $errors = $reject = array();
foreach ($all_links as $connect) {
$links[] = $errors[] = $reject[] = $connect;
}
if (!mysqli_poll($links, $errors, $reject, 2)) {
continue;
}
foreach ($links as $connect) {
if ($result = $connect->reap_async_query()) {
$new = $result->fetch_row();
print_r($new);
mysqli_free_result($result);
} else die(sprintf("MySQLi Error: %s", mysqli_error($connect)));
$processed++;
}
} while ($processed < count($all_links));
mysqli_close($connect);
?>
This gives a result of:
Array ( [0] => 2017-11-28 11:34:29 [1] => 13 ) Array ( [0] => 2017-12-20 12:11:12 [1] => 12 ) Array ( [0] => 2018-01-12 06:37:10 [1] => 0 ) Array ( [0] => 2017-11-28 11:34:01 [1] => 50 )
Edit: It seems to pull in results in any order they come which means they are often out of order. I tried adding another column to my table with a number to indicate what table it is then I can sort the results before I display them. If anyone knows of a better way to do this let me know.

Joomfish migration script returns error

Here is a script that upgrades joomfish (joomla translation component) from joomla 1.5 to 2.5:
$db = new PDO("mysql:host=localhost;dbname=db;charset=UTF8", "root", "pass");
$stmt = $db->prepare("select distinct(jfc.reference_id),c.catid,jfc.language_id,c.modified,c.modified_by,c.version,c.modified_by ,c.ordering,c.created_by,c.metadesc ,c.created_by_alias from jos_jf_content jfc ,jos_content c where jfc.reference_id = c.id and jfc.reference_table = 'content' ");
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($results as $row) {
$count_row = $db->prepare("select * from jos_jf_content where reference_id = ? and language_id = ?");
$count_row->bindValue(1, $row['reference_id']);
$count_row->bindValue(2, $row['language_id']);
$lang_code = $db->prepare("select lang_code from j25_languages where lang_id = ?");
$lang_code->bindValue(1, $row['language_id']);
$lang_code->execute();
$l_code = $lang_code->fetch(PDO::FETCH_OBJ);
$language_code = $l_code->lang_code;
$count_row->execute();
$title ="";
$fulltext ="";
$introtext ="";
$alias ="";
$published ="";
while($col = $count_row->fetch(PDO :: FETCH_ASSOC))
{
if($col['reference_field'] == "title")
{
$title = $col['value'];
}
if($col['reference_field'] == "fulltext")
{
$fulltext = $col['value'];
}
if($col['reference_field'] == "introtext")
{
$introtext = $col['value'];
}
if($col['reference_field'] == "alias")
{
$alias = $col['value'];
}
$published = $col['published'];
}
$exe = $db->prepare("insert into j25_content (`title`,`alias`,`introtext`,`fulltext`,`published`,`catid`,`created`,`created_by`,`created_by_alias`,`modified`,`modified_by`,`version`,`ordering`,`metadesc`,`language`) values(:title,:alias,:introtext,:fulltext,:published,:categoryid,:created,:created_by,:created_by_alias,:modified,:modified_by,:version,:ordering,:metadesc,:language_code)");
$exe->execute(array(':title' => $title,':alias' => $alias,':introtext' => addslashes($introtext),':fulltext' => addslashes($fulltext),':published' => ".$published.",':categoryid' => $row['catid'],':created' => date("Y-m-d H:i:s"),':created_by' => $row['created_by'],':created_by_alias' => "".$row['created_by_alias']."",':modified' => date("Y-m-d H:i:s"),':modified_by' =>$row['modified_by'],':version' => $row['version'],':ordering' => $row['ordering'],':metadesc' => $row['metadesc'],':language_code' => $language_code));
$i = $db->lastInsertId('id');
$asst = $db->prepare("select asset_id from j25_categories where id = ? ");
$asst->bindValue(1, $row['catid']);
$asst->execute();
$asst_id = $asst->fetch(PDO::FETCH_OBJ);
$cassetid = $asst_id->asset_id;
$sel = $db->prepare("select lft,rgt FROM `j25_assets` where id = (SELECT max(id) FROM `j25_assets`)");
$sel->execute();
$select = $sel->fetch(PDO::FETCH_OBJ);
$left = $select->lft;
$right = $select->rgt;
$left=$left+1;
$right = $right+1;
$stmt = $db->prepare("insert into j25_assets (`parent_id`,`lft`,`rgt`,`level`,`name`,`title`) values(:cassetid,:left,:right,:level,:name,:title)");
$stmt->execute(array(':cassetid' => $cassetid,':left' => $left,':right' => $right,':level' => 4,':name' => "com_content.article.".$i,':title' => $title));
$insertedId = $db->lastInsertId('id');
$update = $db->prepare("update j25_content set asset_id = ? where id = ?");
$update->bindValue(1, $insertedId);
$update->bindValue(2, $i);
$update->execute();
$stmt = $db->prepare("insert into j25_jf_translationmap (language,reference_id,translation_id,reference_table) values (:language_code,:reference_id,:translation_id,:content)");
$stmt->execute(array(':language_code' => $language_code,':reference_id' => $row['reference_id'],':translation_id' => $i,':content' => 'content'));
}
Line of code:
$language_code = $l_code->lang_code;
Returns:
Trying to get property of non-object
I'm not an author of the script and not good in PHP, but I've tried to print_r($l_code->lang_code); and I got expected result en-GB from [lang_code] => en-GB. What I need to change in this code? Thanks.
The line $language_code = $l_code->lang_code > 0; sets $language_code to boolean value. Try var_dump($l_code); and var_dump($language_code); to debug your results. You should also check if $l_code actually is an object, or perhaps null was returned. Hope that helps.

Cannot Select table where Timestamp = GET

I am so confused here, how can i select table where schedule_date_time = $_GET['date_time'];
<?php
require 'core/init.php';
$schedule_id = $_GET['id'];
$schedule_date_time = $_GET['date_time'];
$session_id = $_GET['session'];
$user_id = $_GET['user'];
$user_email = $_GET['email'];
$user_name = $_GET['username'];
$registry_id = $_GET['registry'];
$check1 = DB::getInstance()->query("SELECT * FROM chat_schedule WHERE schedule_date_time = $schedule_date_time");
if ($check1->count()) {
$insert = DB::getInstance()->insert('chat_booked', array(
'schedule_id' => $schedule_id,
'schedule_date_time' => $schedule_date_time,
'session_id' => $session_id,
'user_id' => $user_id,
'user_email' => $user_email,
'user_name' => $user_name,
'registry_id' => $registry_id
));
if ($insert = true) {
echo "Insert was Successful";
}
} else {
echo "No Match Found, INSERT FAILED!";
}
Do i need to parse the date or something. I can not figure this out :(
change the $schedule_date_time to '$schedule_date_time' like:
"SELECT * FROM chat_schedule WHERE schedule_date_time = '$schedule_date_time' "

variable not found in php

i passed an array to another page using session
i also passed an index of array
now i want to access that particular index but i am not able to do so can anybody help
here is he first page where i have created the array and stored it in session
<?php
//connection made
$con = mysqli_connect("localhost", "root", "", "QSTNS");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//-----------------two variables entered in datavbase------------
$user = mysqli_real_escape_string($con, $_POST['user']);
$user1 = mysqli_real_escape_string($con, $_POST['user1']);
$sql = "INSERT INTO student (name,rln,scr)VALUES ('$user1','$user','0')";
if (!mysqli_query($con, $sql)) {
die('Error: ' . mysqli_error($con));
}
$res = mysqli_query($con, 'SELECT COUNT(*) FROM qstns');
$row = mysqli_fetch_array($res);
echo $row[0];
$size = $row[0];
//creating an array of size equal to number of questions in DATABASE....
$q_indx = array(); //question indexes without permutation
$attmpt = array(); //check if a question attempted or not
$score = array(); //score per question initially empty
for ($i = 0; $i < $size; $i++) {
array_push($q_indx, $i);
array_push($attmpt, -1);
array_push($score, 0);
}
$cindx = 0;
session_start();
$_SESSION['q_indx'] = $q_indx; //HERE THAT SESSION IS CREATED
$_SESSION['attmpt'] = $attmpt;
$_SESSION['score'] = $score;
$_SESSION['cindx'] = $cindx;
header('Location: quiz_start.php');
mysqli_close($con);
?>
here is the quiz_start.php
<?php
session_start();
$con=mysqli_connect("localhost","root","","QSTNS");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$dslpy=$_SESSION['q_indx'][$_SESSION['cindx']] ;
echo $dsply ;
//$qstn = mysqli_query($con,"SELECT * FROM qstns where qid = '". $dsply[0]
."'");
//echo $qstn['qname'] . '\n';
mysqli_close($con);
?>
it is giving error dsply variable not found
can any body help ?
From this script, we can gather that $_SESSION['q_indx'] holds an array of numbers, as below;
Array
(
[0] => 0
[1] => 1
[2] => 2
[3] => 3
[4] => 4
)
From your code, $cindx = 0;, so we are looking at index 0. Therefore,
echo $_SESSION['q_indx'][0]; //One way of doing it
echo $_SESSION['q_indx'][$cindx]; //Another way of doing it
EDIT
Cannot use object of type mysqli_result as array in C:\wamp\www\quiiz_portal\quiz_start.php on line 12 can u tell why it there
Change your MySQL query to become
$qstn = mysqli_query($con, "SELECT * FROM qstns where qid = '". $dsply[0] ."'");
EDIT
You are missing session_start(); from your first file.

Insert wont insert itemID to database table

Ok , so when someone buys item from my site, it is ment to insert that item ID into the database , but it doesnt for some reason.
$mysql_host = 'localhost'; //Leave at localhost
$mysql_user = ''; //DB User
$mysql_pass = ''; //DB Pass
$mysql_db = ''; //DB Name
$file = 'paypal.log'; //Paypal Log Name will be placed in the same location as your ipn.php file
$payer_email = $_REQUEST['payer_email'];
$ip = $_SERVER['REMOTE_ADDR'];
$time = date("F j, Y, g:i a");
$paylist = array("5.00" => 15017, "0.01" => 18830, "10.00" => 13840, "10.01" => 13842, "9.99" => 13729, "15.00" => 19111, "60.00" => 1046, "40.00" => 1050, "14.99" => 6199);
// connect db
$db = mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die(mysql_error());
$custom = stripslashes(ucwords(strtolower(trim($_REQUEST['custom']))));
$receiver_email = $_REQUEST['receiver_email'];
$payment_status = $_REQUEST['payment_status'];
$mc_gross = $_REQUEST['mc_gross'];
mysql_select_db($mysql_db, $db);
if ($_REQUEST['debug']){
print $payment_status . '\n';
print (isset($paylist[$mc_gross])) ? 1 : 0 . '\n';
print $receiver_email . '\n';
print $custom . '\n';
}
if ($payment_status == "Completed" && $receiver_email == "justincopp77#yahoo.com" && isset($paylist[$mc_gross])) {
$query = "INSERT `status` SET `item` = '$itemid' ,`username` = '$custom'";
$result2 = mysql_query($query) or die(mysql_error());
$prem = mysql_fetch_array($result);
$somecode = "'$time' '$custom' '$payer_email' '$mc_gross' '$ip'\r\n";
// figure out how much to give
$give = $paylist[$mc_gross];
$itemid = $prem['item'] + $give;
// $points = mysql_query($prem)
$qry2 = "SELECT `item` FROM `status` WHERE `username` = '$custom'";
// Log Paypal Transaction
$hak = fopen($file, "a");
fwrite($hak, $somecode);
fclose($hak);
$result2 = mysql_query($qry2) or die(mysql_error());
}
?>
you can see its not putting the item ID in
Does anyone know why it wont inset item id into the database?
What will i need to change to fix it
Thanks in advance
your sql syntax is wrong
$query = "INSERT INTO `status` (item, username) VALUES ('$itemid' ,'$custom')";

Categories