Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   my first php script.. (https://novahq.net/forum/showthread.php?t=26072)

General Nuisance 05-27-2005 11:41 AM

my first php script..
 
i wrote my first php script! :) :) :)

rather simple but i could not do any b 4

go to my site ( click banner in sig) on right there is link called Whats my ip click it...

i'm gonna slowly re do whole site in php... wright my own portal SLOWLY... some of this php stuff don't make much since... but some is really easy..

Steve 05-27-2005 11:43 AM

the only thing on the right is Sponsors and top sites.

in what way do we sponsor you btw?

General Nuisance 05-27-2005 11:50 AM

yes you do.. in a way.. my the link is on the forum.. and the link was is the news....by "sponsors" i mean Links but Sponsors looks better...

Steve 05-27-2005 11:53 AM

coolio

General Nuisance 05-27-2005 12:21 PM

im working on a link data base as i type...

atholon 05-27-2005 12:25 PM

Cool...I gotta go do some work on my site too :(

JonM 05-27-2005 01:39 PM

Re: my first php script..
 
Quote:

Originally posted by General Nuisance
i wrote my first php script! :) :) :)

rather simple but i could not do any b 4

go to my site ( click banner in sig) on right there is link called Whats my ip click it...

i'm gonna slowly re do whole site in php... wright my own portal SLOWLY... some of this php stuff don't make much since... but some is really easy..

gj bro!

are you useing
PHP Code:

$ip getnv($REMOTE_ADDR); 

or
PHP Code:

$ip $_SERVER['REMOTE_ADDR']; 

?

oh yeah...classes classes classes. PHP classes are amazingly nice...I'm using it for all mysql Queries

PHP Code:


class Queries {
     var 
$hi;
     var 
$bye;
     function 
shoot($hi,$bye){
         
uh ...
 }


yeah yeah classes are hard and your going why is he posting this... but trust me... they'll make your coding go a lot quicker

(When i say classes i don't mean like a teacher and school or something i mean actually coding)...

atholon 05-27-2005 02:05 PM

ohh yah I remember classes from the good old C++ days.

General Nuisance 05-27-2005 03:37 PM

Re: Re: my first php script..
 
PHP Code:

$ip $_SERVER['REMOTE_ADDR']; 

[/B][/QUOTE]

that one ^^^

whats the difference?

atholon 05-27-2005 03:42 PM

that is awesome...that helps when you want to ban someone from your site.

IcIshoot 05-27-2005 06:27 PM

Quote:

that one ^^^

whats the difference?
There really isn't any... just 2 ways of doing the same thing.

Personally, I always use the $_SERVER[] method, for $_GET, $_POST, etc.


And from what I just read, getenv() (Elite, pls note the correct function name ;) ) really shouldn't be used. I just read a comment that getenv() doesn't work on IIS (Microsoft's webserver).


IcI

JonM 05-27-2005 07:20 PM

seeings how mainly sites are run on linux it works if your coding for your self (Ici ... it's been a while since i used the function so i forgot okay!, :p) ... :P

IcIshoot 05-27-2005 10:35 PM

lol.

But still, wouldn't it be better to code some things, when possible so that they can work no matter what the system? ;)

Any ways, doesn't really matter.


IcI

General Nuisance 05-28-2005 08:50 PM

my link database..
 
hey i finnished codeing a link database but it does not seem to work proberly....

please look over my code i have checked and checked it...

PHP Code:

<html><head><title>Add Your Link</title></head>
<body>
<?php

$self 
$_SERVER['PHP_SELF'];
$nn $_POST['nn'];
$url $_POST['url'];
$lname $_POST['lname'];
$sc $_POST['sc'];
?>
<form action="<?php echo( $self ) ; ?>" method= "post">
Your Nick Name: <input type="text" name="nn" size="25">
<BR>
Your Websites Catagory: 
  <select size="1" name="sc">
  <option>Please Select</option>
  <option>Delta Force Xtreme Resource</option>
  <option>Joint Operations Escalation Resource</option>
  <option>Joint Operations Resource</option>
  <option>Delta Force Xtreme Squad</option>
  <option>Joint Operations Escalation Squad</option>
  <option>Joint Operations Squad</option>
  </select>
<BR>
Your Websites Name: <input type="text" name="lname" size="80">
<BR>
Your Websites URL: <input type= "text" name="url" size"80">
<BR>
<input type="submit" value="Submit Your Link"> </form>
<BR>

<?php

if( $nn and $url and $lname and $sc # makeing sure fields are filled in
# connecting to Mysql
$conn=@mysql_connect"localhost""My user name""My Password" ) or die( "err:conn" );

#selecting Database

$rs = @mysql_select_db"linkdb"$conn ) or die( "err:conn" );

#create the query

$sql="insert into links (NN, sc, LName, URL) values ( $NN, \"$sc\", \"$LName\", \"$url\" )";

#execute the query

$rs mysql_query$sql$conn );

#confirm the added link

if($rs){ echo( "The Link $lname was Added To the $sc Database!" ); }
}

?>

</body></html>

see this page

HERE

IcIshoot 05-28-2005 09:22 PM

For the forum action, change it from

PHP Code:

<?php echo( $self ) ; ?>

to

PHP Code:

<?= $self?>

(I didn't try submitting the data to a database, but I was able to have the script echo back the selected results making that change.)


IcI

General Nuisance 05-28-2005 10:59 PM

does not work for me :(

this is updateed code:

PHP Code:

 <html><head><title>Add Your Link</title></head>
<body>
<?php

$self 
$_SERVER['PHP_SELF'];
$nn $_POST['nn'];
$url $_POST['url'];
$lname $_POST['lname'];
$sc $_POST['sc'];
?>
<form action="<?php $self ?>" method= "post">
Your Nick Name: <input type="text" name="nn" size="25">
<BR>
Your Websites Catagory: 
  <select size="1" name="sc">
  <option>Please Select</option>
  <option>Delta Force Xtreme Resource</option>
  <option>Joint Operations Escalation Resource</option>
  <option>Joint Operations Resource</option>
  <option>Delta Force Xtreme Squad</option>
  <option>Joint Operations Escalation Squad</option>
  <option>Joint Operations Squad</option>
  </select>
<BR>
Your Websites Name: <input type="text" name="lname" size="80">
<BR>
Your Websites URL: <input type= "text" name="url" size"80">
<BR>
<input type="submit" value="Submit Your Link"> </form>
<BR>

<?php

if( $nn and $url and $lname and $sc # makeing sure fields are filled in
# connecting to Mysql
$conn=@mysql_connect"localhost""my username""my password" ) or die( "err:conn" );

#selecting Database

$rs = @mysql_select_db"linkdb"$conn ) or die( "err:conn" );

#create the query

$sql="insert into links (NN, sc, LName, URL) values ( $NN, \"$sc\", \"$LName\", \"$url\" )";

#execute the query

$rs mysql_query$sql$conn );

#confirm the added link

if($rs){ echo( "The Link $lname was Added To the $sc Database!" ); }
}

?>

</body></html>

PS.

i also tried it exactly the way you did it that did not work either..

Scott 05-28-2005 11:10 PM

<?=$value?> will only work one some php settings.. so it's best to use <?Echo($value);?>.. but for your problem I think it's the mysql query.. I made alot of notes to atholon in another thread please read that.. it can be found here. http://www.novahq.net/forum/showthre...threadid=26098

IcIshoot 05-28-2005 11:29 PM

I added an IF statment
PHP Code:

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

so that the data handling stuff doesn't take place unless data is actually being submitted.


When i ran this, every thing worked, except for the mysql part due to the fact I didn't want to set up a test table . I just commented it out and put echo statements to tell me what was happening.

Try this:

(again, I didn't test to see if the database part worked)

PHP Code:

<?php
  
echo "<html><head><title>Add Your Link</title></head> 
<body>"
;


$self $_SERVER['PHP_SELF']; 
$nn $_POST['nn']; 
$url $_POST['url']; 
$lname $_POST['lname']; 
$sc $_POST['sc']; 

echo 
'<form action="'.$self.'" method="post"> 
Your Nick Name: <input type="text" name="nn" size="25"> 
<BR> 
Your Websites Catagory: 
  <select size="1" name="sc"> 
  <option>Please Select</option> 
  <option>Delta Force Xtreme Resource</option> 
  <option>Joint Operations Escalation Resource</option> 
  <option>Joint Operations Resource</option> 
  <option>Delta Force Xtreme Squad</option> 
  <option>Joint Operations Escalation Squad</option> 
  <option>Joint Operations Squad</option> 
  </select> 
<BR> 
Your Websites Name: <input type="text" name="lname" size="80"> 
<BR> 
Your Websites URL: <input type= "text" name="url" size"80"> 
<BR> 
<input type="submit" value="Submit Your Link" name="submit"> </form> 
<BR>'
;

//Check to see if data is being submitted:
if (isset($_POST['submit'])) {
    
if( 
$nn and $url  and $lname  and $sc 
0
# makeing sure fields are filled in 

# connecting to Mysql 

$conn=@mysql_connect"localhost""my username""my password" ) or die( "err:conn" ); 

#selecting Database 

$rs = @mysql_select_db"linkdb"$conn ) or die( "err:conn"); 

#create the query 

$sql="insert into links (NN, sc, LName, URL) values ( $NN, \"$sc\", \"$LName\", \"$url\" )"

#execute the query 

$rs mysql_query$sql$conn ); 

#confirm the added link 

if($rs){ echo( "The Link $lname was Added To the $sc Database!" ); } else
{
    echo 
"Error submitting link $lname to the $sc Database";
}
}
 
 else
{
    echo 
"some of the fields were not entered in, please try again";
}
}
echo 
"</body></html>";
?>


General Nuisance 05-28-2005 11:35 PM

ok thx panther but i dont know what would be wrong with mysql... here is pic of phpmyadmin

[img] http://24.158.37.186/phpmyadmin.jpg [/img]

General Nuisance 05-28-2005 11:41 PM

Quote:

Originally posted by icishoot
I added an IF statment
PHP Code:

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

so that the data handling stuff doesn't take place unless data is actually being submitted.


When i ran this, every thing worked, except for the mysql part due to the fact I didn't want to set up a test table . I just commented it out and put echo statements to tell me what was happening.

Try this:

(php code removed to keep short.. -gen nuisance)



now that dont work at all for me the page will not even display...

IcIshoot 05-29-2005 02:43 AM

Ok, here is your script in action. I added some code to display the links, as proof that they were submitting to the database.

http://commandoselite.com/scripts/linksdb.php

Also, there is a link that you can click on to see the source code.

For some reason, the source code gets chopped off near the end, but that doesn't matter that section was added to display the links and source code.

every thing after line 73, just look for "Every thing after this line was added so that the links would be displayed, and so that you could view the source code." I added for the links and source code display.

Every thing above that line is your work, just edited where needed to make the script work.

You will have to edit the sql statements to reflect the database table your using. Same for mysql_select_db(), making sure it is selecting your database. And of course the mysql_connect() to reflect your username and passwords.

One thing I noticed though, is that you alternated capitals and lowercase letters for your variables.

That may have been why it wasn't working. Variables are case sensitive. $NN is different from $nn.

Any ways, hope this helps you :)

IcI

General Nuisance 05-29-2005 11:34 AM

COOL!! my script rocks... lol.. thanks ici...

i will find some way to add your name to te site... Thanks!

my contact info:

MSN: GeneralNuisance@gmail.com
Email: same as msn
ICQ: i dont know # but its in my profile...

JonM 05-29-2005 11:46 AM

:gj: gj bro ! I remember my first one to

IcIshoot 05-29-2005 12:50 PM

Make sure though that when you use it to take out the lines


echo '<br><br><a href="linksdb.php?show=source">Click here to see source code</a><br><br>';

++++++++++++++++

if (isset($_GET['show']) AND ($_GET['show'] == "source")){
echo DisplaySourceCode();
}

+++++++++++++++++++++++

function DisplaySourceCode()
{

$h = file_get_contents("linksdb.php");
return "<br><br><textarea cols=60 rows= 20>$h</textarea>";
}


Other wise visitors will be able to get your database username and password.

IcI

General Nuisance 05-29-2005 01:03 PM

ok i did... it works now! im making a link page now to get the mysql entries and post them on the page... will be one in a few min...

Thank you So Much ICIshot!

i will add your name to the site somewhere..

i will post when it is completely integrated in to The Nova-Zone so yall can test it out!

Edit--

:( :( i just got to thinking and looking at script... I DID NOT PUT IN DESCRIPTION!!! :( :( :( :(

thats ok is should be easy to add...

edit # 2 ---

i added the desciption box and it worked first try!

General Nuisance 05-29-2005 02:19 PM

what am i doing wrong?

this script dont work either.... :(

PHP Code:

<html><head><title>The Nova-Zone Link Database </title></head>
<body>

<?php

#connecting To mysql

$conn = @mysql_connect"localhost" "root" "5bk3hm2agn" ) or die( "Err:conn" );

#select the database

$rs = @mysql_select_db"linkdb"$conn ) or die( "err:db" ) ;

# create the query

$sql="select LName, URL, ld, sc from links";

# execute the query

$rs mysql_query$sql,$conn ) ;

#write the data

while( $row mysql_fetch_array$rs ) )
{
echo( 
"Category: " $row["sc"]
echo( 
"Site Name: " $row["LName"]
echo( 
"URL: " $row["URL"]
echo( 
" Site Description: " $row["ld"] ."<BR>");
}
?>
</body></html>

it is supposed to display the links that are submitted to the database..

JonM 05-29-2005 02:51 PM

well it seems to me to be those echo's...

IcIshoot 05-29-2005 03:56 PM

echo( "Category: " . $row["sc"]
echo( "Site Name: " . $row["LName"]
echo( "URL: " . $row["URL"]


those above lines don't have the ");" at the end.

Also, why are you doing "$rs = @mysql_select_db( "linkdb", $conn ) or die( "err:db" ) ;"?

putting the @ infront of mysql_select_db() (or any other function) suppresses the errors. You could be getting errors in the sql statements and not know it.

You should do some thing like "$rs = mysql_select_db( "linkdb", $conn ) or die( mysql_error() ) ;", that way you will recieve any errors and get an idea as to what you have to do to fix them. Same applies to mysql_connect(), mysql_query(), ect.


IcI

IcIshoot 05-29-2005 04:08 PM

Also, my msn: icishoot@yahoo.com
yahoo: icishoot

:)

IcI

General Nuisance 05-29-2005 05:35 PM

well the @ thing is because my book says to do so.

IcIshoot 05-29-2005 07:24 PM

lol, k.

JonM 05-29-2005 08:11 PM

yes, the book is a reference, a tutorial...doesn't mean you should code that way all the time... right now the @ isn't needed, infact it is need the @ is taken off. All the @ does is supress errors..

General Nuisance 05-31-2005 09:34 PM

2nd php script done!
 
hey great news!! icishoot and i got the Links Pages Done for the Nova-zone! check it out and submit your link!

http://www.nova-zone.com\links.php


All times are GMT -5. The time now is 06:55 AM.

Powered by vBulletin®