Jump to content

Custom forms through mysql parsing?


timtamboy63

Recommended Posts

Hey guys, I joined just too ask this question, but I am starting to like php so I may stick around,

Anyway, here's what im trying to do:

Basically, ive got my form printing out some default fields, and then checking the db for any additional fields it has to print out. This bit works fine, i can easily get it to print out the additional fields from the database.

 

I can also add the columns needed to the databsae where the users are stored.

 

The problem im having is parsing the additional values from the additional forms into the database.

 

Might be easier if I give you some more info.

1:In my database, i have two tables, users and profile.

All the users are stored in the table users

The table profile is for any additional fields the admin wants to add to the registration page.

As I said earilier, I can get the fields to print out no problem.(ive also got the required columns added in table users.

I can't work out how to parse them into a sql query.

 

Heres the code for my reg page so far(it doesnt parse the additional values from the registration form.

 

<?php

include_once('includes/header.php');

if(isset($_POST['submitted'])){  //if they've submitted the form, then
    dbconnect();
    $user=mysql_real_escape_string($_POST['reg_user']);  //first santize the input
    $pass=md5(mysql_real_escape_string($_POST['reg_pass']));
    $email=mysql_real_escape_string($_POST['reg_email']);    
    $usernametaken="SELECT * FROM users WHERE username = '$user'";  //check if the username is taken
    $queryresult=mysql_query("$usernametaken");
    $row = mysql_fetch_array($queryresult);
    if($row['username']!=""){   //if it is, tell the user to register under a different name and show them the reg form
        print "Username Taken, please use another username";
        include('includes/regform.php');
    }
    else{  
        $query="INSERT INTO users VALUES('', '$user', '$pass', '$email', '0')";
        mysql_query("$query");
        dbclose();
        print "Thank you for registering " . $user . ". Please Login Below";
        include('index.php');  //show them the login so they can log in
    }
}
else{  //if they havent submitted the form
    include('includes/regform.php');  //print out the form
}
include_once('includes/footer.php');
?>

Im trying to get it to parse the additional values submitted by the registration form, but i can't work out how to.

 

If it helps, here's my registration form(regform.php):

<script language="javascript" src="js/checkform.js"></script>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return checkregform(this);">
Username:<br />
<input type="text" name="reg_user" /><br />
Password:<br />
<input type="password" name="reg_pass" /><br />
Repeat Password:<br />
<input type="password" name="reg_passrepeat" /><br />
Email:<br />
<input type="text" name="reg_email" /><br />
Repeat Email:<br />
<input type="text" name="reg_emailrepeat" /><br />
<?php
dbconnect();
$query="SELECT * FROM profile";
$regform_queryresult=mysql_query("$query") or die(mysql_error());
while($regforms=mysql_fetch_array($regform_queryresult)){
print $regforms['name'] . "<br />";
print "<input type=\"text\" name=\"";
print $regforms['name']; print "\" /><br />";
}
dbclose();
?>
<input type="hidden" name="submitted" /><br />
<input type="submit" name="reg" value="Register!" />
</form>

If you did read through all that thanks

If you can help me, thanks a tonne

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.