6 Replies - 1227 Views - Last Post: 19 April 2010 - 06:29 PM Rate Topic: -----

#1 nick1200   User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

my first ever register script error ?

Posted 18 April 2010 - 05:36 AM

i thought id have ago at making a register script by my self
but for some odd reason its adding the username ip password to the database but not the two drop down's menu's

here's my code

My form
<form action="register.php" method="post">
			<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
				<tr>
					<td width="100%"><h5>Registration</h5></td>
				</tr>
				<tr>
					<td width="100%"><label>Desired Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
				</tr>
				<tr>
					<td width="100%"><label>First Name: <input type="text" name="firstname" size="25" value="<? echo $_POST[firstname]; ?>"></label></td>
				</tr>
				<tr>
					<td width="100%"><label>Last Name: <input type="text" name="lastname" size="25" value="<? echo $_POST[lastname]; ?>"></label></td>
				</tr>
				<tr>
					<td width="100%"><label>Password: <input type="password" name="password" size="25" value="<? echo $_POST[password]; ?>"></label></td>
				</tr>
				<tr>
					<td width="100%"><label>Verify Password: <input type="password" name="password2" size="25" value=""></label></td>
				</tr>
				
				<tr>
					<td width="100%"><label>Gender: <select name="gender" value="<? echo $_POST[gender]; ?>">
<option value="Boy">Boy</option>
<option value="Girl">Girl</option>

</select>

</label></td>
				</tr>
				
				<tr>
					<td width="100%"><label>Starter Pokemon: <select name="starter" value="<? echo $_POST[starter]; ?>">
<option value="poke1">poke1</option>
<option value="poke2">poke2</option>

</select</label></td>
				</tr>
				<tr>
					<td width="100%"><input type="submit" value="Register!"></td>
				</tr>
			</table>
		</form>



my sql

<?php

// Check if he wants to register:
if (!empty($_POST[username]))
{
	// Check if passwords match.
	if ($_POST[password] != $_POST[password2])
		exit("Error - Passwords don't match. Please go back and try again.");

	// Assign some variables.
	$ip = $_SERVER[REMOTE_ADDR];

	require_once("connect.php");

	// Register him.
	$query = mysql_query("INSERT INTO members 
	(username, firstname, lastname, password, date, ip, gender, poke1)
	VALUES	('$_POST[username]','$_POST[firstname]','$_POST[lastname]','$_POST[password]','$date','$ip','$gender','$starter')")
	or die ("Error - Couldn't register user.");
	
	echo "Welcome $_POST[username]! You've been successfully reigstered!<br /><br />
		Please login <a href='login.php'><b>here</b></a>.";
	exit();
}

?>




its adding everything except the gender and poke 1 any reason why ?

This post has been edited by nick1200: 18 April 2010 - 05:58 AM


Is This A Good Question/Topic? 0
  • +

Replies To: my first ever register script error ?

#2 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: my first ever register script error ?

Posted 18 April 2010 - 07:27 AM

The reason is that while inserting data into members table, you are using $gender and $starter instead of $_POST['gender'] & $_POST['starter'].

Just correct the line and it will work-
$query = mysql_query("INSERT INTO members
        (username, firstname, lastname, password, date, ip, gender, poke1)
        VALUES  ('$_POST[username]','$_POST[firstname]','$_POST[lastname]','$_POST[password]','$date','$ip','$_POST[gender]','$_POST[starter]')")
or die ("Error - Couldn't register user.");


Was This Post Helpful? 1
  • +
  • -

#3 nick1200   User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: my first ever register script error ?

Posted 18 April 2010 - 07:35 AM

View Postatik97, on 18 April 2010 - 06:27 AM, said:

The reason is that while inserting data into members table, you are using $gender and $starter instead of $_POST['gender'] & $_POST['starter'].

Just correct the line and it will work-
$query = mysql_query("INSERT INTO members
        (username, firstname, lastname, password, date, ip, gender, poke1)
        VALUES  ('$_POST[username]','$_POST[firstname]','$_POST[lastname]','$_POST[password]','$date','$ip','$_POST[gender]','$_POST[starter]')")
or die ("Error - Couldn't register user.");



Thanks i must of forgot about that im glad it was something little thanks again
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3839
  • View blog
  • Posts: 14,005
  • Joined: 08-August 08

Re: my first ever register script error ?

Posted 18 April 2010 - 07:44 AM

Why are you trusting the user? You should never put POST or GET values directly into a query. At the very least you should use mysql_escape_string on them.
Was This Post Helpful? 0
  • +
  • -

#5 nick1200   User is offline

  • Php Coder
  • member icon

Reputation: -19
  • View blog
  • Posts: 922
  • Joined: 21-March 09

Re: my first ever register script error ?

Posted 18 April 2010 - 08:04 AM

View PostCTphpnwb, on 18 April 2010 - 06:44 AM, said:

Why are you trusting the user? You should never put POST or GET values directly into a query. At the very least you should use mysql_escape_string on them.


This script im making or made then has nothing to do with me
they have asked me to make a register script in any way i like
so i have and there happy with it
if it gets hacked in a month or two then that's there problem ive done what they asked " any way i want "
Was This Post Helpful? 0
  • +
  • -

#6 jrm402   User is offline

  • D.I.C Regular
  • member icon

Reputation: 52
  • View blog
  • Posts: 333
  • Joined: 18-March 10

Re: my first ever register script error ?

Posted 19 April 2010 - 02:36 PM

LOL!! :D As much as it is awesome to do what they want, the customer usually has no idea what they are doing (hence the reason you have a job!). If you had someone build you a block wall, then it fell down, and when you consulted them they said, "Well you never told me to reinforce the wall...". There comes a sort of responsibility with the title to let the customer know what they need to do to have a successful site.

Plus, I bet they were talking more about db design work done "any way you want.". But just a thought.
Was This Post Helpful? 0
  • +
  • -

#7 LiDoNg_9_0   User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 159
  • Joined: 03-September 09

Re: my first ever register script error ?

Posted 19 April 2010 - 06:29 PM

always bare in mind that everytime you register a user, you should check the user validity to avoid duplications..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1