Page 1 of 2

id problem

Posted: Wed Jan 25, 2006 5:55 am
by rsmarsha

Code: Select all

$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 ('','$create_id','$mail','$datejoined','$type','','$_POST[price]','$_POST[exvat2]','Finance','$_POST[quantity]','$_POST[discount]','$_POST[final]','$_POST[extotal]','$_POST[deldet]','$refer','','')";
$enterq = mysql_query($enterorder, $db_conn) or die("Query enter order failed".mysql_error());
The above code enters an id using the variable $create_id, for some reason it enters 32767 all the time. If i change the variable name to an undefined variable it enters 0 as it should, but no matter what i call the variable when defining it, the result is the same number. What makes this even more confusing is that the line above this code echo's the variable onto the page and it shows the correct id.

Posted: Wed Jan 25, 2006 7:05 am
by raghavan20
show us the code for generating the id. Is the id a string because I see you using quotes around it?

Posted: Wed Jan 25, 2006 6:29 pm
by rsmarsha
The id is a number, this number is pulled from another table. If old user from user table, new user same table using mysql_insert_id().

The id is generated correctly as if i place an echo for the id on the line above the code i posted, it echo's the correct id.

Re: id problem

Posted: Wed Jan 25, 2006 6:39 pm
by raghavan20
rsmarsha wrote:

Code: Select all

$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 ('','$create_id','$mail','$datejoined','$type','','$_POST[price]','$_POST[exvat2]','Finance','$_POST[quantity]','$_POST[discount]','$_POST[final]','$_POST[extotal]','$_POST[deldet]','$refer','','')";
$enterq = mysql_query($enterorder, $db_conn) or die("Query enter order failed".mysql_error());
I just noted that you have forgot to put $ before user_id which assumes it as constant. Please use error_reporting(E_ALL) during development of an application.

Posted: Thu Jan 26, 2006 2:34 am
by rsmarsha
A $ before user_id?

So i'd have :

Code: Select all

$enterorder = "INSERT INTO orders_main (orderno,$user_id,username,dateadded
That creates errors, as the user_id is a database field.

I've also tried echo'ing every posted variable and there is nothing with the number it's entering. Also as i've said the line before echo's the variable which i'm trying to enter and it shows correct. Somehow between one line and the next the variable i'm entering changes.

Posted: Thu Jan 26, 2006 4:22 am
by rsmarsha
ok even tried :

Code: Select all

$findid = "SELECT id FROM users WHERE username='$mail'";
$idq = mysql_query($checkuser, $db_conn) or die("Query $findid failed".mysql_error());
$idrow = mysql_fetch_assoc($idq);
$userid = $idrow['id'];

echo ''.$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','','')";
	$enterq = mysql_query($enterorder, $db_conn) or die("Query enter order failed".mysql_error());
It still enters in the number even though the id is defined right above it.

Also if i remove the first query and define user id as 1 instead of idrow['id'] it works.

Posted: Thu Jan 26, 2006 4:31 am
by raghavan20

Code: Select all

$findid = "SELECT id FROM users WHERE username='$mail'"; 
$idq = mysql_query($checkuser, $db_conn) or die("Query $findid failed".mysql_error());
you should be using mysql_query($findid, $db_conn) but I see you using mysql_query($checkuser, $db_conn) :roll:

Posted: Thu Jan 26, 2006 4:35 am
by rsmarsha
changed that and it still enters 32767. :(

Posted: Thu Jan 26, 2006 4:52 am
by raghavan20

Code: Select all

$findid = "SELECT `id` FROM `users` WHERE `username` = '$mail' "; 
$idq = mysql_query($findid, $db_conn) or die("Query $findid failed".mysql_error()); 
echo "<br />Query: "$idq;
$idrow = mysql_fetch_assoc($idq); 
if (is_resource($idrow)){
	if (mysql_num_rows($idrow) > 0){
		echo "<br /> Rows returned: ". $mysql_num_rows($idrow);
		echo "<br />Before assignment - user id: ".$userid;
		$userid = $idrow['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();
	}
}
Run the above and post here the output to the browser....

Posted: Thu Jan 26, 2006 5:02 am
by rsmarsha
I got :

Query: Resource id #14

Posted: Thu Jan 26, 2006 5:36 am
by raghavan20

Code: Select 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; 
$idrow = mysql_fetch_assoc($idq); 
if (is_resource($idrow)){ 
	echo "<br /> Rows returned: ". $mysql_num_rows($idrow); 
    if (mysql_num_rows($idrow) > 0){ 
        
        echo "<br />Before assignment - user id: ".$userid; 
        $userid = $idrow['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(); 
    } 
}
It looks like it is not returning any row for the id. I forgot to put the echo statement for number of rows outside the if block...run this code again and give me the output...thanks

Posted: Fri Jan 27, 2006 3:56 am
by rsmarsha
Result: Resource id #14

Is the lastest output.

Btw thanks for all this help. :) Hopefully will get it sorted.

Posted: Mon Jan 30, 2006 4:38 am
by rsmarsha
any ideas?

Posted: Mon Jan 30, 2006 10:10 am
by John Cartwright
rsmarsha wrote:Result: Resource id #14

Is the lastest output.

Btw thanks for all this help. :) Hopefully will get it sorted.
Tell us ALL the output :wink:

Posted: Tue Jan 31, 2006 3:34 am
by rsmarsha
that is all the output.