Doesnt response on "if" statement?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Doesnt response on "if" statement?

Post by jmansa »

I'm trying to make my page show an "iframe" if certain parameters is ok, but it doesnt seem to work. Can somebody please guide me in the right direction?

1'st part.

Code: Select all

<?php

if (($_GET['uid']) && (is_numeric($_GET['uid']))) {
$userid = $_GET['uid'];

$dbhost = 'myhost';
$dbuser = 'myusername';
$dbpass = 'mypassword';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                    ("Error connecting to mysql: " . mysql_error());

$dbname = 'mydatabase';
mysql_select_db($dbname);

//var_dump($uid);
 
$query="SELECT * FROM users WHERE uid='".$uid."'"; 
$result=mysql_query($query) or die("Unable to find requested user");
$currUser = mysql_fetch_array($result);

?>
The call

Code: Select all

<?php if($currUser['uid']['3d']=='no') { echo '<iframe src= "/player/' . $currUser['uid'] . '.html" width="510" height="345" frameborder="0" scrolling="no"></iframe>';} ?>
The end

Code: Select all

<?php
} else {
echo "No user specified";
}
?>
Hope somebody can help!!!
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

Underneath $currUser = mysql_fetch_array($result); add var_dump($currUser); . Rerun the script and show us the output of $currUser.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

$currUser['uid']['3d'] is wrong. Without seeing your database table schema I can only guess, but I reckon you want: $currUser['3d']
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

I think that your $currUser['uid'] is an array, (since it seems to contain $currUser['uid']['3d']), which will cause problems if you try and echo it...
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

GM wrote:I think that your $currUser['uid'] is an array, (since it seems to contain $currUser['uid']['3d']), which will cause problems if you try and echo it...
$currUser comes from..

Code: Select all

$currUser = mysql_fetch_array($result);
.. there's no way $currUser['uid'] can be an array.
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

OK - i was just looking at the code in the iframe part, which says $currUser['uid']['3d'] - which suggested that $currUser['uid'] is an array, and therefore an attempt to echo it would produce 'Array'.

You responded while I was typing, so I didn't see your response before I posted mine. I agree with you that $currUser is probably the problem.
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Post by jmansa »

JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


OK. Tryid to make an array...

Code: Select all

<?php

if (($_GET['uid']) && (is_numeric($_GET['uid']))) {
$userid = $_GET['uid'];

$dbhost = 'myhost';
$dbuser = myusername;
$dbpass = 'mypassword';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                    ("Error connecting to mysql: " . mysql_error());

$dbname = 'mydatabase';
mysql_select_db($dbname);

//var_dump($uid);
 
$query="SELECT * FROM users WHERE uid='".$uid."'"; 
$result=mysql_query($query) or die("Unable to find requested user");
$currUser = mysql_fetch_array($result);

$iframe = array();
while($r = mysql_fetch_row($result)) {
    $iframe[] = array('uid'=>$r[0],'3d'=>$r[1]);
	sort($array); }	

?>
Still i get no response....? Any ideas...


JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Right. Lets go back to the drawing board here.

1. What is coming from your database? Show us the table fields.

2. What parameters are required to show the iframe?
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Post by jmansa »

The tables are as follows...
uid
name
adress1
adress2
area
city
email
3d
I want to show all the fields regardless of the "3d" field is set to "yes" or "no". I want to show the iframe if the "3d" is set to "yes". The "3d" field is set to "enum" with a yes/no choice.

Hope thats enough!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

I've no idea what an enum field returns when you select it, but assuming it returns the value set rather than the index:

Code: Select all

$query="SELECT * FROM users WHERE uid='".$uid."'";
$result=mysql_query($query) or die("Unable to find requested user");
$currUser = mysql_fetch_array($result);

if ($currUser['3d'] == "yes") {
  echo "iframe";
} else {
  echo "no iframe";
}
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Post by jmansa »

SUPER!!! It did the job but.... Just one little error left. It gets the iframe but not with the html page it should. It shows the "index" page in the iframe but should be showing something else. Any idea???

Code: Select all

<?php if ($currUser['3d'] == "yes") { 
	echo '<iframe src= "/users/' . $currUser['uid'] . '.html" width="510" height="345" frameborder="0" scrolling="no"></iframe>';} 
	else {
	echo "";}
	?>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Sounds like your iframe src is wrong. Just look at the HTML that's being produced and you should be able to figure it out.
jmansa
Forum Commoner
Posts: 81
Joined: Wed Aug 23, 2006 4:00 am

Post by jmansa »

Doesn't seem to be it! I tryid to make the source "http://www.cnn.com" but I still got the "index" page??? There must be something wrong in the code. Any idea?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$uid isn't created anywhere in the snippets posted. $userid is, but not $uid. This may be a source of problems.
Post Reply