By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,631 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,631 IT Pros & Developers. It's quick & easy.

sql query with php problem

sanjay123456
100+
P: 125
Dear friends ,

How i write this query in mysql

data r following
$que=$_POST['que'];

$quiz=$_POST['quiz'];

its variable inserted in to mysql is following query correct or not

mysql_query("INSERT INTO result(que,ans)
VALUES ($que,$quiz)");

sanjay
Feb 3 '07 #1
Share this Question
Share on Google+
4 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Yes, but when the fields have data type character, you better store the values between single quotes, like this
Expand|Select|Wrap|Line Numbers
  1. mysql_query("INSERT INTO result(que,ans) 
  2. VALUES ('$que', '$quiz')");
Ronald :cool:
Feb 3 '07 #2

sanjay123456
100+
P: 125
Sir ,

thx ur quick reply sir
plz tell me that both que and quiz are as a interger and both r coming integer
and in mysql table i aslo declare int can i convert both in int or they r in int in php page

because in jsp everything in form of string

sanjay
Feb 3 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
When both $que and $quiz are integers your original INSERT statement is correct. I.e.
Expand|Select|Wrap|Line Numbers
  1. mysql_query("INSERT INTO result(que,ans) 
  2. VALUES ($que,$quiz)");
Ronald :cool:
Feb 3 '07 #4

P: 24
and you should quote the any input by user, for security reason.
check for get_magic_quotes_gpc() and mysql_real_escape_string();
Feb 6 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.