Page 2 of 2

Posted: Tue Jan 31, 2006 5:09 am
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!!!";
}
?>

Posted: Fri Feb 03, 2006 3:41 am
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. :(

Posted: Fri Feb 03, 2006 4:49 am
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...

Posted: Mon Feb 06, 2006 3:02 am
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.

Posted: Mon Feb 06, 2006 3:47 am
by raghavan20
two problems.
1. smallint does not support the integer generated
2. you are inserting smallint value in quotes

Posted: Mon Feb 06, 2006 9:37 am
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.

Posted: Tue Feb 07, 2006 5:42 am
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

Posted: Tue Feb 07, 2006 8:43 am
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.

Posted: Thu Feb 09, 2006 3:41 am
by rsmarsha
Thanks :) Solved the problem.