Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kinda Java, but in PHP???

Status
Not open for further replies.

internetguy

Technical User
Nov 22, 2003
57
US
Ok, I am trying to have a section on the side of my webpage with several links with friend names. I am trying to make it where when you click the link of the person's name it sends a php request to itself displaying that person, picture in the center of the page. I know everything except how to make it work by clicking links. Right now it is just the names with checkboxes. Please let me know if there is a way to do this.
 
Make each link so that is contains a variable and value for each person. Eg
Code:
<a href=&quot;friends.php?name=bob&quot;>Bob</a>
<a href=&quot;friends.php?name=frank&quot;>Frank</a>
<a href=&quot;friends.php?name=helen&quot;>Helen</a>
.
.
.
then on your friends.php page:
Code:
switch($name)
{
case &quot;bob&quot;:
// code for putting bob info on the page
break;
case &quot;frank&quot;:
// code for putting frank info on the page
break;
case &quot;helen&quot;:
// code for putting helen info on the page
break;
default:
// code for when the user first visit the page
}

Im curious why you say this is &quot;kinda java&quot;. Anyway, that isn't important. Hope this helps.
 
Oh wow thanks a lot, I only though cases related to drop down lists. And to answer your question there is a way in javascript to open another window inside the same page based on coordinates, but it sucks to write out. Anywho, thanks again.
 
Just as a note... java is VERY different to javascript.... they are not the same thing!
 
ok, I am having a problem, it is saying that there is no variable value for $name in the switch($name) expression. I am not sure how I am suppsoed to assign it a value without a post form.
 
By including the &quot;?name=whatever&quot; after the filename it tells php to set the variable $name to the value of &quot;whatever&quot;.
Try
Code:
switch($_GET['name'])
instead
 
ok, now it is saying that it is an undefined index. Just for the record, I have the links of the people's names on the friends page too, I am just sendingthe request back to itself so that the picture will load in the main part of the page.
 
I wasn't entirely sure that was going to work anyway... but I thought it was worth trying.
It shudn't matter that you are calling the same page.
Hmmm, now I clutching at straws (I self taught php to myself so I dont know everything). Try renaming the variable... I dont think &quot;name&quot; is a reserved word
Now your links shoud look like:
Code:
<a href=&quot;friends.php?fnam=bob&quot;>Bob</a>
and your php:
Code:
switch($fnam)
// or
switch($_GET['fnam'])
 
Sorry buddy, it didn't work. That is pretty amazing though that you taught yourself, I have had to read from a book. I am still workin on it though, so if you think of any other ideas that would be great, thanks.
 
hmmmm, i have this feeling its something simple. sleipnir214 might be able to see it.
Try using the age old code
Code:
if ($fnam == &quot;bob&quot;) {
// code for bob
} else if ($fnam == &quot;frank&quot;) {
// code for frank
} else if ($fnam == &quot;helen&quot;) {
.
.
.
} else {
// default screen
}
 
Well the problem with this is that it isn't recognizing the links as variables when they are sent, so the switch function wouldn't work anyways.
 
Ok, thats something to do with your server setup.
I *think* the setting register_argc_argv is set to off in your php.ini file.
My server configuration knowledge is very limited though
 
Sorry, that is on too, I have global variables off though, but I doubt that would have anything to do with it.
 
In which case (as my understanding goes) you need to use $_GET['fnam'] in your script. However, if you are using an older version of php try $HTTP_GET_VARS['fnam'] instead.
 
Just curious.. have you tried just printing out your $_GET array to see if anything is passing? I'm not where I can test anyting right now but its worth a try..

Code:
print_r($_GET);

You might also post up your ini settings.. use phpinfo() and lets see if we can find something wrong.

-Dustin
Rom 8:28
 
k, this is all so sorry if it is kinda long
allow_call_time_pass_reference On On
allow_url_fopen On On
always_populate_raw_post_data Off Off
arg_separator.input & &
arg_separator.output & &
asp_tags Off Off
auto_append_file no value no value
auto_prepend_file no value no value
browscap no value no value
default_charset no value no value
default_mimetype text/html text/html
define_syslog_variables Off Off
disable_classes no value no value
disable_functions no value no value
display_errors On On
display_startup_errors Off Off
doc_root c:\senior_project c:\senior_project
docref_ext no value no value
docref_root no value no value
enable_dl On On
error_append_string no value no value
error_log no value no value
error_prepend_string no value no value
error_reporting 2047 2047
expose_php On On
extension_dir c:\php c:\php
file_uploads On On
gpc_order GPC GPC
highlight.bg #FFFFFF #FFFFFF
highlight.comment #FF8000 #FF8000
highlight.default #0000BB #0000BB
highlight.html #000000 #000000
highlight.keyword #007700 #007700
highlight.string #DD0000 #DD0000
html_errors On On
ignore_repeated_errors Off Off
ignore_repeated_source Off Off
ignore_user_abort Off Off
implicit_flush Off Off
include_path .;c:\php4\pear .;c:\php4\pear
log_errors Off Off
log_errors_max_len 1024 1024
magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off
max_execution_time 30 30
max_input_time 60 60
open_basedir no value no value
output_buffering no value no value
output_handler no value no value
post_max_size 8M 8M
precision 12 12
register_argc_argv On On
register_globals On On
report_memleaks On On
safe_mode Off Off
safe_mode_exec_dir no value no value
safe_mode_gid Off Off
safe_mode_include_dir no value no value
sendmail_from me@localhost.com me@localhost.com
sendmail_path no value no value
serialize_precision 100 100
short_open_tag On On
SMTP localhost localhost
smtp_port 25 25
sql.safe_mode Off Off
track_errors Off Off
unserialize_callback_func no value no value
upload_max_filesize 2M 2M
upload_tmp_dir C:\PHP\uploadtemp C:\PHP\uploadtemp
user_dir no value no value
variables_order EGPCS EGPCS
xmlrpc_error_number 0 0
xmlrpc_errors Off Off
y2k_compliance On On


apache
Apache for Windows 95/NT

Apache Version Apache/1.3.29 (Win32) PHP/4.3.4
Apache Release 10324100
Apache API Version 19990320
Hostname:port localhost:80
Timeouts Connection: 300 - Keep-Alive: 15

Directive Local Value Master Value
child_terminate 0 0
engine 1 1
last_modified 0 0
xbithack 0 0


Apache Environment
Variable Value
COMSPEC C:\WINDOWS\system32\cmd.exe
DOCUMENT_ROOT c:/website/
HTTP_ACCEPT image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
HTTP_ACCEPT_ENCODING gzip, deflate
HTTP_ACCEPT_LANGUAGE en-us
HTTP_CONNECTION Keep-Alive
HTTP_HOST localhost
HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
PATH C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
REMOTE_ADDR 127.0.0.1
REMOTE_PORT 1830
SCRIPT_FILENAME c:/website/tmpg9mgs4goq.php
SERVER_ADDR 127.0.0.1
SERVER_ADMIN jdevan@anths.org
SERVER_NAME localhost
SERVER_PORT 80
SERVER_SIGNATURE <ADDRESS>Apache/1.3.29 Server at localhost Port 80</ADDRESS>
SERVER_SOFTWARE Apache/1.3.29 (Win32) PHP/4.3.4
SystemRoot C:\WINDOWS
WINDIR C:\WINDOWS
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD GET
QUERY_STRING no value
REQUEST_URI /TMPg9mgs4goq.php
SCRIPT_NAME /TMPg9mgs4goq.php


HTTP Headers Information
HTTP Request Headers
HTTP Request GET /TMPg9mgs4goq.php HTTP/1.1
Accept image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
Accept-Encoding gzip, deflate
Accept-Language en-us
Connection Keep-Alive
Host localhost
User-Agent Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
HTTP Response Headers
X-Powered-By PHP/4.3.4
Keep-Alive timeout=15, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/html


bcmath
BCMath support enabled


calendar
Calendar support enabled


com
Directive Local Value Master Value
com.allow_dcom Off Off
com.autoregister_casesensitive On On
com.autoregister_typelib Off Off
com.autoregister_verbose Off Off
com.typelib_file no value no value


ctype
ctype functions enabled


ftp
FTP support enabled


mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 3.23.49

Directive Local Value Master Value
mysql.allow_persistent On On
mysql.connect_timeout 60 60
mysql.default_host no value no value
mysql.default_password no value no value
mysql.default_port no value no value
mysql.default_socket no value no value
mysql.default_user no value no value
mysql.max_links Unlimited Unlimited
mysql.max_persistent Unlimited Unlimited
mysql.trace_mode Off Off


odbc
ODBC Support enabled
Active Persistent Links 0
Active Links 0
ODBC library Win32

Directive Local Value Master Value
odbc.allow_persistent On On
odbc.check_persistent On On
odbc.default_db no value no value
odbc.default_pw no value no value
odbc.default_user no value no value
odbc.defaultbinmode return as is return as is
odbc.defaultlrl return up to 4096 bytes return up to 4096 bytes
odbc.max_links Unlimited Unlimited
odbc.max_persistent Unlimited Unlimited


overload
User-Space Object Overloading Support enabled


pcre
PCRE (Perl Compatible Regular Expressions) Support enabled
PCRE Library Version 4.3 21-May-2003


session
Session Support enabled
Registered save handlers files user

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path C:\PHP\sessiondata C:\PHP\sessiondata
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies Off Off
session.use_trans_sid Off Off


standard
Regex Library Bundled library enabled
Dynamic Library Support enabled
Internal Sendmail Support for Windows enabled

Directive Local Value Master Value
assert.active 1 1
assert.bail 0 0
assert.callback no value no value
assert.quiet_eval 0 0
assert.warning 1 1
auto_detect_line_endings 0 0
default_socket_timeout 60 60
safe_mode_allowed_env_vars PHP_ PHP_
safe_mode_protected_env_vars LD_LIBRARY_PATH LD_LIBRARY_PATH
url_rewriter.tags a=href,area=href,frame=src,input=src,form=,fieldset= a=href,area=href,frame=src,input=src,form=,fieldset=
user_agent no value no value


tokenizer
Tokenizer Support enabled


wddx
WDDX Support enabled
WDDX Session Serializer enabled


xml
XML Support active
XML Namespace Support active
EXPAT Version 1.95.6


zlib
ZLib Support enabled
Compiled Version 1.1.4
Linked Version 1.1.4

Directive Local Value Master Value
zlib.output_compression Off Off
zlib.output_compression_level -1 -1
zlib.output_handler no value no value


Additional Modules
Module Name


Environment
Variable Value
ALLUSERSPROFILE C:\Documents and Settings\All Users
CommonProgramFiles C:\Program Files\Common Files
COMPUTERNAME LARRY
ComSpec C:\WINDOWS\system32\cmd.exe
NUMBER_OF_PROCESSORS 1
OS Windows_NT
Path C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE x86
PROCESSOR_IDENTIFIER x86 Family 15 Model 2 Stepping 9, GenuineIntel
PROCESSOR_LEVEL 15
PROCESSOR_REVISION 0209
ProgramFiles C:\Program Files
SystemDrive C:
SystemRoot C:\WINDOWS
TEMP C:\WINDOWS\TEMP
TMP C:\WINDOWS\TEMP
USERPROFILE C:\Documents and Settings\LocalService
windir C:\WINDOWS


PHP Variables
Variable Value
PHP_SELF /TMPg9mgs4goq.php
_SERVER[&quot;COMSPEC&quot;] C:\\WINDOWS\\system32\\cmd.exe
_SERVER[&quot;DOCUMENT_ROOT&quot;] c:/website/
_SERVER[&quot;HTTP_ACCEPT&quot;] image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*
_SERVER[&quot;HTTP_ACCEPT_ENCODING&quot;] gzip, deflate
_SERVER[&quot;HTTP_ACCEPT_LANGUAGE&quot;] en-us
_SERVER[&quot;HTTP_CONNECTION&quot;] Keep-Alive
_SERVER[&quot;HTTP_HOST&quot;] localhost
_SERVER[&quot;HTTP_USER_AGENT&quot;] Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
_SERVER[&quot;PATH&quot;] C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem
_SERVER[&quot;REMOTE_ADDR&quot;] 127.0.0.1
_SERVER[&quot;REMOTE_PORT&quot;] 1830
_SERVER[&quot;SCRIPT_FILENAME&quot;] c:/website/tmpg9mgs4goq.php
_SERVER[&quot;SERVER_ADDR&quot;] 127.0.0.1
_SERVER[&quot;SERVER_ADMIN&quot;] jdevan@anths.org
_SERVER[&quot;SERVER_NAME&quot;] localhost
_SERVER[&quot;SERVER_PORT&quot;] 80
_SERVER[&quot;SERVER_SIGNATURE&quot;] <ADDRESS>Apache/1.3.29 Server at localhost Port 80</ADDRESS>
_SERVER[&quot;SERVER_SOFTWARE&quot;] Apache/1.3.29 (Win32) PHP/4.3.4
_SERVER[&quot;SystemRoot&quot;] C:\\WINDOWS
_SERVER[&quot;WINDIR&quot;] C:\\WINDOWS
_SERVER[&quot;GATEWAY_INTERFACE&quot;] CGI/1.1
_SERVER[&quot;SERVER_PROTOCOL&quot;] HTTP/1.1
_SERVER[&quot;REQUEST_METHOD&quot;] GET
_SERVER[&quot;QUERY_STRING&quot;] no value
_SERVER[&quot;REQUEST_URI&quot;] /TMPg9mgs4goq.php
_SERVER[&quot;SCRIPT_NAME&quot;] /TMPg9mgs4goq.php
_SERVER[&quot;PATH_TRANSLATED&quot;] c:/website/tmpg9mgs4goq.php
_SERVER[&quot;PHP_SELF&quot;] /TMPg9mgs4goq.php
_SERVER[&quot;argv&quot;] Array
(
)


_SERVER[&quot;argc&quot;] 0
_ENV[&quot;ALLUSERSPROFILE&quot;] C:\\Documents and Settings\\All Users
_ENV[&quot;CommonProgramFiles&quot;] C:\\Program Files\\Common Files
_ENV[&quot;COMPUTERNAME&quot;] LARRY
_ENV[&quot;ComSpec&quot;] C:\\WINDOWS\\system32\\cmd.exe
_ENV[&quot;NUMBER_OF_PROCESSORS&quot;] 1
_ENV[&quot;OS&quot;] Windows_NT
_ENV[&quot;Path&quot;] C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem
_ENV[&quot;PATHEXT&quot;] .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
_ENV[&quot;PROCESSOR_ARCHITECTURE&quot;] x86
_ENV[&quot;PROCESSOR_IDENTIFIER&quot;] x86 Family 15 Model 2 Stepping 9, GenuineIntel
_ENV[&quot;PROCESSOR_LEVEL&quot;] 15
_ENV[&quot;PROCESSOR_REVISION&quot;] 0209
_ENV[&quot;ProgramFiles&quot;] C:\\Program Files
_ENV[&quot;SystemDrive&quot;] C:
_ENV[&quot;SystemRoot&quot;] C:\\WINDOWS
_ENV[&quot;TEMP&quot;] C:\\WINDOWS\\TEMP
_ENV[&quot;TMP&quot;] C:\\WINDOWS\\TEMP
_ENV[&quot;USERPROFILE&quot;] C:\\Documents and Settings\\LocalService
_ENV[&quot;windir&quot;] C:\\WINDOWS
 
Well, just glancing over it I'm not to sure why its not working. If you're sure it won't effect any other scripts running on your server, turn register globals off. Its much safer to run with them off anyways. This may clear up the problem.

Also, try running the same file that you ran with phpinfo() in it but pass it an arg.. ie phpinfo.php?name=frank

Somewhere on the page will be a list of all arguments passed into the script.. see if its making it there.

-Dustin
Rom 8:28
 
it might be useful if you post you php file code here. Maybe there is something else that is affecting it.
 
<html>
<head>
<title>Those that influence me</title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot;>
</head>

<body>
<table width=&quot;760&quot;>
<tr>
<td colspan=&quot;3&quot;><h2>My Friends</h2></td>
</tr>
<tr>
<td height=&quot;1&quot; bgcolor=&quot;#999999&quot; colspan=&quot;3&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot; colspan=&quot;3&quot; height=&quot;30&quot;>Those that influence me</td>
</tr>
<tr>
<td height=&quot;1&quot; bgcolor=&quot;#999999&quot; colspan=&quot;3&quot;></td>
</tr>
<tr>
<td height=&quot;20&quot;></td>
</tr>
<tr>
<td width=&quot;150&quot; valign=&quot;top&quot;>
<a href=&quot;friends.php?fnam=melissa&quot;>Melissa Almond</a>
<?php
switch($_GET['fnam'])
{
case &quot;melissa&quot;:
break;
default:
}
print_r($_GET);
?>
</td>
<td width=&quot;1&quot; bgcolor=&quot;999999&quot; height=&quot;500&quot;></td>
<td><?php
if (empty($name))
{
}
else
{
?><div align=&quot;center&quot;><img src='pics/friends/<?php echo $name ?>.jpg'></div></td>
</tr>
<tr>
<td><a class=&quot;link&quot; href=&quot;main.php&quot;><--Back</a></td>
</tr>
<?php }
?>
</table>
</body>
</html>
 
ok try:

<html>
<head>
<title>Those that influence me</title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;style.css&quot;>
</head>

<body>
<table width=&quot;760&quot;>
<tr>
<td colspan=&quot;3&quot;><h2>My Friends</h2></td>
</tr>
<tr>
<td height=&quot;1&quot; bgcolor=&quot;#999999&quot; colspan=&quot;3&quot;></td>
</tr>
<tr>
<td align=&quot;right&quot; colspan=&quot;3&quot; height=&quot;30&quot;>Those that influence me</td>
</tr>
<tr>
<td height=&quot;1&quot; bgcolor=&quot;#999999&quot; colspan=&quot;3&quot;></td>
</tr>
<tr>
<td height=&quot;20&quot;></td>
</tr>
<tr>
<td width=&quot;150&quot; valign=&quot;top&quot;>
<a href=&quot;friends.php?fnam=melissa&quot;>Melissa Almond</a>
</td>
<td width=&quot;1&quot; bgcolor=&quot;999999&quot; height=&quot;500&quot;></td>
<td><?php
if (empty($fnam))
{
}
else
{
?>
<div align=&quot;center&quot;>
<?php
switch($_GET['fnam'])
{
case &quot;melissa&quot;:
echo &quot;Melissa Almond<br>\n&quot;;
break;
default:
}
?>
<br><img src='pics/friends/<?php echo $fnam ?>.jpg'></div></td>
</tr>
<tr>
<td><a class=&quot;link&quot; href=&quot;main.php&quot;><--Back</a></td>
</tr>
<?php }
?>
</table>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top