Jump to content

Register page - script wont add details to mysql table


overidemehra

Recommended Posts

Hi,

 

i was jsut wondering why does not my script allow to add details when i add the username, password and email. Thought it will not allow me to take the same username or email already present in my mysql table. It even goes thorugh when i add all new details , by saying that i have registered properly and i can login. But when i check in my mysql table, no new data is added. How to fix this?

 

i am new to php... learnt over the net....

 

thanks

 

 

 

<?php

 

  $action=$_GET["action"];

 

  $uname = $_POST["user"];

  $pword = $_POST["pass"];

  $email = $_POST["email"];

  $vpass = $pword;

 

  $user_name = "xxxxx";

  $pass_word = "xxxxx";

  $dbname="xxxx";

  $table = "login";

  $server = "xxxx";

 

  $c=mysql_connect($server,$user_name, $pass_word, $table) OR DIE ('Unable to connect to database! Please try again later.');

  $db_found=mysql_select_db($dbname);

 

 

//if registering, check fields.

if ($action == register) {

 

if (!$uname || !$pword || !$email || !$vpass) {

print "You must fill out all fields.";

 

exit;

}

$dupe1 = mysql_num_rows(mysql_query("SELECT username FROM `$table` WHERE `username` = '$uname'"));

 

if ($dupe1 > 0) {

print "Someone already has that username.";

 

exit;

}

$dupe2 = mysql_num_rows(mysql_query("SELECT email FROM `$table` WHERE `email` ='$email'"));

if ($dupe2 > 0) {

print "Someone already has that email.";

 

exit;

}

 

//check if passwords are the same

if ($pword != $vpass) {

print "The passwords do not match.";

 

exit;

}

//end

//insert

mysql_query("INSERT INTO login (username, email, pass) VALUES ('$uname','$email','$pword')");

 

print "You are now registered. Login.";

}

?>

 

<html>

<body>

 

<form method=post action=register.php?action=register  name=s>

<table>

<tr><td>Username:</td><td><input type=text name=user></td></tr>

<tr><td>Email:</td><td><input type=text name=email></td></tr>

<tr><td>Pass:</td><td><input type=password name=pass></td></tr>

<tr><td>Verify Pass:</td><td><input type=password name=vpass></td></tr>

<tr><td colspan=2 align=center><input type=submit value=Register></td></tr>

</table>

</form>

 

 

</body>

</html>

 

<?php

   $action=$_GET["action"];
   
   $uname = $_POST["user"];
   $pword = $_POST["pass"];
   $email = $_POST["email"];
   $vpass = $pword;

   $user_name = "xxxxx";
   $pass_word = "xxxxx";
   $dbname="xxxx";
   $table = "login";
   $server = "xxxx";

   $c=mysql_connect($server,$user_name, $pass_word, $table) OR DIE ('Unable to connect to database! Please try again later.');
   $db_found=mysql_select_db($dbname);


//if registering, check fields.
if ($action == register) {

if (!$uname || !$pword || !$email || !$vpass) {
print "You must fill out all fields.";

exit;
}
$dupe1 = mysql_num_rows(mysql_query("SELECT username FROM `$table` WHERE `username` = '$uname'"));

if ($dupe1 > 0) {
print "Someone already has that username.";

exit;
}
$dupe2 = mysql_num_rows(mysql_query("SELECT email FROM `$table` WHERE `email` ='$email'"));
if ($dupe2 > 0) {
print "Someone already has that email.";

exit;
}

//check if passwords are the same
if ($pword != $vpass) {
print "The passwords do not match.";

exit;
}
//end
//insert
///////////////////////////////////////////////////////
/////////////////////Code Adjusted from here down
/////////////////////havent looked at the rest, but
/////////////////////if you were just having issue
/////////////////////with just insert this should
/////////////////////fix it..
///////////////////////////////////////////////////////
$query_up = "INSERT INTO login (username, email, pass) VALUES('$uname', '$email', '$pword')";
mysql_query($query_up) or die('Error, insert query failed.<br><br>' . mysql_error());


print "You are now registered. Login.";
}
?>

<html>
<body>

<form method="post" action="register.php?action=register" name="s">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Email:</td><td><input type="text" name="email"></td></tr>
<tr><td>Pass:</td><td><input type="password" name="pass"></td></tr>
<tr><td>Verify Pass:</td><td><input type="password" name="vpass"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Register"></td></tr>
</table>
</form>


</body>
</html>

 

The problem I found with your original insert was it was laid out in my opion wrong, but there's different ways for everyone that is mine.. the concept works fine for me on a site i am building (crecs.org)

 

One thing I beg you to look into and research before implementing this script above is SQL Sanitation.. Sanitize your inputs.. Also consider encrypting passes.. shal() would work fine.. and look into SQL Injection Attacks as well that will help better understand why Sanitation is needed.

thanks alot ppl...

 

 

its is possible that could you just show me where to add these protection commands, as i have no clue u even needd to, i thought all this was fine, as i am testing everything is running perfectly fine now, it adds the data to my database.....

 

 

thanks... :)

 

 

heres my new script

 

 

<?php

 

$action=$_GET["action"];

 

$uname = $_POST["user"];

$pword = $_POST["pass"];

$email = $_POST["email"];

$vpass = $pword;

 

$user_name = "xxxx";

$pass_word = "xxxx";

$dbname="xxxx";

$table = "login";

$server = "xxxx";

 

$c=mysql_connect($server,$user_name, $pass_word, $table) OR DIE ('Unable to connect to database! Please try again later.');

$db_found=mysql_select_db($dbname);

 

 

//if registering, check fields.

if ($action == register) {

 

if (!$uname || !$pword || !$email || !$vpass) {

?>

 

<SCRIPT language=JavaScript>

var message = "Copy Right Belongs To The Administrator";

function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }

if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }

document.onmousedown = rtclickcheck;

</SCRIPT>

 

<META http-equiv=Content-Type content="text/html; charset=UTF-8">

<META content="" name=keywords>

 

<META content="xxxx" name=author><LINK href="xxxx" type=text/css rel=stylesheet>

</HEAD>

<BODY>

<DIV align=center> </DIV>

<DIV id=pageWrapper>

<DIV id=pageHeader>

<H1><B><FONT size=5>xxxx</FONT></B><BR><B><I><FONT size=2>The greatest site on the Internet!</FONT></I></B></H1></DIV>

 

 

<DIV align=center> </DIV></DIV></DIV></DIV>

<DIV id=mainContent><FONT size=5><STRONG> Login</STRONG></FONT>

<DIV class=contentContainer>

<UL>

You must fill out all fields.  <A href="register.php">Click here to Register</a>

 

<?

 

exit;

}

$dupe1 = mysql_num_rows(mysql_query("SELECT username FROM `$table` WHERE `username` = '$uname'"));

 

if ($dupe1 > 0) {

?>

 

<SCRIPT language=JavaScript>

var message = "Copy Right Belongs To The Administrator";

function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }

if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }

document.onmousedown = rtclickcheck;

</SCRIPT>

 

<META http-equiv=Content-Type content="text/html; charset=UTF-8">

<META content="" name=keywords>

 

<META content="xxxx" name=author><LINK href="xxxxx" type=text/css rel=stylesheet>

</HEAD>

<BODY>

<DIV align=center> </DIV>

<DIV id=pageWrapper>

<DIV id=pageHeader>

<H1><B><FONT size=5>xxxxx</FONT></B><BR><B><I><FONT size=2>The greatest site on the Internet!</FONT></I></B></H1></DIV>

 

 

<DIV align=center> </DIV></DIV></DIV></DIV>

<DIV id=mainContent><FONT size=5><STRONG> Login</STRONG></FONT>

<DIV class=contentContainer>

<UL>

Someone already has that username.  <A href="register.php">Click here to Register</a>

 

<? 

 

exit;

}

$dupe2 = mysql_num_rows(mysql_query("SELECT email FROM `$table` WHERE `email` ='$email'"));

if ($dupe2 > 0) {

 

?>

 

<SCRIPT language=JavaScript>

var message = "Copy Right Belongs To The Administrator";

function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }

if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }

document.onmousedown = rtclickcheck;

</SCRIPT>

 

<META http-equiv=Content-Type content="text/html; charset=UTF-8">

<META content="" name=keywords>

 

<META content="xxxx" name=author><LINK href="xxxx" type=text/css rel=stylesheet>

</HEAD>

<BODY>

<DIV align=center> </DIV>

<DIV id=pageWrapper>

<DIV id=pageHeader>

<H1><B><FONT size=5>xxxx</FONT></B><BR><B><I><FONT size=2>The greatest site on the Internet!</FONT></I></B></H1></DIV>

 

 

<DIV align=center> </DIV></DIV></DIV></DIV>

<DIV id=mainContent><FONT size=5><STRONG> Login</STRONG></FONT>

<DIV class=contentContainer>

<UL>

Someone already has that email.  <A href="register.php">Click here to Register</a>

 

<? 

 

exit;

}

 

//check if passwords are the same

if ($pword != $vpass) {

echo "The passwords do not match.";

 

exit;

}

//end

//insert

$send = mysql_query("INSERT INTO login SET `username` = '$uname', `password` = '$pword', `email` = '$email'");

 

if ($send) {

?>

 

<SCRIPT language=JavaScript>

var message = "Copy Right Belongs To The Administrator";

function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }

if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }

document.onmousedown = rtclickcheck;

</SCRIPT>

 

<META http-equiv=Content-Type content="text/html; charset=UTF-8">

<META content="" name=keywords>

 

<META content="xxxx" name=author><LINK href="xxxx" type=text/css rel=stylesheet>

</HEAD>

<BODY>

<DIV align=center> </DIV>

<DIV id=pageWrapper>

<DIV id=pageHeader>

<H1><B><FONT size=5>xxxx</FONT></B><BR><B><I><FONT size=2>The greatest site on the Internet!</FONT></I></B></H1></DIV>

 

 

<DIV align=center> </DIV></DIV></DIV></DIV>

<DIV id=mainContent><FONT size=5><STRONG> Login</STRONG></FONT>

<DIV class=contentContainer>

<UL>

<A href="index.php">Click here to Login</a>

 

<? 

  exit;

}

}

?>

 

                   

                     

 

<html>

<body>

<HEAD><TITLE>xxxx</TITLE>

<SCRIPT language=JavaScript>

var message = "Copy Right Belongs To The Administrator";

function rtclickcheck(keyp){ if (navigator.appName == "Netscape" && keyp.which == 3){ alert(message); return false; }

if (navigator.appVersion.indexOf("MSIE") != -1 && event.button == 2) { alert(message); return false; } }

document.onmousedown = rtclickcheck;

</SCRIPT>

 

<META http-equiv=Content-Type content="text/html; charset=UTF-8">

<META content="" name=keywords>

 

<META content="xxxx" name=author><LINK href="xxxx" type=text/css rel=stylesheet>

</HEAD>

<BODY>

<DIV align=center> </DIV>

<DIV id=pageWrapper>

<DIV id=pageHeader>

<H1><B><FONT size=5>xxxx</FONT></B><BR><B><I><FONT size=2>The greatest site on the Internet!</FONT></I></B></H1></DIV>

 

 

<DIV align=center> </DIV></DIV></DIV></DIV>

<DIV id=mainContent><FONT size=5><STRONG> Login</STRONG></FONT>

<DIV class=contentContainer>

<UL>

<form method=post action=register.php?action=register  name=s>

<table>

<tr><td>Username:</td><td><input type=text name=user></td></tr>

<tr><td>Email:</td><td><input type=text name=email></td></tr>

<tr><td>Pass:</td><td><input type=password name=pass></td></tr>

<tr><td>Verify Pass:</td><td><input type=password name=vpass></td></tr>

<tr><td colspan=2 align=center><input type=submit value=Register></td></tr>

</table>

 

</form>

All Content &copy by xxxx

 

</UL></DIV></DIV></DIV></DIV>

 

</body>

</html>

conti of above ...

 

if  someone could explain how to make the script forward an email to the person who registers my site and as well as to me... jsut how it happens on this site when u register , an email coems with ur user name and password????

 

 

thanks alot

 

 

:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.