3 Replies - 551 Views - Last Post: 15 January 2013 - 01:41 AM Rate Topic: -----

#1 Laura_657  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-November 12

page link to register.php throws up null column error without submit&#

Posted 11 January 2013 - 08:58 AM

Hey, I have a problem with a script that runs on my registration page of my website. The index page contains a submit button which links the user to the registration page, however, since updating the code to include more fields I get this error:

'Failed to run query: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'username' cannot be null'

I get this error just by clicking a link to the register.php page, so I figure something in my registration php code is submitting data as soon as the button is clicked on the index page, which shouldn't be happening. I'd paste all my code, but there is a lot. So I'll paste the seemingly important bits, and if you want more let me know.

register.php
<?php 

    include 'common.php'; 
     
    if(!empty($_POST)) 
    { 
        // Ensure that the user has entered a non-empty username 
        if(empty($_POST['username'])) 
        { 
            die("Please enter a username."); 
        } 
...


index.html
<input type="submit" class="registration" value="Register" /> 
</form>



I want to know which part of my code is causing the error (it actually used to work until I extended the database and so extended the PHP) & I'll be honest I have no idea where to start looking in my PHP code.

p.s. I know that using 'die' isn't the best method

Is This A Good Question/Topic? 0
  • +

Replies To: page link to register.php throws up null column error without submit&#

#2 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: page link to register.php throws up null column error without submit&#

Posted 11 January 2013 - 09:12 AM

debug your code!!
try to print out your variables when submitting your form. you will quickly see what's wrong with them. use var_dump() to see what you are passing.

we can not tell you where the problem is by looking at that small piece of code.
Was This Post Helpful? 0
  • +
  • -

#3 ZevhEr  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 38
  • Joined: 18-July 09

Re: page link to register.php throws up null column error without submit&#

Posted 15 January 2013 - 01:32 AM

try var_dump your $_POST and post your SQL Query.
Was This Post Helpful? 0
  • +
  • -

#4 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 789
  • View blog
  • Posts: 1,675
  • Joined: 30-January 09

Re: page link to register.php throws up null column error without submit&#

Posted 15 January 2013 - 01:41 AM

Your INSERT SQL statement is passing a null value to the DB column username, which can't take a null value. Post the PHP code from register.php all the way down to where you execute the INSERT statement, the bug is somewhere in there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1