DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   PHP (http://www.daniweb.com/forums/forum17.html)
-   -   generating random id and save it into db (http://www.daniweb.com/forums/thread160519.html)

mm2409 Dec 3rd, 2008 5:13 am
generating random id and save it into db
 
dear frnds,

i hace wrote this code to generate unique id for questionnaire and a query to save it into database with two more value (response id and date)

individually i have checked and unique id function is working.
even insert query is also executing correctly.

but when i put it whole into my php file it doesnt save values into DB.

please help to sort it out. i m in hurry.

code is here:

$que_id = uniqid(que);
echo $que_id;
echo "<br>";

$db->query("INSERT INTO tbl_CT_Responses (Response_ID,Questionnaire_ID,Response_Date)
VALUES (".GetSQLValueString("",`int`).","
.GetSQLValueString($que_id,`int`).","
.GetSQLValueString(date('Y-m-d'),`date`)
.")");

echo "The questionnaire ID is inserted successfully";
?>

chrisranjana Dec 3rd, 2008 9:24 am
Re: generating random id and save it into db
 
Why don't you generate some MD5 hash for random numbers yourself ?

mm2409 Dec 3rd, 2008 9:33 am
Re: generating random id and save it into db
 
i can use MD5 hash for random numbers (even i m using it ) but the problem is data is not inserting into db.also not showing any error.

till now cudnt find the reason.


Quote:

Originally Posted by chrisranjana (Post 749408)
Why don't you generate some MD5 hash for random numbers yourself ?


xarz Dec 3rd, 2008 8:49 pm
Re: generating random id and save it into db
 
you should try echoing the query first just to check that it really works out

echo "INSERT INTO tbl_CT_Responses (Response_ID,Questionnaire_ID,Response_Date)
VALUES (".GetSQLValueString("",`int`).","
.GetSQLValueString($que_id,`int`).","
.GetSQLValueString(date('Y-m-d'),`date`)
.")"

mm2409 Dec 4th, 2008 1:57 am
Re: generating random id and save it into db
 
i did ..it gives result object id #2

xarz Dec 4th, 2008 3:14 am
Re: generating random id and save it into db
 
have you to tried to check the mysql errors?

echo mysql_error();

or an alternative to the insert statement

$db->query("INSERT INTO tbl_CT_Responses 
SET
Response_ID=".GetSQLValueString("",`int`).",
Questionnaire_ID=".GetSQLValueString($que_id,`int`).",
Response_Date=".GetSQLValueString(date('Y-m-d'),`date`)."
");

hope it will work out for you.

xarz Dec 4th, 2008 3:19 am
Re: generating random id and save it into db
 
i spotted something also which perhaps can solve your problem
$que_id = uniqid(que);

should be

$que_id = uniqid($que);


All times are GMT -4. The time now is 5:49 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC