 |

12-10-2003, 02:50 PM
|
 |
WebProWorld Pro
|
|
Join Date: Nov 2003
Location: -_-
Posts: 187
|
|
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) | <(^_^)< -|
- - - - - - - - - - - - - - - -
|

12-10-2003, 03:14 PM
|
|
WebProWorld 1,000+ Club
|
|
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 2,193
|
|
Hi,
Try changing the extension of that page to .php instead of .html
php scripts won't run otherwise
|

12-10-2003, 03:27 PM
|
 |
WebProWorld Pro
|
|
Join Date: Nov 2003
Location: -_-
Posts: 187
|
|
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) | <(^_^)< -|
- - - - - - - - - - - - - - - -
|

12-10-2003, 05:35 PM
|
 |
WebProWorld Pro
|
|
Join Date: Nov 2003
Location: -_-
Posts: 187
|
|
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) | <(^_^)< -|
- - - - - - - - - - - - - - - -
|

12-10-2003, 06:56 PM
|
|
WebProWorld 1,000+ Club
|
|
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 2,193
|
|
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
|

12-10-2003, 06:59 PM
|
|
WebProWorld 1,000+ Club
|
|
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 2,193
|
|
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
|

12-10-2003, 07:11 PM
|
 |
WebProWorld Pro
|
|
Join Date: Nov 2003
Location: -_-
Posts: 187
|
|
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) | <(^_^)< -|
- - - - - - - - - - - - - - - -
|

12-10-2003, 07:58 PM
|
 |
WebProWorld Veteran
|
|
Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
|
|
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.
|

12-10-2003, 08:50 PM
|
 |
WebProWorld Pro
|
|
Join Date: Nov 2003
Location: -_-
Posts: 187
|
|
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) | <(^_^)< -|
- - - - - - - - - - - - - - - -
|

12-12-2003, 12:45 PM
|
 |
WebProWorld MVP
|
|
Join Date: Jul 2003
Location: Denver, Colorado USA
Posts: 1,437
|
|
A better (in my opinion) place to ask this question is: www.phphelp.com
|

12-14-2003, 01:54 AM
|
 |
WebProWorld Pro
|
|
Join Date: Aug 2003
Location: Canada
Posts: 103
|
|
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...
|

12-14-2003, 11:24 AM
|
 |
WebProWorld Pro
|
|
Join Date: Nov 2003
Location: -_-
Posts: 187
|
|
oh wow, thank you!!
__________________
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|- >(^_^)> | (t^^t) | <(^_^)< -|
- - - - - - - - - - - - - - - -
|

12-14-2003, 01:57 PM
|
 |
WebProWorld Pro
|
|
Join Date: Aug 2003
Location: Canada
Posts: 103
|
|
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...
|

12-14-2003, 03:55 PM
|
|
WebProWorld Veteran
|
|
Join Date: Jul 2003
Location: Spain
Posts: 335
|
|
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.
|

12-14-2003, 11:01 PM
|
 |
WebProWorld Veteran
|
|
Join Date: Aug 2003
Location: Grand Rapids, MI USA
Posts: 553
|
|
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);
|

12-15-2003, 12:27 AM
|
 |
WebProWorld Pro
|
|
Join Date: Aug 2003
Location: Canada
Posts: 103
|
|
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...
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|