need help to get this form working

hi

i have managed to do the form side with all the fields i want. but now
i am stuck on how to create the file that sends all the info filled in on the sign up
form into the database. can anyone help.

[php]

My Woopsy
    <link rel="stylesheet" href="css/style.css">

Register

[/php]

DJ, welcome back…

So, the form itself is just step #1 of many steps. Next, you need to pull the posted data. Then, you have to
“validate” the entries to make sure they are valid and to indicate ones that are “required” or “optional”. Then,
you can actually do the insert query to store the data.

Here is a great tutorial on all of these sections. Just press the green “Next-Chapter” button to walk thru each of
these steps.

Once you have a working script set up, let us know if you are having further questions. Hope this helps!
http://www.w3schools.com/php/php_forms.asp

One further note. You have the form page moving out to another PHP page to handle the data. Normally, you
would just have the form page posted to itself. In this way, you can show problems in the inputs right on the
same page. Once the data is validated and inserted into the database, you would redirect the page to the correct
secondary page such as a thank-you-for-registering page or a login page.

hi earniealex.

longtime since we spoke nice to here from you again.

this is what i have got so far.

mywoopsy.com = login page

http://mywoopsy.com/sign_up.html = register form

mysql file is added as attachment and also other files i managed to do.

http://mywoopsy.com/area.html = the area where they go once registered and logged in.

its a great start to say i did most this by myself.


net2ftp-1454256400.zip (3.45 KB)

just updated the register form to include countrys


sign_up.doc (94 KB)

just incase links above dont work ive attached the files


net2ftp-1454258136.zip (7.17 KB)

DJ, your files contain HTML and Javascript code. It contains no PHP code…

Do you want help using Javascript to save your data? It is better to use PHP as it is handled on the server not
in the browser. Code in the browser can be viewed by anyone and is NOT secure. The site I posted explains how
to use PHP to pull your data from your form, validate it so that the user’s inputs are safe and not hacking codes
and also shows you how to save the data to your database. Did you study any of that tutorial yet?

If you really want to learn, first study that tutorial and then post some of your problem areas and we will help
you solve it all. Otherwise, what do you need help with?

(*** EDIT: ***) Also, have you set up your database yet? You want to save data to it, just wondering if it is
all set up and ready to receive the data…

ive redone all the script but still get (error registering) on register.php

here is my login, register and db connection php any ideas.

(register.php)

[php]<?php
session_start();
if(isset($_SESSION[‘user’])!="")
{
header(“Location: area.php”);
}
include_once ‘dbconnect.php’;

if(isset($_POST[‘btn-signup’]))
{
$uname = mysql_real_escape_string($_POST[‘uname’]);
$email = mysql_real_escape_string($_POST[‘email’]);
$upass = md5(mysql_real_escape_string($_POST[‘pass’]));

if(mysql_query(“INSERT INTO users(username,email,password) VALUES(’$uname’,’$email’,’$upass’)”))

{
?>

<?php
}
else
{
?>

<?php
}
}
?>

Registration mywoopsy mywoopsy
    <link rel="stylesheet" href="css/style.css">
<?php include_once("template_pageTop.php"); ?>

Register

Sign Me Up
Sign In Here

mywoopsy

[/php]

(index.php)

[php]<?php
session_start();
include_once ‘dbconnect.php’;

if(isset($_SESSION[‘user’])!="")
{
header(“Location: area.php”);
}
if(isset($_POST[‘btn-login’]))
{
$email = mysql_real_escape_string($_POST[‘email’]);
$upass = mysql_real_escape_string($_POST[‘pass’]);
$res=mysql_query(“SELECT * FROM users WHERE email=’$email’”);
$row=mysql_fetch_array($res);
if($row[‘password’]==md5($upass))
{
$_SESSION[‘user’] = $row[‘user_id’];
header(“Location: area.php”);
}
else
{
?>

<?php
}

}
?>

My Woopsy

#loginform{
margin-top:24px;
}
#loginform > div {
margin-top: 12px;
}
#loginform > input {
width: 200px;
padding: 3px;
background: #F3F9DD;
}
#loginbtn {
font-size:15px;
padding: 10px;
}

</head>
<img src="images/logo.gif" alt="mywoopsy">
    <img src="images/logo.gif" alt="mywoopsy" align="right">

 <body><center>
<div class="login">
	<div class="login-screen">
		<div class="app-title">
			<h1>Login</h1>

Sign In

Register

		</div>
	</div>
</div>

mywoopsy

<?php include_once("template_pageBottom.php"); ?> [/php]

(dbconnect.php)

[php]<?php
error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE );
if(!mysql_connect(“localhost”,“root”,“pw”))
{
die('oops connection problem ! --> '.mysql_error());
}
if(!mysql_select_db(“db”))
{
die('oops database selection problem ! --> '.mysql_error());
}

?>[/php]

ive got to be close now.

This line is odd:
if(isset($_SESSION[‘user’])!="")
Normally, I use
if(isset($_SESSION[‘user’]) && $_SESSION[‘user’]!="")

That version checks if the session variable is set AND if it is not set to nothing. In it’s current version it creates
a “boolean” value with the isset() function then, compare the “boolean” true/false (1/0) to the the !="" and that
is oddly formed.

Also, MySQL is deprecated now. It was replaced with MySQLi and you should upgrade to it. The others on this
site will push you to upgrade to PDO which protects your server better than MySQLi. PDO is a bit more tricky to
learn than MySQLi. MySQLi is a simple change. If you can’t figure that out, we can help you here…

i changed the 2 lines you sudgested but still error while registering on registering page and wrong details on login page

i got it working yayyyy

DJ, good for you ! Always a nice exciting feeling to solve a programming puzzle ! ! !

Now, just to add to your knowledge, one way to test a project or actually to debug one is to add in debugging
code at various points in your code. If you are getting errors early in the process, such as inputs are failing, you
can add in break-points to show you data. (Of course, you need to do that when testing before it is live!) To do
this, just add a line like: die("Got to this point, data is: " . $input-variable-name); What this would do is kill
the code at that point and display the variable’s data so you can track what is being sent to the code. You can
put this at one point in the process and if it shows the correct data, just move it down the code and change the
name of the variable to the next section, etc… While doing that, you can see how your code is progressing and
you can find where it is dying. You can also print arrays like this: print_r($array-name-here);

Well, just more ammo for your programming knowledge… I will mark this one solved! See you in the next
thread…

OP, using MD5 for your password is just plain bad. It was hacked like 100 years ago. Your Mysql code is deprecated and will not work at all in the current version of Php. You need to use PDO with prepared statements. Testing for a button name for your script run will completely fail under certain circumstances.

Your code is no good.

Kevin, I already told him he needs to move up to MySQLi. I have talked with DJ many times before and he is a
newbie and needs help, not people telling him his code is no good. Steer him step by step, help him. Please do
not just make comment about having bad code. The reason he is here is to learn. Please either help or don’t
leave a comment at all. You have no patience with newbies and perhaps should be spending time on another
site that has more experienced posters, like GitHub or StackOverflow? Just an idea that might help your level
of patience with newbies… This site is more of a one-on-one site for experts like Kevin and newbies like DJ !

DJ, we have talked several times about not using MySQL and moving up to MySQLi. And, yes, PDO is even much
better for many reason that Kevin does not want to explain to you. PDO has a lot of built in handling that helps
keep out hackers. The data handling processes data in a better way to protect it from hackers injecting code that
can damage or delete your database. PDO also has several nice ways to automate your insert’s and update’s
in your database. A really nice thing with PDO you can fetch the data and inject it into an object automatically
which is great. The objects can be complete data object which makes a lot of object-orientated display much
easier to use. (Of course, Kevin, DJ does not understand any of this!) The PDO API is a little more intuitive in
some ways and it is more object oriented. Where MySQLi is like it is just a procedural API which can be made
to use objects. For experienced programmers, PDO is the only way to go. Hard to follow unless you really do
understand object-orientated programming. MySQLi, being procedural orientated is perfect for beginners to use
and learn with. DJ, I think you need to upgrade to MySQLi and once you understand all of it, then move up to
PDO. Just in my humble opinion!

You know [member=43746]ErnieAlex[/member], if you made that post in the first place I wouldn’t have had to say anything in the second place and you still didn’t say a word to the op about using MD5.

How is helping someone learn bad code helping anyone? The web is full of unlimited resources for learning. If I choose not to write a book in my replies that is up to me. You can spoon feed the OP’s if you want. I think they should take some effort and learn on their own once something has been pointed out to them. Google is only a click away.

And I dont just tell people to use PDO. I took the time to write and provide for free a PDO Bumpstart Database for people to learn from so there is no excuse for anyone still using deprecated code 10+ years later.

I’m guilty of just telling beginners that their code is obsolete or depreciated in the past and I try to have patience with people learning PHP (or new programming language). I get mad at all the old websites that are out there on web that people don’t maintain. >:( Either take that website down or update the material that is on there! Then there are those who keep using depreciated mysql_ statements on their websites thinking they are helping newbies when instead they are doing the complete opposite. They are worse than people who don’t update their aging websites, for they should know better. That is why I say newbies should buy the latest edition of PHP Help book that will at least show them what they should be using at the vary minimum.

A person who is learning PHP for the first time should also be aware of websites that haven’t been updated in a long time. Most websites will have a date the tutorial was written, I say anything older that 2 years should be scrutinized and anything over 5 years shouldn’t even be considered unless it’s very basic PHP with no database or security scripting. A good tutorial website will have a comment section that can also give you an indication if the tutorial is any good. If you see a lot of comments that say “Hey, I can’t get the script to work properly” that is a great big red flag that maybe the tutorial isn’t any good. If you don’t see any current comments on the tutorial that might also be an indicator that the tutorial is outdated. Just my .02 cents on the matter.

Yes, first, thanks for your 2 cents… Any opinion is always great on this site!

Next, yes, I agree 100% that people should learn with the newer PHP coding. For newbies, procedural MySQLi
is much easier to learn than object orientated PDO. Either will work and, yes, it is better to learn PDO, but, it is
not what is happening in the world. Teachers and online tutorials seem to push MySQLi. Perhaps it is easier to
teach procedural to newbies? Not my call there! But, it is still not good to say that, in this instance, MD5 is bad
and not explain what is better to use, but to instead say that the newbie’s code is bad. Just not fair to the
person learning. That was all that I was saying.

As far as the MD5 or SHA1 or SHA256 or any other password encryption being out of date, here is a link to the
PHP manual on how to use the current standard, from PHP.net’s viewpoint, on how to handle it all. This is for
DJ to review to update his MD5… Hope this helps, DJ…
http://php.net/manual/en/function.password-hash.php

thanks for the help so far. yes i am very excited about get something a stupid as a login and register script working be it old or new code. ive learnt so much including how to make loads of tea in between giving the laptop a good shouting at lol. Anyway on to the next stage which of cause would be turning mysql in to mysqli. is it has simple as replacing mysql to mysqli on all php scripts like i read on one site cause that sounds to easy. it is very important to remember that i like you once was am a beginner. a lot of people forgot that once they was a beginner and had no idea what they was doing apart from reading a file with a load of ode only aliens could make sense of. even cold code is still learning. ok not ideal but for me has a newbie is still a great feel of accomplishment.basically you need to have patients with newbies cause shouting and loosing your temper is not going to learn them anything they would just ignore you instead of them been able to pass on the lesons you have learnt them.

DJ, it is very easy to upgrade to MySQLi… It is just a slight bit different. The main difference is that you need to
include the connection string in each of the commands.
So, mysql_query($query) becomes $mysql_query($conn, $query) Basically the same…
(Edit: So, mysql_query($query) becomes $mysqli_query($conn, $query) Basically the same… )

Here is a link that walks you thru connections to the database and a couple commands so you can see how it
all looks. http://www.w3schools.com/php/php_mysql_connect.asp
( That tutorial has a nice explanation of MySQLi both object and procedural versions and also PDO. Just click
the green “Next-Chapter” to walk thru how to use it to create databases, read them, etc… Should help a lot! )

And, here is a nice list of all of the functions you can use MySQLi with and you can click on the ones you need
help with to show you how they work. Hope that helps!
http://www.w3schools.com/php/php_ref_mysqli.asp

So, mysql_query($query) becomes $mysql_query($conn, $query) Basically the same...

Wrong.

So instead of just saying it is wrong so I dont get any more heat, OP the correct would be become $mysqli_query($conn, $query) because all the mysqli functions have an ‘i’ immediately after the “mysql” part. So it would be mysqli_function_name for all the Mysqli Functions.

If you dont put the required ‘i’ your code will break because thats how the makers of Php have decided it should work.

You can see a list of the Mysqli functions in the Php manual at http://php.net/manual/en/book.mysqli.php

The previous reference provided is an incomplete list of the mysqli functions.

Sponsor our Newsletter | Privacy Policy | Terms of Service