1

I have an if statement that is supposed to set the variable $pc162v to a link specified in the MySQL table if content exists in the $vid column of the row. The problem is, the PHP is detecting that there's a link in the MySQL, but isn't setting the $pc162v variable correctly.

Here's the variable declarations:

$pc162v = "";
$vid162 = '<embed width="420" height="236" src="'.$pc162v.'" type="application/x-shockwave-flash"></embed>';

Here's the section of the if statement:

if (empty($row[7])) {
   $vid162 = '';
}
else {
   $pc162v = $row[7];
}

In my web browsers, the part of the code where the variable $vid162 is used, shows up as the following:

<embed width="420" height="236" src="" type="application/x-shockwave-flash">

I have also tried setting $vid162 to:

<embed width="420" height="236" src="<?php echo $pc162v; ?>" type="application/x-shockwave-flash"></embed>

and that just makes the code in my web browser:

<embed width="420" height="236" src="<?php echo $pc162v; ?>" type="application/x-shockwave-flash">

Hope someone has a solution! Thanks in advance.

4
  • The variable is empty right? so then it shows empty when echoed Commented Oct 24, 2013 at 21:56
  • Maybe post all the code concerning the issue. Now it looks like you are setting $pc162v to an empty string. But expect it to have another value. Commented Oct 24, 2013 at 21:56
  • @SmithSmithy It is originally declared as empty, but should be set to the content of row 7 in the "else" part of the if statement. Commented Oct 24, 2013 at 21:59
  • You really need to change the way you name variables! Commented Oct 24, 2013 at 22:07

2 Answers 2

1

You declare an empty var $pc162v, and then use it on the next line to fill the src attribute in $vid162. I would use:

$vid162 = '';

if (!empty($vid)) //Or $row[7], if that contains the url
    $vid162 = '<embed width="420" height="236" src="'.$vid.'" type="application/x-shockwave-flash"></embed>';
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, hadn't really thought to doing it that way, works well for what I'm trying to do.
0

I'm assuming you declare the variable as empty right before the call just to demonstrate for us. If not, that's definitely the problem.

It appears that the PHP itself is not being parsed in your code. Although I can't tell you specifically whether the variable is being set without seeing the interactions with the database, I can say that PHP should always parse if served from a web server that has PHP configured properly. If you know that PHP is being parsed properly in other places, make sure that the page you're using has the .php extension.

If you're unsure of whether the variable is being set correctly, what I would do is set up a test case. In other words, hard in a situation in which case you believe the variable will be pulled correctly from the database, and then simply echo it somewhere on the page. Or, better still, you can use a tool like Kint to help you with debugging. It's definitely a step up from the old var_dump($var);die(); business, although that's an option, too.

So, in essence, I would verify that PHP is being parsed at all on your page, and then test the variable, either via echo, or by using var_dump.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.