Odbc Register Page

Results 1 to 5 of 5
  1. #1
    C:\ WizCoder is offline
    MemberRank
    Aug 2010 Join Date
    JapanLocation
    703Posts

    Odbc Register Page

    So like I'm trying to make a register page for Gunz and I haven't made one in so long so i'm coming across odbc errors and what not.

    Anyways I made a script for retrieving user names etc for ranking and it worked perfectly..

    I'm trying to insert data into mssql but it's not working so good for me.

    Heres the script:
    Code:
    <?php 
    
    //connect to a DSN "myDSN" 
    $host = "COMPUTER2\SQLEXPRESS";
    $user = "sa";
    $pass = "jimmydont";
    $dbname = "GunzDB";
    
    $conn = odbc_connect("Driver={SQL Server};Server={$host}; Database={$dbname}", $user, $pass) or die("Can't connect the MSSQL server.");
    
    if ($conn) 
    { 
      //the SQL statement that will query the database 
      $query = "INSERT INTO Login(UserID,Password) VALUES ('jimmy','dontcry')"; 
      //perform the query 
      $result=odbc_exec($conn, $query); 
    
    
    
    }
    
    
    ?>
    <html>
    <body>
    
    <form action = "#" method = "post"/>
    Username<input type = "text" name = "username"/>
    Password<input type = "password" name = "password"/>
    <input type = "submit" name = "Login" value = "Login"/>
    </form>
    
    </body>
    </html>

    I eject this and all it says is
    :
    Code:
    Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into column 'AID', table 'GunzDB.dbo.Login'; column does not allow nulls. INSERT fails., SQL state 23000 in SQLExecDirect in C:\xampp\htdocs\retrievedata.php on line 16
    I'm clearly not inserting NULLS as I definitively filled in information to enter.. Yes I tried $_POST['username'] I tried so many different combinations of going about this..

    I'm on Xamp 1.7.1 , mssql is allowed.


  2. #2
    Pee Aitch Pee Dave is offline
    MemberRank
    Mar 2011 Join Date
    The NetherlandsLocation
    722Posts

    Re: Odbc Register Page

    The AID column is a primary key.

    Example of a correct query which inserts into both account and login tables. (Without the values.)

    DECLARE @AIDIdent int INSERT INTO Account (UserID,UGradeID,PGradeID,Name,RegDate,Email) VALUES (all, values, here) SET @AIDIdent = @@IDENTITY INSERT INTO Login (UserID,AID,Password) VALUES (all, values, here)

  3. #3
    Hi, I'm Omar! Vusion is offline
    MemberRank
    Jan 2011 Join Date
    HereLocation
    1,658Posts

    Re: Odbc Register Page

    Quote Originally Posted by SuperWaffle View Post
    The AID column is a primary key.

    Example of a correct query which inserts into both account and login tables. (Without the values.)

    DECLARE @AIDIdent int INSERT INTO Account (UserID,UGradeID,PGradeID,Name,RegDate,Email) VALUES (all, values, here) SET @AIDIdent = @@IDENTITY INSERT INTO Login (UserID,AID,Password) VALUES (all, values, here)
    You shouldn't do it in one query when explaining, though.
    Last edited by Vusion; 28-01-13 at 02:52 PM.

  4. #4
    Pee Aitch Pee Dave is offline
    MemberRank
    Mar 2011 Join Date
    The NetherlandsLocation
    722Posts

    Re: Odbc Register Page

    Doesn't really matter ;o.

  5. #5
    C:\ WizCoder is offline
    MemberRank
    Aug 2010 Join Date
    JapanLocation
    703Posts

    Re: Odbc Register Page

    Sorry guys I forgot to update this thread, I found out it was AID ... before seeing comments.

    Thanks for helping.



Advertisement