I have a problem with my query, it returns nothing.
if($champ == "type_id")
{
$bdd = new PDO("mysql:dbname=maruecondi_db;host=localhost","root","");
$request = $bdd->prepare('SELECT * FROM type_commercant WHERE type=:old');
$request->execute(array(':old' => $old));
while($row = $request->fetch())
{
$bdd1 = new PDO("mysql:dbname=maruecondi_db;host=localhost","root","");
$request1 = $bdd1->prepare('UPDATE commercant SET type_id=:type_id WHERE id=:id');
$request1->execute(array(':type_id' => $row['id'],':id' => $id));
}
}
I'm getting variables from ajax request (JQUERY) and i initialize them before, i avoid you the code. Other requests on the page works. I have currently no way to see if somethings got wrong, due to ajax call. (No php orange boxes / pdo message) I tried to solve to problems, and i discovered that we go into the if. I deleted the first query which contains the while, i replaced $row['id'] by a value, and i worked. Since the beginning, i keep copying and pasting the connection to my database so no problem.
So my problem is here:
$request = $bdd->prepare('SELECT * FROM type_commercant WHERE type=:old');
$request->execute(array(':old' => $old));
while($row = $request->fetch())
I don't see what i've done wrong...
$request = $bdd->prepare('SELECT * FROM type_commercant');
$request->execute();
while($row = $request->fetch())
This works, so i tried this:
$request = $bdd->prepare('SELECT * FROM type_commercant');
$request->execute();
while($row = $request->fetch())
{
if($row['type'] == $old)
{
$request1 = $bdd->prepare('UPDATE commercant SET type_id=:type_id WHERE id=:id');
$request1->execute(array(':type_id' => $row['id'],':id' => $id));
}
}
We don't go in the condition if($row['type'] == $old), but i delete this condition, and when i replace with something like this:
while($row = $request->fetch())
{
$request1 = $bdd->prepare('UPDATE commercant SET adresse=:type_id WHERE id=:id');
$request1->execute(array(':type_id' => $row['id'],':id' => $id));
}
It works... i checked $row['type'], $row['id'], $old in array(':type_id' => $row['id'], all variable got the string attented. So what's the problem? Thanks in advance !