first of all, apologies for my bad english.
I try to set two vars as booleans, like this:
if ((strlen($imgCropperIPS) > 100) || (file_exists('files/'.$idIPS .'_ips.jpg'))) {
$logoIPS_temp = true;
} else {
$logoIPS_temp = false;
}
if ((strlen($imgCropperEmp) > 100) || (file_exists('files/'.$idIPS .'_emp.jpg'))) {
$logoEmp_temp = true;
} else {
$logoEmp_temp = false;
}
$data['logoBool'] = $logoEmp_temp . "-" . $logoIPS_temp;
$query = "UPDATE ips SET ipsName='$nameIPS', ipsNIT='$nitIPS', externalMant=$externalMant, empName='$nameEmp', empNIT='$nitEmp', ipsLogo= $logoIPS_temp, empLogo = $logoEmp_temp WHERE idIPS = '$idIPS' AND userAdmin='$userAdmin'";
$data['query'] = $query;
The server response this:
data['logoBool'] response: "-1"
data['query'] response:
"UPDATE ips SET ipsName='hospital', ipsNIT='848484', externalMant=true, empName='buss', empNIT='12312312', ipsLogo= 1, empLogo = WHERE idIPS = '1' AND userAdmin='1'"
The problem is with two vars "logoEmp_temp and logoIPS_temp"
Help.
Define vars in the start of document...
I solved it like this:
$temp_ips = "false";
$temp_emp = "false";
if ((strlen($imgCropperIPS) > 100) || (file_exists('files/'.$idIPS .'_ips.jpg'))) {
$temp_ips = "true";
} else {
$temp_ips= "false";
}
if ((strlen($imgCropperEmp) > 100) || (file_exists('files/'.$idIPS .'_emp.jpg'))) {
$temp_emp = "true";
} else {
$temp_emp = "false";
}
Related
I am trying to replace some pieces of codes in different theme files using the below function, however, I am stuck with the second part of the function where I want to replace some PHP code which contains a single quote.
When I run the function, the only part changes is the first part.
function update_GTour_theme_files()
{
$new_update = file_get_contents("/home/tourieuw/public_html/wp-content/themes/grandtour/header.php");
$new_update = preg_replace('/\$page_menu_transparent = 1/', '\$page_menu_transparent = 0', $new_update);
$new_update = preg_replace('/\$grandtour_page_menu_transparent = 1/', '\$grandtour_page_menu_transparent = 0', $new_update);
if (file_put_contents("/home/tourieuw/public_html/wp-content/themes/grandtour/header.php", $new_update)) {
$errpass = TRUE;
} else {
$errmsg = "Header.php was not updated";
$errpass = FALSE;
}
$new_update_2 = file_get_contents("/home/tourieuw/public_html/wp-content/themes/grandtour/templates/template-tour-header.php");
$new_update_2 = preg_replace('/(esc_html(grandtour_format_tour_price($tour_price)))/', '\'From \'.esc_html(grandtour_format_tour_price($tour_price)', $new_update_2);
if (file_put_contents("/home/tourieuw/public_html/wp-content/themes/grandtour/templates/template-tour-header.php", $new_update_2)) {
$errpass = TRUE;
} else {
$errmsg = "template-tour-header.php was not updated";
$errpass = FALSE;
}
if ($errpass = TRUE) {
echo '</br><span style="color:green;font-weight:bold;">Changes were applied successfully.</span>';
} else {
echo '</br><span style="color:red;font-weight:bold;">' . $errmsg . '</span>';
}
}
I am expecting when running this function that both variables in two files will be replaced with this code
I am getting this Trying to get property of non-object in at if ($fetch_size_id->num_rows > 0) and at else if ($fetch_size_id->num_rows == 0).
Can't figure out what is causing it.
The if conditions don't work as well...
When I var_dump($fetch_size_id) I get bool(false).
$fetch_size_id = $conn->query("
SELECT
`sizes`.`size_id`,
`sizes`.`width`,
`sizes`.`ratio`,
`sizes`.`construction`,
`sizes`.`diameter`
FROM `sizes`
WHERE
`sizes`.`width` = '".$conn->real_escape_string($row['5'])."'
AND `sizes`.`ratio` = '".$conn->real_escape_string($row['6'])."'
AND `sizes`.`construction` = '".$conn->real_escape_string($construction)."'
AND `sizes`.`diameter` = '".$conn->real_escape_string($row['7'])."
");
if ($fetch_size_id->num_rows > 0) {
$fetch_size_id = $fetch_size_id->fetch_object();
$temp_size_id = $fetch_size_id->size_id;
} else if ($fetch_size_id->num_rows == 0) {
//create new
} else {
//error
}
Am I overlooking something?
You are not checking variable $fetch_size_id
if (isset ($fetch_size_id){
if ($fetch_size_id->num_rows) {
$fetch_size_id = $fetch_size_id->fetch_object();
$temp_size_id = $fetch_size_id->size_id;
} else{
//create new
}
} else {
//error
}
I have a script like this:
if(isset($_SESSION["LoginValidation"]) && $_SESSION["LoginValidation"] == 1){
$something = $db->prepare('SELECT cookie FROM users WHERE id = ?');
$something->execute(array($_SESSION["Id"]));
$num_row = $something->fetch();
$_SESSION["cookie"] = $num_row['cookie'];
if ( $_SESSION["cookie"] != $_COOKIE['login']) ){
// jump to following else statement (outer else statement)
}
} else {
/* here - this block should be execute when
- That inner if-statement is true
OR
- That outer if-statement is false
*/
}
As you see, I need to execute if-statement and if inner if-statement is true then execute else-statement. How can I do that?
I think that is a algorithm problem and not php. Anyway, there are several ways to do. For example:
$innerCondition = false;
$outerCondition = false;
if(isset($_SESSION["LoginValidation"]) && $_SESSION["LoginValidation"] == 1) {
$outerCondition = true;
// ...
if ($_SESSION["cookie"] != $_COOKIE['login']) {
$innerCondition = true;
// ...
}
}
if ($innerCondition || !$outerCondition) {
// ...
}
Try something like this:
$doElse = true;
if(isset($_SESSION["LoginValidation"]) && $_SESSION["LoginValidation"] == 1){
$doElse = false;
$something = $db->prepare('SELECT cookie FROM users WHERE id = ?');
$something->execute(array($_SESSION["Id"]));
$num_row = $something->fetch();
$_SESSION["cookie"] = $num_row['cookie'];
if ( $_SESSION["cookie"] != $_COOKIE['login']) ){
$doElse = true;
}
else {
//rest of the logic
}
}
if ($doElse) {
// here - this block should be execute when inner if-statement is true
}
i watching tutorial about developing guestbook with php
this is the code that get the message with the id
public function GetMessage($id)
{
//Database
$id = (int)$id;
$gb_host = 'localhost' ;
$gb_dbname = 'guestbook' ;
$gb_username = 'root';
$gb_password = '' ;
$connection = mysqli_connect($gb_host , $gb_username , $gb_password,$gb_dbname);
$querycheck = mysqli_query($connection,"SELECT * FROM `messages` WHERE `id` = $id");
if($querycheck)
{
$message = mysqli_fetch_assoc($querycheck);
return $message;
}
else
{
mysqli_close($connection);
return NULL;
}
mysqli_close($connection);
}
why in else statment we return NULL instead of False
what's the difference between Null and False ?
The type.
False is boolean and null is a value.
So :
$test = false;
if($test === false) {
//correct
}
$test = null;
if ($test === false) {
//incorrect
} else if ($test === null) {
//correct
}
$test = false;
if(!$test) {
//correct
}
$test = null;
if(!$test) {
//correct
}
More precision in the documentation
Imho in this case and null and false are incorrect, because method should return one type of data!
In our method it should be array not special type (null) or boolean,
and it will be easy to use this method elsewhere, because everytime we know that we works with array, and we don't have write something like this:
$messages = $dao->GetMessage(27);
if (is_array($messages)) {
// ...
}
if (is_null($messages)) {
$messages = []; // because wihout it foreach will down
}
foreach ($messages as $message) {
// ...
}
And as for me it's pretty straightforward:
if we have data at db we'll receive not empty array,
if we don't have data at db - we'll receive empty array.
It's obviously!
I have a code like this
First looping count how many post the array:
for($i = 0; $i < $jumlah_qty ;$i++) {
if(!empty($qty[$i]) && !empty($id_cat[$i])) {
Insert booking:
$insert_booking_hd = $user_class->select($az);
$id_cates = $id_cat[$i];
for($b = 0;$b<$qty[$i];$b++) {
First validation if $_POST[$id_cates) is set run this code:
if(isset($_POST[$id_cates."".$b])){
$id_seat = $_POST[$id_cates."".$b];
Find the seat number in $select_seat and find if seat number is exist in $seat_number:
$select_seat = $user_class->select($query);
$seat_number = $user_class->select($querys);
$row_seat = $user_class->numrows($select_seat);
$row_seat2 = $user_class->numrows($seat_number);
if($row_seat>0) {
$update_seat = $user_class->update($update_false);
$bol[$b] = FALSE;
} else {
if( $row_seat2>0 ) {
$insert_booking_dt = $user_class->insert($insert);
$update_seat = $user_class->update($update_true);
$bol[$b] = TRUE;
} else {
$bol[$b] = FALSE;
}
}
} else {
$insert_booking_dt = $user_class->insert($insert_without_seat);
$bol[$b] = TRUE;
}
if($bol[$b]) {
echo "FALSE";
header("location:../../../print.php?id=$id_booking");
}
else {
echo "WRONG";
header("location:../../../event.php?msg=Same seat number");
}
}
}
}
Anything wrong with my php validation?
Because if I input array of $id_seat it will always redirect to print.php although validation is FALSE
for example if I input 3 array and then I echo FALSE WRONG FALSE FALSE
still redirect to print.php not to event.php
How can I read if one of array is get WRONG and then redirect to event.php?
How can I read if one of array is get WRONG and then redirect to event.php?
You may break out of for-loops.
Instead of:
else {
echo "WRONG";
header("location:../../../event.php?msg=Same seat number");
}
You could try:
else {
echo "WRONG";
header("location:../../../event.php?msg=Same seat number");
break 2;
}