[MYSQL, PHP] Creating a register field

Obey

You just played yourself.
Nov 23, 2013
250
29
DISCLAIMER: THIS IS MY FIRST TIME TRYING TO USE MYSQL/PHP!
Hi, I'm trying to add a column called 'country' to my 'users' table so that it's stored in the database and I can use it later on in an online users page. I thought the following SQL would work:
Code:
ALTER TABLE users
ADD column_name country
But it returns this error:
"#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'country' at line 2"

I'm sure this is pretty simple but I just can't figure it out. Can anyone please help? Thank you.
 

Khalil

IDK
Dec 6, 2011
1,642
786
Want me to help you on skype? I charge $8.
Help has already been provided to him, free of charge.
Not that I think you're capable of running a simple query to add a column to a table, but if you did know how to do so, you would seriously charge $8 just for that simple query? You pathetic child..

Thanks, it worked. Could you explain the "VARCHAR(225) NOT NULL" part to me?
The 'varchar(255)' part indicates that the content of the column will be a string and the length of the string that will take place inside that column will be 255 characters, and the 'NOT NULL' part means that the column will not hold a value of null, meaning it won't be empty.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
Thanks, it worked. Could you explain the "VARCHAR(225) NOT NULL" part to me?
VARCHAR means varied-characters I think, so it is just a normal string -- consisting of numbers + letters and other symbols like periods, commas, etc

255 is the maximum length of the string. I'm sure VARCHAR's max-length is 255 though, so if you wanted more, you'd have to use TEXT or LONGTEXT, maybe BLOB. There's more but I'm unsure as to which is the right to use

NOT NULL means it can't be empty when a record is being inserted into the database.
 

Obey

You just played yourself.
Nov 23, 2013
250
29
VARCHAR means varied-characters I think, so it is just a normal string -- consisting of numbers + letters and other symbols like periods, commas, etc

255 is the maximum length of the string. I'm sure VARCHAR's max-length is 255 though, so if you wanted more, you'd have to use TEXT or LONGTEXT, maybe BLOB. There's more but I'm unsure as to which is the right to use

NOT NULL means it can't be empty when a record is being inserted into the database.
Help has already been provided to him, free of charge.
The 'varchar(255)' part indicates that the content of the column will be a string and the length of the string that will take place inside that column will be 255 characters, and the 'NOT NULL' part means that the column will not hold a value of null, meaning it won't be empty.

Do you guys know by any chance how to make it so that once you put in your country on the registration field it goes into the column that I just created? I tried to use this but it didn't work.
Code:
<div class="field field-country"> 
                                        <label for="country"><b>Country</b></label> 
                                        <input type="text" id="country" size="35" value="<?php echo $template->form->reg_country; ?>" name="reg_country" class="text-field" maxlength="32"> 
                                    </div>
 

Khalil

IDK
Dec 6, 2011
1,642
786
Thanks, it worked. Could you explain the "VARCHAR(225) NOT NULL" part to me?
Do you guys know by any chance how to make it so that once you put in your country on the registration field it goes into the column that I just created? I tried to use this but it didn't work.
Code:
<div class="field field-country">
                                        <label for="country"><b>Country</b></label>
                                        <input type="text" id="country" size="35" value="<?php echo $template->form->reg_country; ?>" name="reg_country" class="text-field" maxlength="32">
                                    </div>
Open a thread in the Habbo section's .
 

Users who are viewing this thread

Top