Hi there all!
I'm just starting db connectivity with mySQL, and it's been a while since I used php.
This code has an error somewhere, but my host is suppresing error messages, and I can't see for myself what's wrong; please advise? Thanks.
if ($add == "yes")
{
$check = "[^0-9A-Za-z]";
$agecheck = "[^0-9]";
if (ereg($check, $username)) die('Username can only contain a-z and 0-9');
if (ereg($check, $password)) die('Password can only contain a-z and 0-9');
if ($age != "")
{
if (ereg($agecheck, $age)) die('Age can only contain 0-9');
}
elseif ($age == "")
{
$age = "NULL";
}
// Connecting, selecting users database
echo "Connecting, selecting users database...<BR>";
$link = mysql_connect('localhost', 'username', 'password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully...<BR>';
mysql_select_db('domd') or die('Could not select database');
$query = 'INSERT INTO `users` (`UserID`, `Username`, `Heirachy`, `Password`, `Age`, `Join_date`, `Last_login`, `Holiday`) VALUES (\'\', \'${username}\',
\'m\', \'${password}\', \'${age}\', \'${date}\', \'${date}\', \'n\')';
// Closing connection
mysql_close($link);
}
Nots: The db connecting values aren't username etc., but I've replaced them for obvious reasons. 😉