php code not working

Srirama

Adept
hi guys,I'm trying to get a simple login system going,where in a user registers with his/her email id,an email is sent to that email id with a registration code.
That registration id is entered and verified.
Since i'm a newbie to the php world :ashamed:
I stored all the information from the form,that I got in a previous php page in session variables,so that they remain accessible on the other php page where i check for validation.
So basically just nothing happens here,if the condition of the IF is found to be true,there should be an insertion and redirect me to the register-success.php page.

What is going wrong here?
Any help will deeply appreciated!,thanks for your time! :)

CODE:

<?php

session_start();

$link= mysql_connect(
':/Applications/MAMP/tmp/mysql/mysql.sock',
'root',
'root'
) or die("Could not connect.");
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db("forum");
if(!$db) {
die("Unable to select database");
}
$regcode=$_POST['regcode'];
$_SESSION['random']=$random;
$fname=$_SESSION['fname'];
$lname=$_SESSION['lname'];
$login=$_SESSION['login'];
$password=$_SESSION['password'];
$email=$_SESSION['email'];
if($regcode == $random)
{
//Create INSERT query
$registerquery = mysql_query("INSERT INTO members (firstname,lastname,username,password,email) VALUES('".$fname."', '".$lname."', '".$login."','".$password."','".$email."')");

//Check whether the query was successful or not
if($registerquery) {
header("location: register-success.php");
exit();
}else {
die("Query failed");
}
}

?>
 
Check out the documentation for the "header()" function on the php.net site and also the comments which have some possibly useful suggestions.

Like using the headers_sent() function for troubleshooting, or ensuring no extra spaces/lines in your PHP file before/after the opening/closing tags.

Another interesting tip was to check your .php file format (encoding) to ensure its UTF8 and nothing else which could be sending some characters before the header() call...
 
vishalrao said:
Check out the documentation for the "header()" function on the php.net site and also the comments which have some possibly useful suggestions.

Like using the headers_sent() function for troubleshooting, or ensuring no extra spaces/lines in your PHP file before/after the opening/closing tags.

Another interesting tip was to check your .php file format (encoding) to ensure its UTF8 and nothing else which could be sending some characters before the header() call...
Thanks for your suggestion mate!

I also messed up with Session having single quotes instead of double quotes.

Now it works great! :)
 
Am back with one more..

Code:

<?php
$video="http://www.youtube.com/v/AyPzM5WK8ys";
?>
<html>
<object width="425" height="350">
<param name="movie" value="<? echo $video ?>" />
<param name="wmode" value="transparent" />
<embed src="<? echo $video ?>"
type="application/x-shockwave-flash"
wmode="transparent" width="425" height="350" />
</object>
</html>

trying to embed the following youtube in php,actually this is not exactly the scenario,but a simplified one.
what i am actually doing is getting the code for the youtube from a user and trying to display it.

what do i have to do,to make it work?

This is making me mad :mad:
 
What is the problem you see? What if you run your code in web server and click "View Source" in your browser (try different browsers also) to see the actual output?

Maybe the shortcut <? ... ?> is not enabled and you need to do the full <?php echo $video ?> thing?

edit: assuming the actual rest of the youtube code/html tags/params are correct, if you check that works by hardcoding HTML with no PHP first...
 
The problem is it does nothing..

But,

on doing the php echo thing,i get the flash player going,but it says movie not loaded(on rightclicking on the page)! :mad:

e6vmhk.png


And,yes it works while using html alone.
 
No,the view source does not show it.

The thing is i had it woking briefly,and i fiddled around a bit,and it does not work again.

Look at the code below:

newforone.php

<?php

error_reporting(0);

session_start();

print "<link rel='stylesheet' href='style.css' type='text/css'>";

print "<table class='maintables'>";

print "<tr class='headline'><td>Post a link</td></tr>";

print "<tr class='maintables'><td>";

if(isset($_POST['submit']))

{

$video1 = $_POST['video1'];

if(strlen($video1)<1)

{

print "You did not type in a link."; //no post entered

}



else

{





$_SESSION["video1"]=$video1;



}



}

else

{

print "<form action='newone.php' method='post'>";

print "link:
";

print "<input type='text' name='video1' size='60'>
";



print "<input type='submit' name='submit' value='submit'></form>";

}

print "</td></tr></table>";

?>

newone.php

<?php

session_start();

$video1 = $_SESSION["video1"];

?>

<html>

<object width="425" height="350">

<param name="movie" value="<?php echo $video1; ?>" />

<param name="wmode" value="transparent" />

<embed src="<?php echo $video1; ?>"

type="application/x-shockwave-flash"

wmode="transparent" width="425" height="350" />

</object>

</html>
 
Can't say... maybe try adding extra double quotes for the echo param, like <?php echo "$video1"; ?>

Also since you say view source does not "show it", try using the flush(); call or whatever, also see if there is missing <head> and <body> tags which are normally under <html>

Must be some small formatting/typo in there :)
 
Well for header(); I'd like to suggest few things, use ob_start(); for header(); to work

And the syntax for header() is header("Location: index.php");

I have found it to not working when using header("location: index.php");

NOTICE THE L(caps) and l(small) in Location

And for the video thing, I'd suggest just use dreamweaver to generate the video embed code.
 
^^ Was that pseudo code or actual code?

If actual, try to stick to standards :p Stylesheets in header.

And you really should sanitize your $_POST ;)

Use the iframe method instead to embed.

Code:
http://www.youtube.com/embed/mDfM0tk6Os0

So that would be

Code:
<iframe title="YouTube video player" class="youtube-player" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/VIDEOID" frameborder="0" allowFullScreen></iframe>

Best not take the url and show directly. Take the link, regex match it and then use the matched regex to add. It will be safer.

Or best use the api.API Overview Guide - YouTube APIs and Tools - Google Code
 
Ok guys,thanks for the input.

As of now the code is also displaying in view source,but the frigging thing just does not load.

My test site,which uses the post method to get the link,which it also displays on echo.



A simpler one,where variable is directly passed within the same php page,and not got via post.

 
The images are blurry, but the <param name movie value="""> part has double-double quotes it looks like (in the first one) when the <embed src=""> seems fine, the non post second one looks better. Can you see why there are extra double quotes (or something like it) in the youtube link for the <param name=movie value=""> tag?
 
Got rid of the extra double quotes.

Still nothing.

screenshot20110130at526.png


As you mentioned the pic does seems to be blurry.

Have a look here.

Click here

I am totally befuddled,one which is directly embedded using html works,the other does not,i cant find the bug here.

Look at the next screenshot.



for clarity sakes.

Once more click here
 
Back
Top