I'm trying to get data from a specific row from my database.
And I get the error:
Unknown column 'Apalm' in 'where clause'
This is my code:
$naam = $_GET['naam'];
$result = mysql_query("SELECT * FROM planten WHERE naam = $naam")
or die(mysql_error());
And the picture below shows my database.
It seems like the script thinks the row is called "Apalm". But I clearly stated to search in 'naam'?
This is probably very easy to fix, but I just can't seem to find it on Google.
So please help me, or point me in the right direction. I'm very eager to learn this!
Thanks in advance!
naam column seems to be a text, so enclose its value between single quotes within the sql code as well:
"SELECT * FROM planten WHERE naam = '$naam'"
However, pls consider using either proper escaping or prepared statements to prevent sql injection.
I have a query which retrieves 3 columns from table which works fine in phpmyadmin
SELECT cab_id,
SUM(IF(rating=1,1,0)) as up,
SUM(IF(rating=0,1,0)) as down
FROM rating WHERE cab_id=101
table->'rating'
Can anyone help me to find how I can get this query worked using redbeanphp ?
I tried ,
R::getRow(),R::getAll(),R::$adapter->getAssoc()
none is working!!!
To check the correctness of code I tried,
SELECT * FROM rating group by cab_id having cab_id=101
and found working.But I need the first query statement to work! Any help ,please?
I got the answer finally, This one works.
$val = R::getAll($query);
I'm trying to insert a ton of rows into my MySQL database. I have a query like this, but with about 700 more repetitive entries in it but for some reason the query is only inserting the first row to the database. In this case it would be '374','4957','0'.
INSERT INTO table VALUES ('374','4957','0'),('374','3834','0'),('374','4958','0'),('374','5076','0'),('374','4921','0'),('374','3835','0'),('374','4922','0'),('374','3836','0'),('374','3837','0'),('374','4879','0'),('374','3838','0')
I can't figure out what I'm doing wrong.
Thank you in advance.
Don't mean to state the obvious, but if the first field '374' is your primary key field, than this is the issue.
Otherwise, are there any error messages received from the database? That is always a good place to look for bugs.
For better understanding why something is not working next time use code like this:
$sql = "INSERT INTO table VALUES ('374','4957','0'),('374','3834','0')";
if (!mysqli_query($link, $sql)) {
printf("Errormessage: %s\n", mysqli_error($link));
}
That should display error message returned from MySQL.
More information: PHP manual - mysqli_error
Try to write the column names before values.
For example:
INSERT INTO table (column1,column2,column3) VALUES ...
I am trying to run this query from a drop down menu, the category and the destination data are working fine, just not the subcategory, it's probably an issue with my Html or Javasscript but i wanted to get the opinion of an expert with MYSQL if poss? I am quite new to PHP and MYSQL, but learning fast, Not sure my HTML will post here so i will just ask if someone can confirm that my query should work ok. Thanks guys.
$category=$_POST['Category'];
$subcategory=$_POST['Subcategory'];
$destination=$_POST['Destination'];
$result = mysql_query("SELECT * FROM travel WHERE Category='$category' AND Subcategory='$subcategory' AND Destination='$destination'")
or die(mysql_error());
$row = mysql_fetch_array( $result ) ;
Not sure if it's a culprit in your case, but you have to escape data coming from a user before passing it to the query :
$category=mysql_real_escape_string($_POST['Category']);
$subcategory=mysql_real_escape_string($_POST['Subcategory']);
$destination=mysql_real_escape_string($_POST['Destination']);
....
I'm not completely sure what I'm doing wrong here I've looked through again and again for incorrectly placed quotes but I cannot for the life of me get this UPDATE query code to work... and I've troubleshooted it down to the query itself and it gives an incorrect syntax error, yet I have no idea what is wrong with it as it is identical to the manual.
$change = mysql_query("UPDATE Images SET Group='$group' WHERE ID = '$imgid'") or
die(mysql_error());
you might need to do :
"UPDATE Images SET `Group`='$group' WHERE ID = '$imgid'"
as group is a keyword in MySQL .
Well... if the update does not work this might have two reasons. Either your syntax is wrong; this should result in MySQL throwing an error which should show up with your die(mysql_error()).
Or there is simply no record matching your WHERE-condition. To check if any record was updated at all you might want to take a look at mysql_affected_rows(). And you could run a SELECT-query on that table, using the same WHERE-condition.
try this ..
"UPDATE Images SET Group='".$group."' WHERE ID = ".$imgid