Jump to content


Photo

Uploading & Viewing PHP Site


  • Please log in to reply
3 replies to this topic

#1 dewbie

dewbie
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 09 May 2006 - 02:10 PM

I have decided that its about time I got up to speed with PHP.

I'm using my PlusNet account for hosting and for the MySQL database (which I created using phpmyadmin)

I am trying to create a v.simple login site just to get used to working with the code etc..

I have created a database: dewbie_pn

I have created a table: members

In this table I have: Id, username, password. I have put in 3 users details.

------------------------------------------------------------------------------------

Now, my problem is getting these pages on the net so they work!!

I've tried uploading them to my usual ftp.plus.net account, whenever I try to open main_login.php it askes if I want to save the file to disc instead of opening the page.

I tried uploading it to my cshell.plus.net and ccgi.plus.net parts of my web space, and for this I just get an error message (You don't have permission to access / on this server.)

Now this is really nooby of me, but what am I doing wrong?!

------------------------------------------------------------------------------------

Here is a list of the code for the 3 pages.

main_login.php
(this is a login page where the 3 users I have created login with their usernam and password)

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

This goes to this page..

checklogin.php
(checks the login details against the database)

<?php
$host="humbug"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="dewbie_pn"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>

If it matches, it goes to this final page...

login_successful.php
(displays a page saying "Successfuly Logged In"

// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.
<?
session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 09 May 2006 - 02:56 PM

If its asking you if you want to download the files then its either in the wrong location or your host doesn't support php.

Surely your host provides instructions on where to upload php files too?

#3 dewbie

dewbie
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 11 May 2006 - 08:09 AM

Update on my problem...

PlusNet told me that I do need to put it on my ccgi.plus.net space, so I did, then I realised it wasn't workign as I had put it in the cgi bin folder, I moved it from there into the main directory and got this error message:

[img src=\"http://img506.imageshack.us/img506/5639/php39um.jpg\" border=\"0\" alt=\"IPB Image\" /]

I then tried loading it onto the KK space, just to see if it worked, and it did! However, I have problems with this bit if anyone can help me... also ideas why it isnt working on my plusnet space when it does on KK's, even though PlusNet claim that their ccgi supports PHP.. maybe they dont have PHP installed on my ccgi space?!

This is the bit of code that is wrong, I need to know what to put in for $host as it doesnt seem to like ccgi.plus.net ot humbug..

[!--coloro:red--][span style=\"color:red\"][!--/coloro--]$host="humbug"; // Host name[!--colorc--][/span][!--/colorc--]
$username="dewbie"; // Mysql username
$password="2fbe8e1fefb41176"; // Mysql password
$db_name="dewbie_pn"; // Database name
$tbl_name="members"; // Table name

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 11 May 2006 - 08:36 AM

99.999% of the time the host should be 'localhost'

$host="localhost"; // Host name

put it in just like that.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users