I'm currently creating a website using joomla (with template mega deals II), and whenever I test registration, I get either one of two errors.
One: Warning
Registration failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 2)' at line 3
This happens when my id column in my users table is not the primary key, so it creates a db entry with 0 for id. The registration form does go through and I can see that the account had been added in the table; however, the id is always 0 no matter how many accounts I add.
Two: Warning
Error getting the user from the database: Duplicate entry '0' for key 'PRIMARY'
This happens when I set the id as a primary key and let it auto increment. I did a lot of testing, and playing around with the values in the table, it seems to me that for some reason, the registration form sends info to the database with id set to 0 (since default for id is none) first, then the error comes in, then it auto increments inside the table. I say this because I'm able to add 1 user before this specific error keeps reoccuring, so it seems like the very first user takes up the default id and current auto increment id at the same time? Is this even possible?
Both are set as INT(11), but when I use id as a primary key the max value of id is the current increment of the id, usually something around the 700s.
Any help would be appreciated in solving this problem.
Here is a picture of my db structure.
https://i.stack.imgur.com/txT9E.png
These are all the other possible solutions from stackoverflow I've tried:
MySQL PHPMyAdmin Error #1062 - Duplicate entry '0' for key 'PRIMARY'
phpMyAdmin #1062 - Duplicate entry '' for key 'PRIMARY'
MySQL 1062 - Duplicate entry '0' for key 'PRIMARY'
Error: Duplicate entry '0' for key 'PRIMARY'
#1062 - Duplicate entry '0' for key 'PRIMARY'
phpmyadmin error "#1062 - Duplicate entry '1' for key 1"
phpMyAdmin: MySQL Error 1062 - Duplicate entry
#1062 - Duplicate entry 0' for key 'PRIMARY'
Here is code from registration directory in mega deals II template
From default.php
<?php
/**
* @package Joomla.Site
* @subpackage com_users
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
JHtml::_('behavior.formvalidation');
?>
<div class="row">
<div class="col-sm-4 col-sm-offset-4">
<div class="registration<?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1>
<?php endif; ?>
<form id="member-registration" action="<?php echo JRoute::_('index.php?option=com_users&task=registration.register'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
<?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?>
<?php $fields = $this->form->getFieldset($fieldset->name);?>
<?php if (count($fields)):?>
<?php foreach ($fields as $field) :// Iterate through the fields in the set and display them.?>
<?php if ($field->hidden):// If the field is hidden, just display the input.?>
<?php echo $field->input;?>
<?php else:?>
<div class="form-group">
<?php echo $field->label; ?>
<?php if (!$field->required && $field->type != 'Spacer') : ?>
<span class="optional"><?php echo JText::_('COM_USERS_OPTIONAL');?></span>
<?php endif; ?>
<div class="group-control">
<?php echo $field->input;?>
</div>
</div>
<?php endif;?>
<?php endforeach;?>
<?php endif;?>
<?php endforeach;?>
<div class="form-group">
<button type="submit" class="btn btn-primary validate"><?php echo JText::_('JREGISTER');?></button>
<a class="btn btn-danger" href="<?php echo JRoute::_('');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="registration.register" />
</div>
<?php echo JHtml::_('form.token');?>
</form>
</div>
</div>
</div>
From complete.php
<?php
/**
* @package Joomla.Site
* @subpackage com_users
*
* @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
?>
<div class="registration-complete<?php echo $this->pageclass_sfx;?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1>
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h1>
<?php endif; ?>
</div>