PDA

View Full Version : Help with Modification Issues


Abronsyth
01-31-2017, 08:52 PM
Hey all, me again!

I am working on a riddle system that will quickly allow admins to create riddles, activate one at a time, and then users can answer them and get a reward once each (per riddle).

However I am getting the most obnoxious error:
Parse error: syntax error, unexpected '=' in /home/inekelmy/public_html/view/riddleview.php on line 29

Here is the code it's referring to:
$id = $mysidia->db->select("riddle", array("id"), ("name" = $mysidia->input->post("currname")))->fetchColumn();
$clue = $mysidia->db->select("riddle", array("clue"), ("name" = $mysidia->input->post("currname")))->fetchColumn();
$solve = $mysidia->db->select("riddle", array("solve"), ("name" = $mysidia->input->post("currname")))->fetchColumn();

Does anyone see where I'm messing things up?

IntoRain
01-31-2017, 10:10 PM
The entire "where" part of the query has to be inside the quotation marks. Also, you can fetch everything at once rather than making multiple calls to the database


$riddle = $mysidia->db->select("riddle", array("id", "clue", "solve"), "name = '{$mysidia->input->post('currname')}'")->fetchObject();

$id = $riddle->id;
$clue = $riddle->clue;
$solve = $riddle->solve;

Abronsyth
02-01-2017, 08:45 AM
Aaaah! Right!

Thank you so much!

Abronsyth
02-01-2017, 09:55 AM
OK one more problem.

It's this chunk of code;

$done = $mysidia->db->select("solved_riddles", array("name", "uid"), "name = '{$active}'", "uid = '$mysidia->user->uid'")->fetchColumn();
if($done){...}
else{...}

It is not doing what it is supposed to do. It is showing me the if{} content regardless of whether the uid+name are added to the table or not. The code simply adds a new row whenever someone solves a riddle, it records the riddle name and the user ID. This part is fully functioning.

The if{} statement is supposed to make it so that users who have solved see the if{} content, and users who have not see the else{} content.

If someone could point out my error here I'd be mighty thankful...and then I could run through some more tests and release the damn thing as a mod :colonu:

IntoRain
02-01-2017, 12:36 PM
I think the problem is with the syntax. Instead of


"name = '{$active}'", "uid = '$mysidia->user->uid'")->fetchColumn();


Try


"name = '{$active}' and uid = '{$mysidia->user->uid}'")->fetchObject();

Abronsyth
02-01-2017, 07:29 PM
That seems to have done the trick, thank you!