# Web development - Beginner help plz!



## r3drock3t88 (Jan 13, 2007)

Hey all, 

First off, thanks for takin a look at the thread! I'm in need of some help.

I've always been curious as to how a website such as ebay.com is developed. What is involved in creating a website like that. What kind of hosting do you need and all of that good stuff.

Also, I was wondering if anyone could help a beginner get started in the right direction. I want to build a website, not necessarily as advanced as ebay, clearly  but I am interested in learning. Thank you all in advance!!


----------



## AbvAvgUser (Oct 3, 2002)

For something like ebay, you will at least need a cluster of dedicated servers.

However, if you want to start on a smaller note, you can use shared hosting and OSCommerce from http://www.oscommerce.com 

There are a few more of such e-commerce scripts available.


----------



## r3drock3t88 (Jan 13, 2007)

Thanks a lot, I will definitely be checking that site out.

Is there anyway someone might be able to explain to me how to setup a login area on a website so the user can login and it connects to the MySQL database? I have been trying for a while now and still cannot grasp the concept as to how this all works out.

Any help is much appreciated! thank you!


----------



## MMJ (Oct 15, 2006)

Plenty of ways.

http://www.google.com/search?q=php+login


----------



## r3drock3t88 (Jan 13, 2007)

lol yeah... that shows me the script but not necessarily how to set it up / connect it to the mysql database.

I don't know how to setup the database which is mainly my problem here.


----------



## MMJ (Oct 15, 2006)

Can you be more descriptive? 

Do you mean you don't know how to install the db or don't know how to connect to it or what?


----------



## r3drock3t88 (Jan 13, 2007)

Well, I guess a bit of both.

Heres my scenario...

I don't have a webhosting plan or any of that. I am using dreamweaver to develop my website and what I'd really like to have in there is a "Registration" section, a "Login" section, and a "My Account" section.

I am confused as to how to set these up on my website. I know that I need a database to store the information, but could anyone possibly walk me through how one would go about doing this?


----------



## MMJ (Oct 15, 2006)

Download and install AppServ, the link is in my sig.


----------



## lightnb (Jun 16, 2002)

To register users, you'll need to start with a form of some sort, to get the information out of them. ie:


```
<?PHP

function form_generator()
{

$output = "
User ID:
Password:
Confirm Password:

";

return $output;

}

// And then you'll need to construct a SQL query from the input they provide, such as:

if ($HTTP_POST_VARS['submit'] == 'register') // If the form has been submited
{
$username = $HTTP_POST_VARS['username'];
$password = $HTTP_POST_VARS['password'];
$password2 = $HTTP_POST_VARS['password2'];

if($password == $password2) // if the passwords match NOTE: You should do A LOT more validation than this on a production server!!
{
$query = "INSERT INTO Users username, password VALUES ('$username', '$password')";
$result = safe_query($query); // insert into the database
}
else // passwords don't match
{
echo "Those Paswords don't match";
$form = form_generator(); //regenerate the form
echo $form; //  redisplay it
}
}
else //the form has not been submited
{
$form = form_generator();
echo $form;
}

?>
```
EDIT: By the way, I just coded that from scratch, so there may be typos. vB isn't my text editor of choice...


----------



## r3drock3t88 (Jan 13, 2007)

Woo, thanks a lot for that man! I appreciate it...seems as if it has everything I'll need. However, I'm a little lost on the installation / use part of it all.

I seemed to have installed it all correctly, but I'm not so sure how to use it? Sorry if im being a bit repititious, just trying to get the most out of it!

Any help is appreciated, thank you in advance!


----------



## lightnb (Jun 16, 2002)

Do you have a web sever setup yet? In order to run this script, you'll need a webserver running Linux. This usually costs $5/month.

Once you have your site, create a new file in Dreamweaver called "register.php" Be sure you end the file with '.php' so that the server knows it's a script.

Modify the PHP code as needed. Right now, it only takes username and password, and doesn't validate that the data is acurate.

Upload the file using Dreamweaver or an FTP program.

Contact your new webhost, and get the address for PHPmyAdmin. This will let you create databases and tables in MySQL. Once you have your database, create a new table called 'users' with the fields 'users_KEY' 'username' 'password', and anything else you want to store. Set 'users_KEY' to INT 255, auto-Increment, and primary key. The others can be VARCHAR 255. If this doesn't make sense now, you will see what I mean when you open PHPmyAdmin.

You will also need to connect to to the database using your username and password, provided by your host.


----------



## r3drock3t88 (Jan 13, 2007)

I stumbled upon this website ... http://www.siteground.com/hosting_features.htm

The hosting plan seems really good for the price they offer, anyone care to take a looksy?

And yes I've messed around with MySQL databases and PHPMyAdmin using freehostia.com. I've set up a table and all that good stuff, my trouble is just connecting the database to my php code i have running through dreamweaver. I'm guessing somewhere in that code i need it to relay the information to the database using the server host, username and password of mysql.

ahh i hate being a beginner! Things like this are so hard to figure out at first lol. Thank you all for the help!


----------



## lightnb (Jun 16, 2002)

r3drock3t88 said:


> seems as if it has everything I'll need.


All that script will do is add users to the database. And it's actually an oversimplified version at that. To complete it, you will need to define the function "safe_query" which connects to the database, and add more validation.

Also, there's nothing stoping me from entering:


```
<script type='text/javascript'>alert("Your Ugly!");</script>
```
into the username field (which will display an Alert message telling your users that they are ugly), or any other nasty or malicious code. You really need to use a striptags function, etc. to prevent that.

It should also maintain the values that are already filled in on a page reload (if an erro occurs), instead of emptying and making the user start over..


----------



## lightnb (Jun 16, 2002)

r3drock3t88 said:


> I'm guessing somewhere in that code i need it to relay the information to the database using the server host, username and password of mysql.


Yup.

Create a file called SQL_connect.php that looks like this:


```
// Conect to the Database

$conn = mysql_connect("localhost", "your_username", "your_password")
or die ("I've failed you master: " . mysql_error());

// Select the Database

mysql_select_db("database name");

function safe_query ($query="")
	{
	global $verbose_death;

	if ($verbose_death == true)
		{
  		echo "$query";
 		$result = FALSE;
  		if (!empty($query))
  			{
    		$result = @mysql_query($query);
  			if (!$result)
  				{
    	 		echo "I've Failed You:";
     			echo "Script Name: " . $_SERVER['PHP_SELF'];
    			echo "Include File: " . __FILE__;
      		echo "errorno=" . mysql_errno();
      		echo "error="   . mysql_error();
      		echo "query= "  . $query;
      		echo "";
     			print_r(debug_backtrace());
     			echo "";
     			exit;
    			}
  			}
  		}
  		else
  		{
  		$result = FALSE;
  		if (!empty($query))
  			{
    		$result = @mysql_query($query);
    		}
    	}

  		return $result;
	}
```
then in "register.php"

include it on the next line after the "<?PHP", like:


```
require('SQL_connect.php');
```


----------



## lightnb (Jun 16, 2002)

I'm using navigatoris for hosting my test site.

I only use my account for testing, so I can't say how they are under 'load', but I'm happy with them for my purposes.


----------



## AbvAvgUser (Oct 3, 2002)

You don't really need to sign-up for a hosting account to test out PHP+MySQL code. Have a look at XAMPP. :up:

This will install Apache, PHP, MySQL and phpMyadmin in your machine. Just start the servers by double clicking on the right files, place your code at the right place. Then you can check all your code even without a net connection  All information is there in their readme file.

Anyway, if you ever need to test it out in a real hosting account, you can always contact me for a demo account


----------



## r3drock3t88 (Jan 13, 2007)

AbvAvgUser said:


> You don't really need to sign-up for a hosting account to test out PHP+MySQL code. Have a look at XAMPP. :up:
> 
> This will install Apache, PHP, MySQL and phpMyadmin in your machine. Just start the servers by double clicking on the right files, place your code at the right place. Then you can check all your code even without a net connection  All information is there in their readme file.
> 
> Anyway, if you ever need to test it out in a real hosting account, you can always contact me for a demo account


Thanks a lot for the generosity! I really appreciate it. I'll be taking a look at the XAMPP in a couple of minutes, and try to get that up and running. Thank you all again for the responses, I really do appreciate it! I just need to get the understanding of how it all relates to each other and what not.


----------



## MMJ (Oct 15, 2006)

MMJ said:


> Download and install AppServ, the link is in my sig.


Much like XAMMP, installs Apache, mysq, php, phpmyadmin, and is much easier to use for the beginner.


----------



## r3drock3t88 (Jan 13, 2007)

Yeah, XAMPP Seems to be real easy to use, but I keep getting an error whenever I click any links that are on the pregenerated local host website. For example when I load up phpMyAdmin my apache server generates an error saying it must close. Then I lost connection to the local host. :-/ nothing ever works! lol, if anyone knows why this might happen let me know, thank you very much!


----------



## MMJ (Oct 15, 2006)

Remove it, try appserv.


----------



## r3drock3t88 (Jan 13, 2007)

Alright well I have appserv installed... Just not so sure how to use it / set it up :-/ if you have time to then awesome! if not thats okay to youve all been very helpful so far!


----------



## MMJ (Oct 15, 2006)

Type in *http://localhost * in the browser. What do you see?

I hope you removed XAMMP, there could be some conflicting if you haven't.


----------



## r3drock3t88 (Jan 13, 2007)

yeah i made sure i removed it before hand, when i type http://localhost i get a webpage saying " The AppServ Open Project - 2.5.8 for Windows at the top and then says stuff like ...

About AppServ Version 2.5.8 for Windows
AppServ is a merging open source software installer package for Windows includes :

# Apache Web Server Version 2.2.4
# PHP Script Language Version 5.2.1
# MySQL Database Version 5.0.27
# phpMyAdmin Database Manager Version 2.9.2

I don't really understand what the program does after you install it. I went into C:\AppServ folder and I see all of the installed files but I don't know what I need to with them to begin editing?


----------



## MMJ (Oct 15, 2006)

What appserv (and xammp) does is install apache, mysql, and php.

So basically you are a web server. You can run php scripts and store store stuff in a db.

What were you expecting?


----------



## r3drock3t88 (Jan 13, 2007)

Well, thats exactly what I was expecting lol, I just don't know how to use it. How do I go about storing things in the database? And how do I view my database through phpMyAdmin? And also can I create the designs in dreamweaver? If so where do I save my .html and .php files in order to be able to type say... http://localhost/index.html and have my homepage show up?

Thanks again I really appreciate it, I realize I'm probably being a little repititious but I really want an understanding as to how to work all of this. Thanks for your patience!


----------



## MMJ (Oct 15, 2006)

Place scripts and whatnot in *C:\AppServ\www*. You should probably remove the current index.php.

To use phpMyAdmin go to *http://localhost/phpmyadmin/*

To insert data into the db you'll probably have to use a script. The login script above uses a db.


----------



## r3drock3t88 (Jan 13, 2007)

Hmm, when I typed http://localhost/phpmyadmin in the URL the first time I got a message box prompting me for user name and password. I didn't know it at first so I took a wild guess with username "root" and no password. This brought me to a screen saying phpMyAdmin - error #2003 - The server is not responding

Any ideas why?

**EDIT --- I figured out what I was doing wrong, but yet again I have stumbled upon another error! >: | This also happened when I used xampp. When I would log into the phpmyadmin an error would occur and the server would be forced to shutdown. Then the connection to the local host is lost and I cannot do anything. :-/ any idea why? Thanks!

Idk if this could be where the problem occurs? When I ran the mySQL stop batch program i got this message in cmd

####### Stop MySQL Daemon #######

bin\mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to MySQL server on 'localhost' (10061)'
Check that mysqld is running on localhost and that the port is 3306.
You can check this by doing 'telnet localhost 3306'

So I did what it said and go this...

C:\>telnet localhost 3306
Connecting To localhost...Could not open a connection to host on port 3306 : Con
nect failed

Also when i double click the mySQL start batch program a CMD prompt pops up for a second then goes away, does this signify its starting? Or is this some sort of problem as well...


----------



## r3drock3t88 (Jan 13, 2007)

Here is a picture of the error I recieve when I load the http://localhost/phpmyadmin file...










httpd.exe stops working ... is there some sort of configuration i need to do that I didn't do?

All I've done is directly after installing the software i went to the c:\appserv folder and started up apachestart.bat and mysqlstart.bat ... thats it, didn't change any configuration settings so I don't know if I'm supposed to or not?


----------



## MMJ (Oct 15, 2006)

Go to Run>services.msc

Look for *Apache2.2* and *mysql*

Are they turned on? If not try turning them on.


----------



## r3drock3t88 (Jan 13, 2007)

Yes sir they are both on and running. They are set to startup automatically. Hmm ... pretty strange. Any other ideas??


----------



## MMJ (Oct 15, 2006)

During the appserv setup it should have asked you for the password for root. What did you type in?

Can you take some screenshots of the errors?


----------



## r3drock3t88 (Jan 13, 2007)

MMJ said:


> During the appserv setup it should have asked you for the password for root. What did you type in?
> 
> Can you take some screenshots of the errors?


I took a screen shot and posted it in a previous post, heres the link to it just incase you didn't see it or it for some reason wont show.

http://i2.photobucket.com/albums/y5/r3drock3t88/error.jpg

And the password is my private password so I don't feel comfterble posting, but I know for sure what it is.

I can successfully load http://localhost with no problems, but it's when I load http://localhost/phpmyadmin that the error occurs.


----------



## MMJ (Oct 15, 2006)

Uninstall it, restart, install it again.

You shouldn't have to run any .bat files or anything else.

try a php script and see if it compiles.


----------



## r3drock3t88 (Jan 13, 2007)

MMJ said:


> Uninstall it, restart, install it again.
> 
> You shouldn't have to run any .bat files or anything else.
> 
> try a php script and see if it compiles.


The only reason I ran any .bat files was because the error would occur and the server would shut down. When I ran the .bat file it would work again until I went to the phpmyadmin section, then yet again it would shut down.

What do you mean run a php script? load it through the http://localhost/test.php or was there something else?


----------



## MMJ (Oct 15, 2006)

Never mind.

So lets go over this again.

You removed Xammp, the apache & mysql services are running, php scripts are compiling. But you get errors when you open phpmyadmin.

Correct?


----------



## r3drock3t88 (Jan 13, 2007)

MMJ said:


> Never mind.
> 
> So lets go over this again.
> 
> ...


Yes, 100% correct. Even before I installed Xammp I recieved the error, then I switched to Xammp to see if the error continued to occur and it did. In Xammp the error I got said "apache.exe has generated errors and must close" and for the appserv the error says "httpd.exe has generated errors and must close".

What I did at the beginning of all of this was install appserv to c:\appserv and then it said "would you like to run apache and mysql now" and I hit yes at the end of the installation. I then loaded firefox and typed "http://localhost" and the page loaded up. That worked perfectly fine. Nothing goes wrong until I attempt to load the phpmyadmin via "http://localhost/phpmyadmin" ... that is when the server seems to shut itself down. At this point I cannot even load "http://localhost" unless I restart my apache server.

Thats the summary of whats going on. By the way! Happy Easter to you!


----------

