0

I wrote a little script for read data from mysql . but i've a little problem ,

this is my code :

    <?php
$con=mysql_connect('localhost','user','pass');
mysql_query("set names utf8");
mysql_query("set charset utf8");
mysql_set_charset('utf8');  
mysql_select_db('dbname',$con);
$query="SELECT * FROM profiles where user_id=11";
$select=mysql_query($query);
while($row=mysql_fetch_array($select)){
echo $row['value'].'  '.'';
}
mysql_close($con);

?>

for now , the script read value of column user_id = 11 , I've another column " key " , how can i read data from this row if , user_id = 11 and key = Age ?

can you help me about this issue ?

Thank you

5
  • and key = 'Age' or something like that. Commented Feb 14, 2015 at 20:57
  • I've been tried this before , but i do not give any answer , blank page :( thank you Commented Feb 14, 2015 at 21:04
  • i've tried this on phpmyadmin , I see ERRoR : " #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'key=Age ORDER BY profiles.user_id ASC LIMIT 0, 30' at line 1 " Commented Feb 14, 2015 at 21:13
  • 2
    key is a reserved word Commented Feb 14, 2015 at 21:14
  • is there any way for resolve this issue ? :( Commented Feb 14, 2015 at 21:23

2 Answers 2

2

use

`key`='Age'

KEY is reserved word in mysql

Sign up to request clarification or add additional context in comments.

5 Comments

THank you , so how can i resolve this issue ? i can't change the column name
I've used this , i still see Error : 1064
Please post whole query.
No no , I've wrote profile for example :D Real Code I've tested in phpmyadmin is : SELECT * FROM haevm_userxtd_profiles WHERE user_id=853 key='BASIC_FATHER'
Excellent , I've used this on phpmyadmin and it works , but on php script , i did not recived any answer :D BUT BUT , i See this On php myadmin show query box : SELECT * FROM haevm_userxtd_profiles WHERE user_id =853 AND key = 'BASIC_FATHER' ORDER BY haevm_userxtd_profiles.user_id ASC LIMIT 0 , 30 and i've used it on php script too :D NOW The problem Has been SOlved :X THank youuu
0

Change the echo $row['value']. Instead of the word value, use the column name.

1 Comment

Hello , the value is the column name :D also when i try this without include the key , I see the response without any problem . i just need it to limit by key . age , mob , date and etc ... . for now . it's print all of information saved in all keys . all rows with user_id 11 . i've many rows with this user ID . but all of them have an extra key name .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.