PDA

View Full Version : [PHP] Create table on User register [MySQL]



Zaxza
April 8th, 2006, 12:57 PM
Hi, i'm working on a registration script and need to create a new table in MySQL when a user registers. I want the table to get it's name from the username of the person registering. How exactly can i do this?


$sql = "create table user ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), name VARCHAR (70), date VARCHAR (70), message VARCHAR (70), url VARCHAR (70))";
mysql_query($sql,$link) or die (mysql_error()); This creates a table called user, right?

I also have a tick box that when ticked i want it show a text field. Its to notify a user by email when they have a message. The text field is there so they can select the subject they want. How is this done?
Thanks in advance...

McGuffin
April 8th, 2006, 01:49 PM
So what you want to do is have a user table that houses all of the users, right?

In that case, just do this:



$sql = "create table user ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), name VARCHAR (70), date VARCHAR (70), message VARCHAR (70), url VARCHAR (70))";
mysql_query($sql,$link) or die (mysql_error());

$sql = "INSERT INTO `user` ( `id`, `name`, `date`, `message`, `url`) VALUES (NULL, '$name', '$date', '$message', '$url')";
mysql_query($sql,$link) or die (mysql_error());


Where $name, $message and $url would be entered information and I'm assuming you'd generate the proper date ($date) for them.

Ankou
April 8th, 2006, 01:55 PM
Hi, i'm working on a registration script and need to create a new table in MySQL when a user registers. I want the table to get it's name from the username of the person registering. How exactly can i do this?

Use the users name when creating the database table.


$username = "Chuck";

$sql = "create table $username ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), name VARCHAR (70), date VARCHAR (70), message VARCHAR (70), url VARCHAR (70))";

mysql_query($sql,$link) or die (mysql_error());

Just make sure that you're checking the users name for invalid characters so that you can actually make the table.



I also have a tick box that when ticked i want it show a text field. Its to notify a user by email when they have a message. The text field is there so they can select the subject they want. How is this done?
Thanks in advance...

Not sure I follow you. You mean when a user click on a check box that it will display a text field (as in the text field wasn't showing before the box is checked)?

Or do you just mean that if the check box is checked and the user enters information into the text field that the email being sent will use that field as the subject?

Or am I wrong with both of the above and you are looking for something else? If so, elaborate on what you're looking for since I'm not understanding you.

Zaxza
April 8th, 2006, 02:08 PM
Ye I want to have it appear when the tickbox is ticked. So that a user can then type in the Subject of the email in it.

Before:
http://i32.photobucket.com/albums/d12/maiverock/ss.jpg

After:
http://i32.photobucket.com/albums/d12/maiverock/ss2.jpg

bwh2
April 8th, 2006, 02:39 PM
i'm just curious, why do you want a whole new table created when a user registers?

Ankou
April 8th, 2006, 02:57 PM
Something like the following should work for your checkbox situation. It's just a very simple example to give you an idea on what you could do.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Checkbox enable</title>

<script type="text/javascript">
var subjectChecked = false;

function subjectLine(){
if(subjectChecked) subjectChecked = false;
else subjectChecked = true;

if(subjectChecked) document.genericForm.emailSubject.disabled = false;
else document.genericForm.emailSubject.disabled = true;
}

function clearCheck(){
document.genericForm.emailMe.checked = false;
document.genericForm.emailSubject.value = '';
document.genericForm.emailSubject.disabled = true;
}
</script>

</head>
<body onload="clearCheck()">
<form name="genericForm">
Notify you on new post: <input type="checkbox" name="emailMe" onclick="subjectLine()" /> <br />
Email Subject: <input type="text" name="emailSubject" disabled="disabled" value="" /> <br />
</form>
</body>
</html>

Zaxza
April 8th, 2006, 03:04 PM
Yeah i do. I'm trying to set it up so that when a user registers an account they get a customised shoutbox. I have a table for all my members' details and account settings. But i wanted a separate one for they're messages.
This is what i want the final registration form to look like:
http://i32.photobucket.com/albums/d12/maiverock/ss3.jpg

bwh2
April 9th, 2006, 01:24 PM
you should make one shoutbox table, not one for each user.

skOOb
April 9th, 2006, 02:35 PM
^ agreed. making a new table for every user doesnt make any sense. You should have one table of users, and then one table for the shoutbox containing the user identifier. Post questions if you need too, but don't do one shoutbox table per user.

SlowRoasted
April 10th, 2006, 11:05 AM
I second those guys in saying you need one table for the shoutbox. It's a bit rediculous to make a table for each, and also you will have to write extra code to make sure that no two people have the same username/table.