Page 1 of 1

mysql help

Posted: Fri May 03, 2002 9:12 pm
by triality159
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!!

Posted: Fri May 03, 2002 9:18 pm
by pozytron
You haven't really given enough information. What kind of table do you want? What's the goal of your page?

Posted: Fri May 03, 2002 9:23 pm
by triality159
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??

Posted: Fri May 03, 2002 9:33 pm
by triality159
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

Posted: Fri May 03, 2002 11:12 pm
by pozytron
The only big mistake you made was that the SQL code should be in a mysql_query().

Code: Select all

mysql_query("CREATE TABLE `user` ( 
`username` TINYINT(15) NOT NULL, 
`password` TINYINT(15) NOT NULL, 
PRIMARY KEY (`username`, `password`)");
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

User Names

Posted: Sat May 04, 2002 1:42 am
by Brian
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.

Posted: Sat May 04, 2002 7:32 am
by triality159
thanx guys for the help...also brian how do i prevent spaces?? thanx

Preventing Spaces

Posted: Sat May 04, 2002 8:35 am
by Brian
triality159 wrote:thanx guys for the help...also brian how do i prevent spaces?? thanx
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:

Beginning Space: /^ /

End Space: / $/

Consecutive Spaces: / / (Two Spaces Between The Slashes)

Any of the Above: /^ | | $/ (Two Spaces Between The Vertical Pipes)

Have fun! :)