[SOLVED] needs help with saving a $variable to a file &

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
User avatar
asi0917
Forum Commoner
Posts: 41
Joined: Thu Nov 25, 2004 10:37 am
Location: Shoreline, Washington
Contact:

[SOLVED] needs help with saving a $variable to a file &

Post by asi0917 »

i am totaly new to server side scripting and found this niffty script
<?php
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip;
?>

can someone tell me how to save $ip to a file?

also i was wondering what all this file.php?code=code stuff is about

also, i was on greycobra.com and keep encountering the problem of this information i need, for example
http://www.greycobra.com/tutorials.php? ... view&id=53
asks you for your host, database and i don't even know where mySQL surver thingy is or what it is exactly
and
FYI i use http://hosting.mixcat.com/ so.. ya
_________________________________
help=goodness
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

1. how to write something to a file [php_man]fwrite[/php_man]

2. file.php?variable=code

you can fetch the code in the url with the reserved variable $_GET, in this case you just use $_GET['variable'] to use code.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: [SOLVED] needs help with saving a $variable to a file &a

Post by josh »

asi0917 wrote: also i was wondering what all this file.php?code=code stuff is about
That is how you pass a variable to a script

create test.php and put the following code in it:

Code: Select all

<?php
print_r($_REQUEST);
?>
then go to test.php?code=code


This is how php gets user input, to get a specific input do something like:

Code: Select all

<?php
echo ("I like " . $_REQUEST['affection']);
?>
then call test.php?affection=php

This should print out "I like php"

see where I'm going?
asi0917 wrote: asks you for your host, database and i don't even know where mySQL surver thingy is or what it is exactly
and
FYI i use http://hosting.mixcat.com/ so.. ya
That is an issue to take up with hosting.mixcat.com

Is your email and ftp and host logins/passwords all the same? If so then your mysql password is probably the same as well, usually the host is "localhost"

Code: Select all

<?php
$link = mysql_connect('localhost', username', 'password')
   or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
?>
Use this script to test the passwords, if you get "connected succesfully" then you have the right info

What this is doing is connecting up to an sql server, sql means simple query language and a sql server basically allows you to interact with a database from your script.
User avatar
asi0917
Forum Commoner
Posts: 41
Joined: Thu Nov 25, 2004 10:37 am
Location: Shoreline, Washington
Contact:

Post by asi0917 »

thank you
User avatar
asi0917
Forum Commoner
Posts: 41
Joined: Thu Nov 25, 2004 10:37 am
Location: Shoreline, Washington
Contact:

Post by asi0917 »

so why doesn't this work?

Code: Select all

<html>
<body>
<a href="http://hosting.mixcat.com/asi0917/welcome.php?=1">
#1</a>
<br>
<a href="http://hosting.mixcat.com/asi0917/welcome.php?=2">
#2</a>
<br>
<?php
echo ("I like " . $_REQUEST['link']);
?>
<?
if ($_REQUEST['link'])===1);
{
echo "you clicked link #1";
}
else
{
echo "you clicked link #2";
}
?>
</body>
</html>
????
?>
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

2 reasons

1, you didnt name the variable in the url

you did
?=1

you should have done
?link=1



2,

you are improperly using the === operator.
=== means equal AND of the same data type
== just means equal, and is less specific

data which comes trhough $_REQUEST is generally of data type string
you are saying
if $_REQUEST['link'] is equal to and the same type, as integer 1
you want to say:
if $_REQUEST['link'] is equal to and the same type, as string 1

this would work

Code: Select all

if ($_REQUEST['link']) === '1') { // the quotes mean its a string
User avatar
asi0917
Forum Commoner
Posts: 41
Joined: Thu Nov 25, 2004 10:37 am
Location: Shoreline, Washington
Contact:

Post by asi0917 »

awwwwww i wasn't sure waht the difference was between === and == but that was a typo :)
thanks for the correction
Post Reply