I run $search query which returns no. of rows and using if Else statement
If (no. of rows>0{
Update The row where symbol=123;
}else{
Insert new row
}
I am able to run the query successfully. I have a column with value (id(primary), name and symbol). I would like to update row value if symbol=123; and insert if it is different then 123.
I am able to insert new row when I enter different symbol but unable to update value although executes successfully if symbol no is same.
Here is my code
$sql="SELECT * FROM entrance WHERE symbol='15369-2017-02'";
$STH = $db->prepare($sql);
$STH->execute(array(symbol));
$User = $STH->fetch();
if (!empty($User)){
$sql = "UPDATE entrance SET name ='Sagar Rawal'
WHERE symbol='15369-2017-02'";
$q = $db->prepare($sql);
$q->execute($sql);
}
else{
$sql = "INSERT INTO entrance(name,symbol) VALUES (:a,:b)";
$q = $db->prepare($sql);
$q->execute(array(':a'=>$a,':b'=>$b));
}
But when I run from Mysql command panel below code
UPDATE entrance SET name="Ritish Karki" WHERE symbol="15369-2017-02"
Then value change successfully. Any help?