Twister1004 Posted October 16, 2008 Share Posted October 16, 2008 Hey guys, I really like this forum, seems like it will be a lot of help to me, as a new coder. However, I am getting an error within my script. Before I show you the script, I would like to tell you what I am trying to do. Objective: I am trying to get the person registered as like a normal script, however, as well when they register, I am making a profile page for them as well. (Still coding it so it's not working.) So what I am trying to do is get the person registered, then get the information just entered to go into another table along with their account id. My problem: While I do this, I am getting an "Incorrect integer value: '' for column 'accountid' at row 1" accountid is a column within the table accounts. There is also another spot in the table profile for accountid as well. Conclusion: So basically this should make more since. I'm trying to take the accountid from the account newly created row from the table accounts to the table profile. Script: <?php error_reporting(E_ALL);?> <html> <head> <title>Abysmal Essence | Register - Complete</title> </head> <body> <?php $user = $_POST['user']; $name = $_POST['name']; $pass = $_POST['pass']; $vpass = $_POST['vpass']; $email = $_POST['email']; $dob = $_POST['dob']; include ("config.php"); $sel = 'SELECT * FROM `accounts` WHERE `username`="' . $_POST['user'] . '"'; //Andy edited here $result = mysql_query($sel) or die(mysql_error()); $data = mysql_fetch_assoc($result); if(mysql_num_rows($result) >0) { //echo "Username exitsts<br>"; }else{ //echo "Username Aviable<br>"; } if ($user == "") { echo 'Please enter a username.'; exit(); } elseif (mysql_num_rows(mysql_query($sel)) >= 1) { echo 'The username already exists. Please choose another name.<br>'; exit(); } elseif ($pass == "") { echo 'You did not enter a password. Please go back and enter a password.<br>'; exit(); } elseif ($vpass != $pass) { echo 'Your passwords do not match. Please re-enter your password.<br>'; exit(); } else { $con = 'INSERT INTO `accounts` (username, name, password, email, dob) VALUES ("' . $user . '", "' . $name . '", "' . $pass . '", "' . $email . '", "' . $dob . '")'; $accountid = mysql_query($account['accountid']); $account = "SELECT * FROM `accounts` WHERE `accountid` = '$accountid'"; $con2 = 'INSERT INTO `profile` (accountid, about, content, unknown) VALUES ( "'.$accountid.'","Edit me", "Edit me", "Edit me")'; mysql_query($con2) or die(mysql_error()); mysql_query($con) or die(mysql_error()); echo '<center>You have successfully created your account. You can now log in.</center>'; } ?> <br/><br/> Your account has been created.<br/> You will be e-mailed on your Login information. Please note: We have to manually send E-mails.<br/>If you are within the team for development, you will be sent an extra ID along with your login information.<br/> More info will be told when E-mails are received.<br/> <input type='button' value='Home' onclick='parent.window.location.href = "./"' /> </body> </html> Now the script I added into this would be this section: else { $con = 'INSERT INTO `accounts` (username, name, password, email, dob) VALUES ("' . $user . '", "' . $name . '", "' . $pass . '", "' . $email . '", "' . $dob . '")'; $accountid = mysql_query($account['accountid']); $account = "SELECT * FROM `accounts` WHERE `accountid` = '$accountid'"; $con2 = 'INSERT INTO `profile` (accountid, about, content, unknown) VALUES ( "'.$accountid.'","Edit me", "Edit me", "Edit me")'; mysql_query($con2) or die(mysql_error()); mysql_query($con) or die(mysql_error()); echo '<center>You have successfully created your account. You can now log in.</center>'; } Any advice or help? Thank you very much for reading / posting. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted October 16, 2008 Share Posted October 16, 2008 Now the script I added into this would be this section: else { $con = 'INSERT INTO `accounts` (username, name, password, email, dob) VALUES ("' . $user . '", "' . $name . '", "' . $pass . '", "' . $email . '", "' . $dob . '")'; $accountid = mysql_query($account['accountid']); $account = "SELECT * FROM `accounts` WHERE `accountid` = '$accountid'"; $con2 = 'INSERT INTO `profile` (accountid, about, content, unknown) VALUES ( "'.$accountid.'","Edit me", "Edit me", "Edit me")'; mysql_query($con2) or die(mysql_error()); mysql_query($con) or die(mysql_error()); echo '<center>You have successfully created your account. You can now log in.</center>'; } Any advice or help? Thank you very much for reading / posting. Well there are a few problems with that code. The first $con = 'INSERT INTO `accounts` (username, name, password, email, dob) VALUES ("' . $user . '", "' . $name . '", "' . $pass . '", "' . $email . '", "' . $dob . '")'; $accountid = mysql_query($account['accountid']); $account = "SELECT * FROM `accounts` WHERE `accountid` = '$accountid'"; mysql_query returns a result resource and nothing else. result resources cannot be used within queries. In order to get the data returned from a query you'll need to use one of the following functions: mysql_fetch_(array, assoc or row) or mysql_result You should use the following code. // define the query for inserting a new account $sql = 'INSERT INTO `accounts` (username, name, password, email, dob) VALUES '. '("' . $user . '", "' . $name . '", "' . $pass . '", "' . $email . '", "' . $dob . '")'; // create a new account $result = mysql_query($sql); // check that the query executed successfully if($result) { // now that a new account has been added we'll retrieve the accountid $accountid = mysql_insert_id(); // if you're not sure what this function does go to http://php.net/mysql_insert_id // now create a new profile $sql = 'INSERT INTO `profile` (accountid, about, content, unknown) VALUES ( "'.$accountid.'","Edit me", "Edit me", "Edit me")'; $result = mysql_query($sql); if($result) { echo '<center>You have successfully created your account. You can now log in.</center>'; } // unable to create account profile, kill the script and display an error else die('Unable to create account profile!<br />MySQL Error: '.mysql_error()); } // unable to create new account kill, the script and display an error else die('Unable to create a new account!<br />MySQL Error: '.mysql_error()); Quote Link to comment Share on other sites More sharing options...
Twister1004 Posted October 16, 2008 Author Share Posted October 16, 2008 Omg, I ran the code and I'm so happy! Could you explain it to me in dummy terms what i did wrong and how you fixed it? =D *grabs popcorn* Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.