tags:

views:

152

answers:

4

My knowledge level here is like zilch, but please bear with me.

I have a site built in PHP/MySQL that uses the Smarty template engine. There's a registration form that, for some reason, isn't posting the data to the DB. Here's the function:

        $u = new H_User;
            $u->setFrom($p);
            $smarty->assign('user', $u);
            $val = $u->validate();
            if ($val === true) {

                $temp = new H_User;
                $temp->orderBy('user_id desc');
                $temp->find(true);

                $next_id = $temp->user_id + 1;

                $u->user_id = $next_id;
                $u->user_password = md5($p['user_password']);
                $u->user_regdate = mktime();
                $u->user_active = 0;
                $u->insert();
                $hash = md5($u->user_email . $u->user_regdate);

                $smarty->assign('hash', $hash);
                $smarty->assign('user', $u);

                $smarty->assign('registration_complete', true);

                $d = new H_Demographic;
                $d->setFrom($p);
                $d->insert();

How can I figure out what's wrong here? I don't get any PHP errors and I don't know how to get MySQL to display the errors that might indicate what's wrong with that syntax.

MORE INFO AS PER REQUESTS

#
# Table structure for table `user`
#

DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `user_id` mediumint(8) NOT NULL default '0',
  `user_active` tinyint(1) default '1',
  `username` varchar(25) NOT NULL default '',
  `user_password` varchar(32) NOT NULL default '',
  `user_session_time` int(11) NOT NULL default '0',
  `user_session_page` smallint(5) NOT NULL default '0',
  `user_lastvisit` int(11) NOT NULL default '0',
  `user_regdate` int(11) NOT NULL default '0',
  `user_level` tinyint(4) default '0',
  `user_posts` mediumint(8) unsigned NOT NULL default '0',
  `user_timezone` decimal(5,2) NOT NULL default '0.00',
  `user_style` tinyint(4) default NULL,
  `user_lang` varchar(255) default NULL,
  `user_dateformat` varchar(14) NOT NULL default 'd M Y H:i',
  `user_new_privmsg` smallint(5) unsigned NOT NULL default '0',
  `user_unread_privmsg` smallint(5) unsigned NOT NULL default '0',
  `user_last_privmsg` int(11) NOT NULL default '0',
  `user_emailtime` int(11) default NULL,
  `user_viewemail` tinyint(1) default NULL,
  `user_attachsig` tinyint(1) default NULL,
  `user_allowhtml` tinyint(1) default '1',
  `user_allowbbcode` tinyint(1) default '1',
  `user_allowsmile` tinyint(1) default '1',
  `user_allowavatar` tinyint(1) NOT NULL default '1',
  `user_allow_pm` tinyint(1) NOT NULL default '1',
  `user_allow_viewonline` tinyint(1) NOT NULL default '1',
  `user_notify` tinyint(1) NOT NULL default '1',
  `user_notify_pm` tinyint(1) NOT NULL default '0',
  `user_popup_pm` tinyint(1) NOT NULL default '0',
  `user_rank` int(11) default '0',
  `user_avatar` varchar(100) default NULL,
  `user_avatar_type` tinyint(4) NOT NULL default '0',
  `user_email` varchar(255) default NULL,
  `user_icq` varchar(15) default NULL,
  `user_website` varchar(100) default NULL,
  `user_from` varchar(100) default NULL,
  `user_sig` text,
  `user_sig_bbcode_uid` varchar(10) default NULL,
  `user_aim` varchar(255) default NULL,
  `user_yim` varchar(255) default NULL,
  `user_msnm` varchar(255) default NULL,
  `user_occ` varchar(100) default NULL,
  `user_interests` varchar(255) default NULL,
  `user_actkey` varchar(32) default NULL,
  `user_newpasswd` varchar(32) default NULL,
  `first_name` varchar(40) NOT NULL default '',
  `last_name` varchar(40) NOT NULL default '',
  `level` int(10) unsigned NOT NULL default '0',
  `disabled` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`user_id`),
  KEY `user_session_time` (`user_session_time`)
) TYPE=MyISAM;
A: 

I'm still trying to figure this out and dump this in as a comment vs. an answer so I apologize if this shows up as an answer because it is not. Try putting the following code to spit out your errors:

error_reporting(E_ALL);
ini_set('display_errors', '1');

You may want to look at your php.ini file to allow displaying errors as well.

Duniyadnd
added that code but no errors were revealed
mobius1ski
A: 

Do you have access to your server error log? That should show MySQL errors, I think. But as Pekka said, this isn't really enough info to go on.

crimson_penguin
i do, but it's not reporting mysql errors or any errors related to this site.
mobius1ski
A: 

MySQL connections all have a way to access the last errors thrown by them. It depends on which method you're using to connect to the DB. For instance, I use mysqli class. Therefore, as an example directly from PHP's website:

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if (!$mysqli->query("SET a=1")) {
    printf("Errormessage: %s\n", $mysqli->error);
}

is how I could connect and then retrieve an error if it was thrown. How are you sending data to the DB? Do you have an example of the code that injects the data into the DB?

dscher
A: 

put

trigger_error(mysql_error());

after

$d->insert();

Edit:

As Marc B pointed out, you would need to use

trigger_error(mysqli_error());

instead for mysqli_ functions. PHP can be lame sometimes.

Duncan
This would only work if smarty's using the mysql_*() functions internally. If it's using mysqli directly, or indirectly via MDB2/PDO, this'll be useless.
Marc B
@Marc B: How so? Does Smarty bypass PHP's MySQL functions? According to the manual, `mysql_error()` "Returns the error text from the last MySQL function." Surely that would be *any* call to MySQL?
Duncan
@duncan you're my hero
mobius1ski
@Duncan: mysqli and mysql use seperate connection pools. A db handle produced in one cannot be used in the equivalent function calls of the other.
Marc B
@Marc B: I misread what you wrote, and thought you meant that it wouldn't work if MDB/PDO was being used.
Duncan