WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-10-2003, 02:50 PM
labrynth_of_fire's Avatar
WebProWorld Pro
 

Join Date: Nov 2003
Location: -_-
Posts: 187
labrynth_of_fire RepRank 0
Default I made this php script, and it doesnt seem to work

Ive tried everything i can, but the print command seems to not be working ^>_<^
<?php
$number=$_POST['number']
$name=$_POST['name'];
$email=$_POST['email'];
$comments=$_POST['comments'];
$to="sr71storm@charter.net";
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email";
if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo "you have chosen" $number"Thanks for your comments.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
$number="1";
if ($number =="1"){
print ("you have chosen 1st image");
}
elseif($number=="2"){
print("you have chosen 2nd image");
}
else($number=="3"){
print("you have chosen 3rd image");
}
?> see anything wrong with it?
i am using it on a form www.zultone.com/image_pick.html ,its just an idea i had to see if it would work but it doesnt seem to be working...
I want the user to type in a number, and that number brings up a certain image, and shows it to them and sends me an email about which one they picked, but its showing nothing....
__________________
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|- >(^_^)> | (t^^t) | <(^_^)< -|
- - - - - - - - - - - - - - - -
Reply With Quote
  #2 (permalink)  
Old 12-10-2003, 03:14 PM
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: Toronto, Canada
Posts: 2,193
cyanide RepRank 0
Default

Hi,

Try changing the extension of that page to .php instead of .html
php scripts won't run otherwise
__________________
|
Web Hosting Guru
| Need Help For Your Forum?
Reply With Quote
  #3 (permalink)  
Old 12-10-2003, 03:27 PM
labrynth_of_fire's Avatar
WebProWorld Pro
 

Join Date: Nov 2003
Location: -_-
Posts: 187
labrynth_of_fire RepRank 0
Default

do you mean save it as a .php instead of .html ? thats what i did...but when i first uploaded it , it was in binary, will that ruin the whole thing?
__________________
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|- >(^_^)> | (t^^t) | <(^_^)< -|
- - - - - - - - - - - - - - - -
Reply With Quote
  #4 (permalink)  
Old 12-10-2003, 05:35 PM
labrynth_of_fire's Avatar
WebProWorld Pro
 

Join Date: Nov 2003
Location: -_-
Posts: 187
labrynth_of_fire RepRank 0
Default

ive got another question about php, how do you make it where people can log in to your site, and make an account, and have profiles n such?
__________________
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|- >(^_^)> | (t^^t) | <(^_^)< -|
- - - - - - - - - - - - - - - -
Reply With Quote
  #5 (permalink)  
Old 12-10-2003, 06:56 PM
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: Toronto, Canada
Posts: 2,193
cyanide RepRank 0
Default

Quote:
Originally Posted by labrynth_of_fire
do you mean save it as a .php instead of .html ? thats what i did...but when i first uploaded it , it was in binary, will that ruin the whole thing?
Yes.
You can even just right-click and change name also.
The page won't be able to read your php script unless the php extension is there
Binary is for images, you should upload in ASCII
__________________
|
Web Hosting Guru
| Need Help For Your Forum?
Reply With Quote
  #6 (permalink)  
Old 12-10-2003, 06:59 PM
WebProWorld 1,000+ Club
 

Join Date: Jul 2003
Location: Toronto, Canada
Posts: 2,193
cyanide RepRank 0
Default

Quote:
Originally Posted by labrynth_of_fire
ive got another question about php, how do you make it where people can log in to your site, and make an account, and have profiles n such?
Well, you're talking about a whole new ball-game there.
Extensive knowledge of php and interaction with MySQL databse would be required.
You should check out some free scripts at hotscripts

Atleast it'll get you started in the right direction
__________________
|
Web Hosting Guru
| Need Help For Your Forum?
Reply With Quote
  #7 (permalink)  
Old 12-10-2003, 07:11 PM
labrynth_of_fire's Avatar
WebProWorld Pro
 

Join Date: Nov 2003
Location: -_-
Posts: 187
labrynth_of_fire RepRank 0
Default

thanks, its saved as image_show.php but still isnt working, ill fiddle with it some more, and thanks for that link!!
Could I use JavaScript with that to?
__________________
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|- >(^_^)> | (t^^t) | <(^_^)< -|
- - - - - - - - - - - - - - - -
Reply With Quote
  #8 (permalink)  
Old 12-10-2003, 07:58 PM
redcircle's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
redcircle RepRank 0
Default

It could be done in Javascript.

the first line
$number=$_POST['number']

does not have an ; at the end of the line. It's usually nice to post the error you are getting.
Reply With Quote
  #9 (permalink)  
Old 12-10-2003, 08:50 PM
labrynth_of_fire's Avatar
WebProWorld Pro
 

Join Date: Nov 2003
Location: -_-
Posts: 187
labrynth_of_fire RepRank 0
Default

thanks for pointing that out, it never said i had an error...all that happend was a blank page, and i should get an email but havent gotten any from it...
__________________
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|- >(^_^)> | (t^^t) | <(^_^)< -|
- - - - - - - - - - - - - - - -
Reply With Quote
  #10 (permalink)  
Old 12-12-2003, 12:45 PM
davebarnes's Avatar
WebProWorld MVP
WebProWorld MVP
 

Join Date: Jul 2003
Location: Denver, Colorado USA
Posts: 1,439
davebarnes RepRank 3davebarnes RepRank 3
Default

A better (in my opinion) place to ask this question is: www.phphelp.com
__________________
Dave Barnes
+1.303.744.9024
http://www.marketingtactics.com
Reply With Quote
  #11 (permalink)  
Old 12-14-2003, 01:54 AM
adposter's Avatar
WebProWorld Pro
 

Join Date: Aug 2003
Location: Canada
Posts: 103
adposter RepRank 0
Default Creating an account login

Quote:
Originally Posted by labrynth_of_fire
ive got another question about php, how do you make it where people can log in to your site, and make an account, and have profiles n such?
There's a lot of topic about creating your own login sessions but here's a basic one:

1.) create a mysql table called USERS, you can add more fields later as you wish:

create table users (
id int unsigned not null auto_increment,
userid varchar(24) not null,
password varchar(24) not null,
primary key(id));

2.) create your PHP script form. We'll call this script LOGIN.PHP

<?
// when the user click login button
if (isset($login))
{
// 1.) here is where you connect to your MYSQL db to access user id and password.
$dbname = "user_db"; // supposing you created a db user_db
@mysql_connect("0.0.0.0.0", "useruser", "passpass") or die(mysql_error());
@mysql_select_db($dbname) or die(mysql_error());

// 2.) Once connected you then run a query
$qry = "SELECT * FROM users where userid=\"$userid\" and password=\"$pass\"";
$res = mysql_query($qry) or die(mysql_errno().":".mysql_error());
$rows = mysql_num_rows($res);

if ($rows == 0)
print "ACCESS DENIED";
else {
// 3.) Once verified correct. You set the cookie by doing:
setcookie("userid", $userid, time()+3600); //1 HR

// 4.) then you can open the menu or whatever page the user wants to see...VIOLA!
print "Welcome $userid!!!!"; }
}
else
{
print "<form action=\"login.php\" method=\"post\">
User ID: <input type=\"text\"name=\"userid\" size=\"10\">

Password: <input type=\"password\"name=\"pass\" size=\"10\">



<input type=\"submit\" name=\"login\" value=\"Login\">
</form>
";
}
?>


This is a very very basic way to create a login screen, but i'm sure other members here might give you another better idea. There are lots of ways to create better ones, but because you're beginning PHP, I hope this one helps and easy to grasp.

Thanks,
Jon
__________________
I love adobo, afritada and emphanada....if you're Spanish or Filipino you know what I mean...
Reply With Quote
  #12 (permalink)  
Old 12-14-2003, 11:24 AM
labrynth_of_fire's Avatar
WebProWorld Pro
 

Join Date: Nov 2003
Location: -_-
Posts: 187
labrynth_of_fire RepRank 0
Default

oh wow, thank you!!
__________________
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|- >(^_^)> | (t^^t) | <(^_^)< -|
- - - - - - - - - - - - - - - -
Reply With Quote
  #13 (permalink)  
Old 12-14-2003, 01:57 PM
adposter's Avatar
WebProWorld Pro
 

Join Date: Aug 2003
Location: Canada
Posts: 103
adposter RepRank 0
Default no problemo...

Quote:
Originally Posted by labrynth_of_fire
oh wow, thank you!!
No problemo...
mind you, there's no error correction on these, like checking to see if user has typed anything in the fields, but I guess you know how to do that, so I won't bother writing it...i'll leave that up to you for the sake of learning it...

Let me know if it worked...

Jon
__________________
I love adobo, afritada and emphanada....if you're Spanish or Filipino you know what I mean...
Reply With Quote
  #14 (permalink)  
Old 12-14-2003, 03:55 PM
WebProWorld Veteran
 

Join Date: Jul 2003
Location: Spain
Posts: 335
computergenius RepRank 1
Default Re: I made this php script, and it doesnt seem to work

Quote:
Originally Posted by labrynth_of_fire
print ("you have chosen 1st image");

see anything wrong with it?
Apart from the fact that the page must have the extension .php insteadof .html, you have too many quotes. It should be
print ('you have chosen 1st image');
Notice that I have changed quotes 1 and 4 to single quotes.

You could have changed quotes 2 and 3 to single quotes instead, but this would have run very slightly slower.

And I don't like the if..else. I would have used a function (as the text is so similar), or a switch statement if the text is not likely to stay so similar.
__________________
Pete Clark
Advertise events locally in Spain for free - http://hotcosta.com/events.php
Reply With Quote
  #15 (permalink)  
Old 12-14-2003, 11:01 PM
redcircle's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
redcircle RepRank 0
Default

Quote:
Originally Posted by labrynth_of_fire
thanks for pointing that out, it never said i had an error...all that happend was a blank page, and i should get an email but havent gotten any from it...
Do you have error's truned on in the php.ini ?

Quote:
Originally Posted by adposter

1.) create a mysql table called USERS, you can add more fields later as you wish:

create table users (
id int unsigned not null auto_increment,
userid varchar(24) not null,
password varchar(24) not null,
primary key(id));

2.) create your PHP script form. We'll call this script LOGIN.PHP

<?
// when the user click login button
if (isset($login))
{
// 1.) here is where you connect to your MYSQL db to access user id and password.
$dbname = "user_db"; // supposing you created a db user_db
@mysql_connect("0.0.0.0.0", "useruser", "passpass") or die(mysql_error());
@mysql_select_db($dbname) or die(mysql_error());

// 2.) Once connected you then run a query
$qry = "SELECT * FROM users where userid=\"$userid\" and password=\"$pass\"";
$res = mysql_query($qry) or die(mysql_errno().":".mysql_error());
$rows = mysql_num_rows($res);

if ($rows == 0)
print "ACCESS DENIED";
else {
// 3.) Once verified correct. You set the cookie by doing:
setcookie("userid", $userid, time()+3600); //1 HR

// 4.) then you can open the menu or whatever page the user wants to see...VIOLA!
print "Welcome $userid!!!!"; }
}
else
{
print "<form action=\"login.php\" method=\"post\">
User ID: <input type=\"text\"name=\"userid\" size=\"10\">

Password: <input type=\"password\"name=\"pass\" size=\"10\">



<input type=\"submit\" name=\"login\" value=\"Login\">
</form>
";
}
?>
Somewhat correct but your method does not take into account that PHP default install has register_globals turned off. Posted variables should be $_POST['userid'] and $_PASS['pass']; For some optimizations I would first use single quotes opposed to double quotes. PHP looks for variables within the double quotes. using single quotes it doesn't. I would also add a limit at the end of the SQL statement so the script will stop after it finds the one result. Also because we are not using any information in the sql result we only need to select the primary index field from the record. These are just speed optimizations not necessary and really wouldn't have an effect on a small site. But what if there were 10,000 users. If it found 1 record after searching through the first 10 it doesn't need to look any more it has a valid result. Without the limit 1 with will continue on through the rest of the 10,000 which is wasting CPU. Best to start off learning the best way. Make it a habit to optimize not just get the job done.
Code:
$qry = 'SELECT id FROM users where userid="'.$_POST['userid'].'" and password="'.$_POST['pass'].'" limit 1';
$res = mysql_query($qry) or die(mysql_errno().":".mysql_error());
$rows = mysql_num_rows($res);
Reply With Quote
  #16 (permalink)  
Old 12-15-2003, 12:27 AM
adposter's Avatar
WebProWorld Pro
 

Join Date: Aug 2003
Location: Canada
Posts: 103
adposter RepRank 0
Default A basic script is basic script...

Quote:
Originally Posted by redcircle
Do you have error's truned on in the php.ini ?
My installation which is default as far as i'm concerned is okay with all errors turned on. Using PHP 4.3+. With regards to those minor details, I would've put them but because I was giving labyrinth_of_fire a basic script which he requested, he got what he asked.

I've tested the script and it worked on my system. Those minor details you've explained are for later use. Can't spoon feed. Thanks for the added info though. As for him since he's learning the basic stuff, it's all here. What he just needs to grasp is to get the basics of PHP.

Nevertheless, the comment is appreciated. Why complicate, when you can make it simple with results. And later on, optimize it. As I said to him earlier, there are better ways to do it, but he has the basic idea and he can learn from it.

Jon
__________________
I love adobo, afritada and emphanada....if you're Spanish or Filipino you know what I mean...
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0