Jump to content

[SOLVED] "Insert into" help


adamlacombe

Recommended Posts

I have this code here:

<?php
include "connect.php";

$password = md5($password);

      $join="INSERT INTO admins(username,password,avatar,myspace) values('$username','$password','$avatar','$myspace')";

      mysql_query($join) or die("Could not join"); //insert post

      print "You have registerd, <A href='main_login.php'>login</a>.";


   print "<form name='form' action='register.php' method='post'>";

   print "Your name:<br />";

   print "<input type='text' name='username' size='20'><br />";

   print "Password:<br />";

   print "<input type='text' name='password' size='20'><br />";

   print "Avatar:<br />";

   print "<input type='text' name='avatar' size='20'><br />";

   print "Myspace:<br />";

   print "<input type='text' name='myspace' size='20'><br />";

   print "<input type='submit' name='submit' value='Join!'></form>";


?>

 

and when I register, it creates two rows, one with all the information like username,password ect. and another with nothing.

How would i fix this?

Thanks in advanced,

Adam L

Link to comment
Share on other sites

You can actually just do this all in one page.  It will make things a lot easier, especially validation and readability so you don't have to go from script to script.

 

A couple things I noticed/fixed:

  • You weren't properly escaping your data, which in turn could result in a security issue.  Learn to use mysql_real_escape_string.
  • The query was being executed, unconditionally, with blank information, resulting in your blank entry issue.
  • I submitted your data to the same page for the reasons stated above.
  • There is no error or validation checking.  I'm not sure if you got to this or not but users could enter blank, duplicate, or potential invalid usernames that would have otherwise been successfully INSERTed into your database.
  • Cleaned and formatted your code a bit.

 

include "connect.php";

if(isset($_POST['submit']))
{
   $password = md5(mysql_real_escape_string($_POST['password']));
   $avatar = mysql_real_escape_string($_POST['avatar']);
   $username = mysql_real_escape_string($_POST['username']);
   $myspace = mysql_real_escape_string($_POST['myspace']);
   $join="INSERT INTO admins(username,password,avatar,myspace) values('$username','$password','$avatar','$myspace')";
   mysql_query($join) or die("Could not join" . mysql_error()); //insert post
   print "You have registerd, login.";
}  
   
print "</pre>
<form name="'form'" action="'register.php'" method="'post'">";
print "Your name:
";
print "
";
print "Password:
";
print "
";
print "Avatar:
";
print "
";
print "Myspace:
";
print "
";
print "</form>";<br><br

 

Hope this helps, good luck.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.