Switch Statment Give Always The default [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 8 years ago.
Improve this question
I have a problem in my script in wampserver. It runs well. But in my hosting it doesn't display
the page which is named classed.php?cat=[category_Name_Example]
<?php header("Content-type: text/html; charset=utf-8");
?>
<?php include_once("analyticstracking.php") ?>
<?php
include 'includis/html_codes.php';
include 'includis/config.php';
$catID= mysql_real_escape_string($_GET['cat']);
switch ($catID)
{
case 'javascript' :
$catName = "javascript";
$PageTitle = "Javascript ";
$img = "img/javascript.png";
break;
case 'htmlandcss' :
$catName = "htmlandcss";
$PageTitle = "html ";
$img = "img/html2.png";
break;
default:header('location: /404');
}
if (!isset($catID)){
header ('Location 404.php');
}
if (empty($catID)){header ('Location 404.php');}
include 'includis/db.php';
?>
please help thanx :)

Most probable reason is that you do not have an open database connection while calling to this function. In this case mysql_real_escape_string just returns false.

Related

Getting variable value from another page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I was trying to get variable value from a page and echo it out in another page
for example I have 2 pages pg1.php and pg2.php:
On pg2.php I have:
<?php
$vr = "Hello";
?>
Now I want to echo this out on pg1.php, I have tried this:
<?php
require "pg2.php";
echo $vr;
?>
It works, but the problem is whatever else I have on pg2.php will be displayed on pg1.php.
It would be best to restructure your code so that variables are defined in one file that then includes another file with output etc.
<?php
// vars.php
$vr = "Hello";
?>
<?php
// pg1.php
require "vars.php";
echo $vr;
?>
<?php
// pg2.php
require "vars.php";
// other stuff
// ...
// ...
?>
But for this issue in general, buffer output and then delete the buffer:
<?php
// pg1.php
ob_start();
require "pg2.php";
ob_end_clean();
echo $vr;
?>

Call variable without echo or print [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to call variable with in variable and below attempts are working fine
Attempt 01:
<?php
$var1 = "Hello";
echo $var1;
?>
Attempt 02:
<?php
$view = '$var1 = "Hello";
echo $var1;';
echo $view;
?>
But I'm trying to call variable without using "echo" or "print" command, as mentioned below
<?php
$view = '$var1 = "Hello";
echo $var1;';
$view;
?>
Is there any other way to achieve this? Please advise.
<?php
$view = '$var1 = "Hello";
echo $var1;';
eval($view);
?>

Infinite loop. Why? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
i wanna test if my variable is empty or not to display some differents things.
When i don't use the else...if everything work but when i use this code :
<?php
$Amazon = get_post_meta($post->ID, "Lien Amazon", true);
?>
<?php
if( $Amazon != NULL ){
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;}
else {
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;}
?>
What is the problem ? Thank you
Here is an output error. You haven't closed and reopened the string on trying to concat a variable.
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;
Do instead:
echo '<li><span class="post-meta-key">Acheter sur Amazon</li>' ;

Get youtube info with php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want get in my site this text info:
http://gdata.youtube.com/feeds/api/videos/IyBvgi4ZlbM
when the video is not found.
how i can writte the code?
i don't understand here:
https://developers.google.com/youtube/2.0/developers_guide_php?csw=1
thank you!
You can try checking the video is available or not with headers:
$headers = get_headers("http://gdata.youtube.com/feeds/api/videos/".$row['youtube']);
if (!strpos($headers[0], '200'))
{
echo "Video is not found";
}
Try this ;)
<?php
$headers = get_headers('http://gdata.youtube.com/feeds/api/videos/IyBvgi4ZlbM');
$is_ok = substr($headers[0], 9, 3) == 200;
if($is_ok){
echo 'Video is OK :)';
}
else{
echo 'Something is wrong :(';
}

If else - how to switch between two php files depending on the url [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So, I would like to switch between 2 php files depending on the url. So far my code looks like this...
<?php $url = $_SERVER["REQUEST_URI"];
if (strpos($url, "/ru/")) {
<?php wp_nav_menu(array('theme_location' => 'Tours-en')); ?>
}else {
<?php wp_nav_menu(array('theme_location' => 'Tours-ru')); ?>
}
?>
I don't know what should be before <?php wp_nav_menu(array('theme_location' => 'Tours-en')); ?> like use <? php wp_nav_menu etc.. I hope you see what is my problem. I don't know the name of the "command" which should be before <?php.
To clarify, the two php files between which I would like to switch contain menus.
Any help would be appreciated.
What about this:
<?php
$url = $_SERVER["REQUEST_URI"];
wp_nav_menu(array(
'theme_location' => (strpos($url, "/ru/"))?'Tours-en':'Tours-ru'
));
?>

Categories