mysql help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
triality159
Forum Newbie
Posts: 4
Joined: Fri May 03, 2002 9:12 pm
Location: illinois
Contact:

mysql help

Post 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!!
pozytron
Forum Newbie
Posts: 12
Joined: Fri May 03, 2002 7:14 pm
Location: Denver

Post by pozytron »

You haven't really given enough information. What kind of table do you want? What's the goal of your page?
triality159
Forum Newbie
Posts: 4
Joined: Fri May 03, 2002 9:12 pm
Location: illinois
Contact:

Post 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??
triality159
Forum Newbie
Posts: 4
Joined: Fri May 03, 2002 9:12 pm
Location: illinois
Contact:

Post 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
pozytron
Forum Newbie
Posts: 12
Joined: Fri May 03, 2002 7:14 pm
Location: Denver

Post 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
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

User Names

Post 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.
triality159
Forum Newbie
Posts: 4
Joined: Fri May 03, 2002 9:12 pm
Location: illinois
Contact:

Post by triality159 »

thanx guys for the help...also brian how do i prevent spaces?? thanx
Brian
Forum Contributor
Posts: 116
Joined: Thu Apr 18, 2002 5:33 pm

Preventing Spaces

Post 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! :)
Post Reply