id problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

This should definitely work...earlier in the code there were some elusive errors...try this with confidence and show us the output...

Code: Select all

<?php 
error_reporting(E_ALL);

$findid = "SELECT `id` FROM `users` WHERE `username` = '$mail' ";  
$idq = mysql_query($findid, $db_conn) or die("Query $findid failed".mysql_error());  
echo "<br />Result: ".$idq;  
if (is_resource($idq)){
	echo "<br />Rows returned: ".mysql_num_rows($idq);
	if (mysql_num_rows($idq) > 0){
		echo "<br />Before assignment - user id: ".$userid;  
		$userid = mysql_result($idq, 0, "id");
		echo "<br /> After assignment - user id".$userid;  

		$type = 'Awaiting credit check';  
		$enterorder = "INSERT INTO orders_main 
		(orderno,user_id,username,dateadded,status,archive,price,exvat,payment,q,discount,total,totalexvat,deldet,refer,l_model,config)  
		VALUES ('','$userid','$mail',$datejoined','$type','','$_POST[price]','$_POST[exvat2]','Finance','$_POST[quantity]','$_POST[discount]','$_POST[final]','$_POST[extotal]','$_POST[deldet]','$refer','','')";  

		echo "<br > Insert Query: ".$enterorder;  
		mysql_query($enterorder, $db_conn) or die("Query enter order failed".mysql_error());  
		echo "Rows Affected: ".mysql_affected_rows();  
	}else{
		echo "<br />Unable to find id!!!";
	} 
}else{
	echo "<br />Is not a valid resource!!!";
}
?>
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Thanks for the reply.

Here is the output :

Code: Select all

Result: Resource id #14
Rows returned: 1
Before assignment - user id: 89826
After assignment - user id89826
Insert Query: INSERT INTO orders_main (orderno,user_id,username,dateadded,status,archive,price,exvat,payment,q,discount,total,totalexvat,deldet,refer,l_model,config) 
VALUES ('','89826','ryanmarshall@irealms.co.uk','2006-02-03','Awaiting credit check','','4921','4188.09','Finance','1','','4921','4188.09','','','','')
Rows Affected: 1
Looks like it's entering the correct id, but it still enters the phantom number. :(
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

do you mean to say that it is not entering 89826? if yes, please post the database structure of this table and I am also wondering why you are using varchar/text for an integer value...
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

I'm not using text for integer.

Structure is :

Code: Select all

CREATE TABLE `orders_main` (
  `orderno` int(20) unsigned NOT NULL auto_increment,
  `user_id` smallint(7) NOT NULL default '0',
  `username` varchar(50) NOT NULL default '',
  `dateadded` date NOT NULL default '0000-00-00',
  `status` varchar(100) NOT NULL default '',
  `archive` smallint(1) unsigned NOT NULL default '0',
  `price` decimal(5,2) NOT NULL default '0.00',
  `exvat` decimal(5,2) NOT NULL default '0.00',
  `payment` varchar(100) NOT NULL default '',
  `q` smallint(3) unsigned NOT NULL default '1',
  `discount` smallint(4) unsigned NOT NULL default '0',
  `total` decimal(8,2) unsigned NOT NULL default '0.00',
  `totalexvat` decimal(8,2) unsigned NOT NULL default '0.00',
  `deldet` text NOT NULL,
  `sub` smallint(1) unsigned NOT NULL default '0',
  `refer` varchar(250) NOT NULL default '',
  `l_model` varchar(150) NOT NULL default '',
  `config` varchar(10) NOT NULL default '',
  `proc_date` date NOT NULL default '0000-00-00',
  `proc2_date` date NOT NULL default '0000-00-00',
  `build_date` date NOT NULL default '0000-00-00',
  `test_date` date NOT NULL default '0000-00-00',
  `d_date` date NOT NULL default '0000-00-00',
  `col_date` date NOT NULL default '0000-00-00',
  `num_sub` smallint(1) NOT NULL default '0',
  `test_ap_date` date NOT NULL default '0000-00-00',
  `stock` smallint(1) NOT NULL default '0',
  `cc_tstatus` varchar(100) NOT NULL default '',
  PRIMARY KEY  (`orderno`),
  UNIQUE KEY `orderno` (`orderno`)
) TYPE=MyISAM AUTO_INCREMENT=10 ;
Also yes it is not entering the id as the output shows.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

two problems.
1. smallint does not support the integer generated
2. you are inserting smallint value in quotes
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

MySQL will do implicit conversion for quoted integers, so no worries there. But smallint does only have a range of -128 to 127, I believe.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

feyd wrote:MySQL will do implicit conversion for quoted integers, so no worries there. But smallint does only have a range of -128 to 127, I believe.
that is tinyint feyd
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

raghavan20 wrote:that is tinyint feyd
You're right, I was thinking storage size was a byte, but smallint uses a word. Therefore the range is -32768 to 32767 when signed, or 0 to 65536 unsigned.
rsmarsha
Forum Contributor
Posts: 242
Joined: Tue Feb 08, 2005 4:06 am
Location: Leeds, England

Post by rsmarsha »

Thanks :) Solved the problem.
Post Reply