mysql help
Moderator: General Moderators
-
triality159
- Forum Newbie
- Posts: 4
- Joined: Fri May 03, 2002 9:12 pm
- Location: illinois
- Contact:
mysql help
does anyone know how to make tables with a php script so like the user doesnt have to do it by hand it will just happen when he sets it up...please help!!
-
triality159
- Forum Newbie
- Posts: 4
- Joined: Fri May 03, 2002 9:12 pm
- Location: illinois
- Contact:
im going to make a news posting script and right now i am just trying to get the user validation thing down but i need to make 2 tables one for the username and one for hte password........i know how to make the tables using like phpmyadmin but i want to make it so the user doesnt have to do it by hand they can just run the install script and it will make it for them....can you help??
-
triality159
- Forum Newbie
- Posts: 4
- Joined: Fri May 03, 2002 9:12 pm
- Location: illinois
- Contact:
alrite here is what i got right now
<html>
<head>
<title>Connect to the Database</title>
</head>
<body>
<?php
$dbconn = mysql_connect("localhost", "user", "pass");
$result = mysql_select_db("news", $dbconn);
if ( $result == false )
{
echo mysql_error();
} else {
echo "Yay! We connected successfully!";
}
CREATE TABLE `user` (
`username` TINYINT(15) NOT NULL,
`password` TINYINT(15) NOT NULL,
PRIMARY KEY (`username`, `password`)
);
?>
</body>
</html>
but it still doesnt work.....
http://www.fcubed.dx-games.com/news/db_test.php
is the site....hope u guys can help!! thanx
<html>
<head>
<title>Connect to the Database</title>
</head>
<body>
<?php
$dbconn = mysql_connect("localhost", "user", "pass");
$result = mysql_select_db("news", $dbconn);
if ( $result == false )
{
echo mysql_error();
} else {
echo "Yay! We connected successfully!";
}
CREATE TABLE `user` (
`username` TINYINT(15) NOT NULL,
`password` TINYINT(15) NOT NULL,
PRIMARY KEY (`username`, `password`)
);
?>
</body>
</html>
but it still doesnt work.....
http://www.fcubed.dx-games.com/news/db_test.php
is the site....hope u guys can help!! thanx
The only big mistake you made was that the SQL code should be in a mysql_query().
Also, are you sure you want the username to be a number? Users prefer to have a word as a username because it's easier to remember.
Hope this helps.
Cheers
Code: Select all
mysql_query("CREATE TABLE `user` (
`username` TINYINT(15) NOT NULL,
`password` TINYINT(15) NOT NULL,
PRIMARY KEY (`username`, `password`)");Hope this helps.
Cheers
User Names
Here is just a quick tip for you:
Keep in mind that if you do change your user names to strings, you should disallow spaces at the beginning or the end and disallow more than one consecutive space in the middle to prevent any issues that may arise due to spaces not being clearly present or spaces being consolidated (impersonation, etc.). Full validation is important, of course, but the space issue is easy to overlook.
Keep in mind that if you do change your user names to strings, you should disallow spaces at the beginning or the end and disallow more than one consecutive space in the middle to prevent any issues that may arise due to spaces not being clearly present or spaces being consolidated (impersonation, etc.). Full validation is important, of course, but the space issue is easy to overlook.
-
triality159
- Forum Newbie
- Posts: 4
- Joined: Fri May 03, 2002 9:12 pm
- Location: illinois
- Contact:
Preventing Spaces
As soon as a program has the input from the user, you should always validate it. During the validation phase, just use a pattern-matching function such as preg_match() (there are other ways; experiment!) to check for spaces at the beginning or the end of a string or consecutively in the middle of one. Read up on a pattern-matching function of your choice then try these super-simple patterns:triality159 wrote:thanx guys for the help...also brian how do i prevent spaces?? thanx
Beginning Space: /^ /
End Space: / $/
Consecutive Spaces: / / (Two Spaces Between The Slashes)
Any of the Above: /^ | | $/ (Two Spaces Between The Vertical Pipes)
Have fun!