mattd8752 Posted January 26, 2007 Share Posted January 26, 2007 Well, Im not positive, but I believe that PHP is misinterpreting what I am telling it to do. I don't quite get how, but I'll show you a bit of code and what it is supposed to do:[code] $usrid = 0; $sql = "SELECT * FROM userdata"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ $currid = $row['id']; if($usrid < $currid){ $usrid = $currid; } }$usrid = $usrid + "1"; $carid = 0; $sql = "SELECT * FROM userdata"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ if($carid < $row['carid']){ $carid = $row['carid']; } }$carid = $carid + "1"; $sql = "SELECT * FROM salecars"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ if($carid = $row['carid']){ $carname = $row['name']; if($row['type'] != "beginner"){ echo "Stop trying to cheat.</div><div id=\"footer\"><b>".$onlinet."</b></div>"; die(); } } } mysql_query("INSERT INTO userdata (id,owner,cash,carid) VALUES ('".$usrid."','".$userdata['username']."','10000', '".$carid."')");echo mysql_error(); mysql_query("INSERT INTO car (carid,name,owner) VALUES ('".$carid."','".$carname."','".$userdata['username']."')");echo mysql_error();[/code]That code basically assigns IDs to be inserted into the database. I am getting their UserID fine, however when I look in the database, their carid in both the car and userdata database is = 11.If someone could fix this please try. If you need to see the whole code just ask, but just a warning it has 300 and something lines, and it is a bit messy since I coded it all tonight (without a break from this file). Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 26, 2007 Author Share Posted January 26, 2007 Im just curious if anyone knows, would it work if I made the car select a second page? If so, or you can think of any "rebuilds" to fix this please tell me. Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 26, 2007 Share Posted January 26, 2007 you know you can do " SELECT * FROM salecars WHERE carid='$carid' " right? Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 26, 2007 Author Share Posted January 26, 2007 I know, I guess I didn't think of that but, That isn't the problem though. The problem is getting the IDs from the database. I always get 11 from the car part. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 Because you loop through. I bet you have 10 cars, right? Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 26, 2007 Author Share Posted January 26, 2007 Nope, NONE. I've tried multiple times. Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 26, 2007 Author Share Posted January 26, 2007 Forgot to mention, if I add another car they will both have 11 as their carid and both have the 11th car. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 26, 2007 Share Posted January 26, 2007 Your carid (as well as userid, any 'id') should really be an auto-incrementing ID, in which case you wouldn't need to find out the most recent ID and insert it - this is pretty poor design. Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 26, 2007 Author Share Posted January 26, 2007 I know it isn't designed properly, this is because PHPbb is intergrated with my site so about half the stuff is in 1 database half in another. Please just try and help me fix this because if I were to do auto incrementing IDs it would screw up all of my code leaving me with another 15-20 hours of coding (which would normally take ten times as long as this one on my schedule). Quote Link to comment Share on other sites More sharing options...
dgiberson Posted January 26, 2007 Share Posted January 26, 2007 your problem is you are concatenating the variable not making an addition.$usrid = 0;This:$usrid = $usrid + "1";Should be:$usrid = $usrid + 1;or $usrid++;Same thing goes for the cars..... Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 26, 2007 Author Share Posted January 26, 2007 That works the exact same with $userid++ and $carid++, userid is working and carid isn't. I have no idea why. Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 26, 2007 Author Share Posted January 26, 2007 Bump, could someone explain how I would change this script:[code]<?phpdefine('IN_PHPBB', true);$site_root_path = './'; //<-- Modify$phpbb_root_path2 = '/forum/'; //<-- Modify $phpbb_root_path = $site_root_path . $phpbb_root_path2;include($phpbb_root_path . 'extension.inc');include($phpbb_root_path . 'common.php');include($phpbb_root_path . 'config.php');$userdata = session_pagestart($user_ip, PAGE_INDEX);init_userprefs($userdata);//login checkif($userdata['session_logged_in']){}else{echo "Please <a href=\"".$phpbb_root_path."/login.php\">login</a>";die();} //private message checkif ( $userdata['user_new_privmsg'] ){$l_message_new = ( $userdata['user_new_privmsg'] == 1 ) ? $lang['New_pm'] : $lang['New_pms'];$l_privmsgs_text = sprintf($l_message_new, $userdata['user_new_privmsg']);if ( $userdata['user_last_privmsg'] > $userdata['user_lastvisit'] ){$sql = "UPDATE " . USERS_TABLE . "SET user_last_privmsg = " . $userdata['user_lastvisit'] . "WHERE user_id = " . $userdata['user_id'];if ( !$db->sql_query($sql) ){message_die(GENERAL_ERROR, 'Could not update private message new/read time for user', '', __LINE__, __FILE__, $sql);}$s_privmsg_new = 1;$icon_pm = $images['pm_new_msg'];}else{$s_privmsg_new = 0;$icon_pm = $images['pm_no_new_msg'];} }else{$l_privmsgs_text = $lang['No_new_pm'];$s_privmsg_new = 0;$icon_pm = $images['pm_no_new_msg'];}if ( $userdata['user_unread_privmsg'] ){$l_message_unread = ( $userdata['user_unread_privmsg'] == 1 ) ? $lang['Unread_pm'] : $lang['Unread_pms'];$l_privmsgs_text_unread = sprintf($l_message_unread, $userdata['user_unread_privmsg']);}else{$l_privmsgs_text_unread = $lang['No_unread_pm'];} //private message check finish$user_forum_sql = ( !empty($forum_id) ) ? "AND ( u.user_session_page = $forum_idOR s.session_page = $forum_id)" : "";$sql = "SELECT u.username, u.user_id, u.user_allow_viewonline, u.user_level, s.session_logged_in, s.session_ipFROM ".USERS_TABLE." u, ".SESSIONS_TABLE." sWHERE u.user_id = s.session_user_idAND ( s.session_time >= ".( time() - 300 ) . "OR u.user_session_time >= " . ( time() - 300 ) . " )$user_forum_sqlORDER BY u.username ASC";$result = $db->sql_query($sql);if(!$result){message_die(GENERAL_ERROR, "Couldn't obtain user/online information.", "", __LINE__, __FILE__, $sql);}$userlist_ary = array();$userlist_visible = array();$logged_visible_online = 0;$logged_hidden_online = 0;$guests_online = 0;$online_userlist = "";$prev_user_id = 0;$prev_session_ip = 0;while( $row = $db->sql_fetchrow($result) ){// User is logged in and therefor not a guestif( $row['session_logged_in'] ){// Skip multiple sessions for one userif( $row['user_id'] != $prev_user_id ){$style_color = "";if( $row['user_level'] == ADMIN ){$row['username'] = '<b>' . $row['username'] . '</b>';$style_color = 'style="color:#' . $theme['fontcolor3'] . '"';}else if( $row['user_level'] == MOD ){$row['username'] = '<b>' . $row['username'] . '</b>';$style_color = 'style="color:#' . $theme['fontcolor2'] . '"';}if( $row['user_allow_viewonline'] ){$user_online_link = '<a href="' . append_sid($phpbb_root_path2."profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'>' . $row['username'] . '</a>';$logged_visible_online++;}else{$user_online_link = '<a href="' . append_sid($phpbb_root_path."profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=" . $row['user_id']) . '"' . $style_color .'><i>' . $row['username'] . '</i></a>';$logged_hidden_online++;}if( $row['user_allow_viewonline'] || $userdata['user_level'] == ADMIN ){$online_userlist .= ( $online_userlist != "" ) ? ", " . $user_online_link : $user_online_link;}}}else{if( $row['session_ip'] != $prev_session_ip ){$guests_online++;}}$prev_user_id = $row['user_id'];$prev_session_ip = $row['session_ip'];}if( empty($online_userlist) ){$online_userlist = $lang['None'];}$online_userlist = ( ( isset($forum_id) ) ? $lang['Browsing_forum'] : $lang['Registered_users'] ) . " " . $online_userlist;$online_userlist = "<span style=\"background-color: #C0C0C0\">" . $online_userlist . "</span>";$total_online_users = $logged_visible_online + $logged_hidden_online + $guests_online;if($total_online_users > $board_config['record_online_users']){$sql = "UPDATE " . CONFIG_TABLE . "SET config_value = '$total_online_users'WHERE config_name = 'record_online_users'";if( !$result = $db->sql_query($sql) ){message_die(GENERAL_ERROR, "Couldn't update online user record (nr of users)", "", __LINE__, __FILE__, $sql);}$sql = "UPDATE " . CONFIG_TABLE . "SET config_value = '" . time() . "'WHERE config_name = 'record_online_date'";if( !$result = $db->sql_query($sql) ){message_die(GENERAL_ERROR, "Couldn't update online user record (date)", "", __LINE__, __FILE__, $sql);}$board_config['record_online_users'] = $total_online_users;$board_config['record_online_date'] = time();}if( $total_online_users == 0 ){$l_t_user_s = $lang['Online_users_zero_total'];}else if( $total_online_users == 1 ){$l_t_user_s = $lang['Online_user_total'];}else{$l_t_user_s = $lang['Online_users_total'];}if( $logged_visible_online == 0 ){$l_r_user_s = $lang['Reg_users_zero_total'];}else if( $logged_visible_online == 1 ){$l_r_user_s = $lang['Reg_user_total'];}else{$l_r_user_s = $lang['Reg_users_total'];}if( $logged_hidden_online == 0 ){$l_h_user_s = $lang['Hidden_users_zero_total'];}else if( $logged_hidden_online == 1 ){$l_h_user_s = $lang['Hidden_user_total'];}else{$l_h_user_s = $lang['Hidden_users_total'];}if( $guests_online == 0 ){$l_g_user_s = $lang['Guest_users_zero_total'];}else if( $guests_online == 1 ){$l_g_user_s = $lang['Guest_user_total'];}else{$l_g_user_s = $lang['Guest_users_total'];}$l_online_users = sprintf($l_t_user_s, $total_online_users);$l_online_users .= sprintf($l_r_user_s, $logged_visible_online);$l_online_users .= sprintf($l_h_user_s, $logged_hidden_online);$l_online_users .= sprintf($l_g_user_s, $guests_online);mysql_close();include "dbconnect.php";$onlinet = "$l_online_users<br>$online_userlist<br>"; ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>F1 Simulator</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><style type="text/css">* { margin:0; padding:0; }BODY { background-color:#651;font-size:16px; }a { color:#807859;text-decoration:none; }a:hover { text-decoration:underline; }#header { background-color:#BFAC60;padding:8px; }#left { float:left;width:200px;padding:8px;background-color:#dc8; }#right { float:right;width:200px;padding:8px;background-color:#dda }#center { margin-right:215px;margin-left:215px;padding:8px;background-color:#eec; }#footer { clear:both;background-color:#CCC08F;padding:8px; }#left, #right, #center { height: 400px;}#wrapper { overflow:hidden; }</style></head><body><div id="header"><h1>F1 Racing Simulator</h1></div><div id="left"><b>Menu</b><br><?phpinclude "menu.php";?></div><div id="right"><b>Private Messages</b><br><a href="<?php echo $phpbb_root_path2; ?>privmsg.php?folder=inbox"><?php echo $l_privmsgs_text; ?></a></div><div id="center"><?phpif(!isset($_POST['submit'])){?><p><b>Welcome <?php echo $userdata['username']; ?>!</b></p><br><br><h1>Team Setup</h1><br>Please fill in the following...<br><FORM action="setupteam.php" method="post">Your Desired Team Name: <input type="text" name="teamname"><br>Your Desired Starting Car: <select name="carid"> <?php $result = mysql_query("select * from salecars WHERE type = 'beginner'"); //grab all the content while($r=mysql_fetch_array($result)) { $name=$r["name"]; $id=$r["carid"]; //display the car echo "<option value = \"".$id."\">".$name."</option>"; } ?></select><br><INPUT type="submit" name="submit" value="Set Up My Team"></FORM><?}else{ echo "Attempting to SetUp your car...<br>"; //time to check if they've got a team already (they're trying to get a free car)...$found = mysql_result(mysql_query('SELECT count(0) FROM `userdata` WHERE `owner` = "'.$userdata['username'].'" LIMIT 1'), 0, 0); if ( $found > 0 ){ echo ("You already have a racing team...</div><div id=\"footer\"><b>".$onlinet."</b></div>"); die(); }else{ $usrid = 0; $sql = "SELECT * FROM userdata"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ $currid = $row['id']; if($usrid < $currid){ $usrid = $currid; } }$usrid++; $carid = 0; $sql = "SELECT * FROM userdata"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ if($carid < $row['carid']){ $carid = $row['carid']; } }$carid++; $sql = "SELECT * FROM salecars"; $query = mysql_query($sql); while($row = mysql_fetch_array($query)){ if($carid = $row['carid']){ $carname = $row['name']; if($row['type'] != "beginner"){ echo "Stop trying to cheat.</div><div id=\"footer\"><b>".$onlinet."</b></div>"; die(); } } } mysql_query("INSERT INTO userdata (id,owner,cash,carid) VALUES ('".$usrid."','".$userdata['username']."','10000', '".$carid."')");echo mysql_error(); mysql_query("INSERT INTO car (carid,name,owner) VALUES ('".$carid."','".$carname."','".$userdata['username']."')");echo mysql_error(); echo "Your racing team is now setup! Good luck! Please return to the <a href=\"main.php\">home page</a>"; }}?></div><div id="footer"><b><?php echo $onlinet; ?></b></div></body></html>[/code]to use auto incrementing ID please. Im not quite sure how that would work. For those who need to see the DB structure the SQL is as follows:[code]-- phpMyAdmin SQL Dump-- version 2.9.0.2-- http://www.phpmyadmin.net-- -- Host: localhost-- Generation Time: Jan 26, 2007 at 05:19 PM-- Server version: 4.1.21-- PHP Version: 4.4.2-- -- Database: `mattd_racingdb`-- -- ---------------------------------------------------------- -- Table structure for table `car`-- CREATE TABLE `car` ( `carid` varchar(255) NOT NULL default '', `name` varchar(255) NOT NULL default '', `owner` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `car`-- INSERT INTO `car` VALUES ('11', 'Super Aguri-Honda', 'Admin');-- ---------------------------------------------------------- -- Table structure for table `carbrakesuspension`-- CREATE TABLE `carbrakesuspension` ( `carid` varchar(255) NOT NULL default '', `frictionkv` varchar(255) NOT NULL default '', `frontbrake` varchar(255) NOT NULL default '', `backbrake` varchar(255) NOT NULL default '', `handbrake` varchar(255) NOT NULL default '', `autoclutchbrake` varchar(255) NOT NULL default '', `frontspring` varchar(255) NOT NULL default '', `backspring` varchar(255) NOT NULL default '', `frontdamper` varchar(255) NOT NULL default '', `backdamper` varchar(255) NOT NULL default '', `frontantirollbar` varchar(255) NOT NULL default '', `backantirollbar` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `carbrakesuspension`-- -- ---------------------------------------------------------- -- Table structure for table `carengine`-- CREATE TABLE `carengine` ( `carid` varchar(255) NOT NULL default '', `maxspeedrpm` varchar(255) NOT NULL default '', `points` varchar(255) NOT NULL default '', `currentpoint` varchar(255) NOT NULL default '', `currentpointspeed` varchar(255) NOT NULL default '', `currentpointtorque` varchar(255) NOT NULL default '', `maxfrictiontorque` varchar(255) NOT NULL default '', `frictionkv` varchar(255) NOT NULL default '', `momentofinertia` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `carengine`-- -- ---------------------------------------------------------- -- Table structure for table `cargearbox`-- CREATE TABLE `cargearbox` ( `carid` varchar(255) NOT NULL default '', `drivenwheels` varchar(255) NOT NULL default '', `frictionkv` varchar(255) NOT NULL default '', `numberofgears` varchar(255) NOT NULL default '', `1` varchar(255) NOT NULL default '', `2` varchar(255) NOT NULL default '', `3` varchar(255) NOT NULL default '', `4` varchar(255) NOT NULL default '', `5` varchar(255) NOT NULL default '', `6` varchar(255) NOT NULL default '', `final` varchar(255) NOT NULL default '', `reverse` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `cargearbox`-- -- ---------------------------------------------------------- -- Table structure for table `cartyres`-- CREATE TABLE `cartyres` ( `carid` varchar(255) NOT NULL default '', `frontreactionspring` varchar(255) NOT NULL default '', `backreactionspring` varchar(255) NOT NULL default '', `frontfrictionkv` varchar(255) NOT NULL default '', `backfrictionkv` varchar(255) NOT NULL default '', `frontcoefficientoffriction` varchar(255) NOT NULL default '', `backcoefficientoffriction` varchar(255) NOT NULL default '', `frontpoints` varchar(255) NOT NULL default '', `backpoints` varchar(255) NOT NULL default '', `frontshapefactor` varchar(255) NOT NULL default '', `backshapefactor` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `cartyres`-- -- ---------------------------------------------------------- -- Table structure for table `carwheelsuspensionsteering`-- CREATE TABLE `carwheelsuspensionsteering` ( `carid` varchar(255) NOT NULL default '', `frontcamber` varchar(255) NOT NULL default '', `backcamber` varchar(255) NOT NULL default '', `fronttoe` varchar(255) NOT NULL default '', `backtoe` varchar(255) NOT NULL default '', `frontsuspensionxangle` varchar(255) NOT NULL default '', `backsuspensionxangle` varchar(255) NOT NULL default '', `frontsuspensionyangle` varchar(255) NOT NULL default '', `backsuspensionyangle` varchar(255) NOT NULL default '', `steeringxangle` varchar(255) NOT NULL default '', `steeringyangle` varchar(255) NOT NULL default '', `fulllockangle` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `carwheelsuspensionsteering`-- -- ---------------------------------------------------------- -- Table structure for table `parts`-- CREATE TABLE `parts` ( `name` varchar(255) NOT NULL default '', `cost` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `parts`-- INSERT INTO `parts` VALUES ('Monocoque', '117900');INSERT INTO `parts` VALUES ('Bodywork', '35000');INSERT INTO `parts` VALUES ('Rear wings', '20000');INSERT INTO `parts` VALUES ('Front wings', '18750');INSERT INTO `parts` VALUES ('Engine', '214300');INSERT INTO `parts` VALUES ('Gearbox', '128600');INSERT INTO `parts` VALUES ('Exhaust', '11600');INSERT INTO `parts` VALUES ('Telemetrie', '107150');INSERT INTO `parts` VALUES ('Fire extinguisher', '3200');INSERT INTO `parts` VALUES ('Brake discs', '6200');INSERT INTO `parts` VALUES ('Brake pads', '3600');INSERT INTO `parts` VALUES ('Brake calipers', '23000');INSERT INTO `parts` VALUES ('Wheels (set)', '4120');INSERT INTO `parts` VALUES ('Tyre', '1000');INSERT INTO `parts` VALUES ('Shock absorber (set)', '5200');INSERT INTO `parts` VALUES ('Pedals', '2200');INSERT INTO `parts` VALUES ('Dashboard', '3200');INSERT INTO `parts` VALUES ('Steering', '4300');INSERT INTO `parts` VALUES ('Mirrors', '1300');INSERT INTO `parts` VALUES ('Steering wheel', '39000');INSERT INTO `parts` VALUES ('Tank', '10700');INSERT INTO `parts` VALUES ('Under work', '8600');INSERT INTO `parts` VALUES ('Suspension', '40000');INSERT INTO `parts` VALUES ('Driver''s seat', '3000');INSERT INTO `parts` VALUES ('Stickers', '1600');INSERT INTO `parts` VALUES ('Other Components', '43000');-- ---------------------------------------------------------- -- Table structure for table `salecars`-- CREATE TABLE `salecars` ( `carid` varchar(255) NOT NULL default '', `type` varchar(255) NOT NULL default '', `name` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `salecars`-- INSERT INTO `salecars` VALUES ('1', 'beginner', 'Renault F1');INSERT INTO `salecars` VALUES ('2', 'beginner', 'Ferrari');INSERT INTO `salecars` VALUES ('3', 'beginner', 'McLaren-Mercedes');INSERT INTO `salecars` VALUES ('4', 'beginner', 'Honda');INSERT INTO `salecars` VALUES ('5', 'beginner', 'Sauber-BMW');INSERT INTO `salecars` VALUES ('6', 'beginner', 'Toyota');INSERT INTO `salecars` VALUES ('7', 'beginner', 'Red Bull Racing-Ferrari');INSERT INTO `salecars` VALUES ('8', 'beginner', 'Williams-Cosworth');INSERT INTO `salecars` VALUES ('9', 'beginner', 'Scuderia Toro Rosso');INSERT INTO `salecars` VALUES ('10', 'beginner', 'SpykerMF1-Toyota');INSERT INTO `salecars` VALUES ('11', 'beginner', 'Super Aguri-Honda');-- ---------------------------------------------------------- -- Table structure for table `teams`-- CREATE TABLE `teams` ( `owner` varchar(255) NOT NULL default '', `name` varchar(255) NOT NULL default '', `carid` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `teams`-- -- ---------------------------------------------------------- -- Table structure for table `userdata`-- CREATE TABLE `userdata` ( `id` varchar(255) NOT NULL default '', `owner` varchar(255) NOT NULL default '', `cash` varchar(255) NOT NULL default '', `carid` varchar(255) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;-- -- Dumping data for table `userdata`-- INSERT INTO `userdata` VALUES ('1', 'Admin', '10000', '11');[/code]Please help if you can. Thats all I have that I can provide ATM. If you noticeINSERT INTO `userdata` VALUES ('1', 'Admin', '10000', '11');that carid is 11. It should be assigned in order. And I dropped other users to retry the script. ID does workPlease don't quote my source, I plan to EDIT it out. Quote Link to comment Share on other sites More sharing options...
mattd8752 Posted January 26, 2007 Author Share Posted January 26, 2007 Could anyone link me to a tutorial or tell me how I would use incrementing IDs Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 26, 2007 Share Posted January 26, 2007 You are setting id and carid's datatype to a string (VARCHAR) These columns should have their data types set to INT not VARCHAR. If your column is VARCHAR then any data in that column is treated as a string - even if its a number.When its INT the data will be treated as an interger not a string. So when you are doing this:[code]$usrid = $usrid + "1";// OR$carid = $carid + "1";[/code]What you are telling PHP is to add the [b]string[/b] 1 to the end of the [b]string[/b] in $carid so you will be getting 11 all the time. PHP wont add the numbers! In order for PHP to treat it as a number you need change the id and carid data types to INT and remove the quotes from 1.So this will be your query when you create your userdata table:[code]CREATE TABLE `userdata` ( `id` INT(11) NOT NULL default '', `owner` varchar(255) NOT NULL default '', `cash` varchar(255) NOT NULL default '', `carid` INT(11) NOT NULL default '') ENGINE=MyISAM DEFAULT CHARSET=latin1;[/code]to change you code so the id column autoincrements you need to change your SQL query for the id column to this:[code]`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY[/code]MySQL will now increase the id by one automatically when ever you add an entry to the usertable. Quote Link to comment Share on other sites More sharing options...
dgiberson Posted January 26, 2007 Share Posted January 26, 2007 omg whats up with the varchars..... datatypes man! datatypes! 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.