FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

database install file

 


Requell
I am creating a database install file. I am new with the php and sql resources however im learning pretty quickly.

This command does not seem to work, and I havent figured out why.


Code:
mysql_query(
    "INSERT INTO `UserAccounts` (
      UName,
      UFName,
      ULName,
      UPass,
      AccessLevel
                        )
    VALUES (
      'Admin',
      'Anthony',
      'Clink',
      'Mmage1029r',
      '3'
          )"
);
SonLight
Assuming you are properly connected to the database, and that you do have a table called 'UserAccounts' with the specified column names and the right properties, then it is not obvious why it failed. If your script is intended to initially setup the database, then it would be more common for it to include table creation commands.

You might try using the mysql_error() function to see if it gives you a more specific error message. If you are not able to figure it out from that, post the error message here and maybe someone can give you more insight.
Requell
Ahh thank you, I used the
Code:
or die(mysql_error());
command, and it told me I did not have the UserAccounts table.

The whole script is
Code:
<html>

<head>
  <title></title>
</head>

<body>

<?php

include "dbaccess.php";

if (mysql_query("CREATE DATABASE plumbing",$con))
  {
  echo "Database created";
  }

else
  {
  echo "Error creating database: " . mysql_error();
  }// Create table in my_db database

mysql_select_db("plumbing", $con);

$sql =
   "CREATE TABLE `UserAccounts`
(
  `ID` int(11) NOT NULL auto_increment,
  `UName` text NOT NULL,
  `UFName` text NOT NULL,
  `ULName` text NOT NULL,
  `UPass` text NOT NULL,
  `AccessLevel` text NOT NULL,
  PRIMARY KEY  (`ID`)
)";

mysql_query($sql,$con);

mysql_query(
    "INSERT INTO `UserAccounts` ( UName, UFName, ULName, UPass, AccessLevel )
VALUES (
'Admin', 'Anthony', 'Clink', 'Mmage1029r', '3'
)")
or die(mysql_error());

mysql_close($con);
?>


</body>

</html>


I had
Code:
mysql_query($sql,$con);
posted after the data was posted. So the table was not created before the data was inserted. Thank you for your help!
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.