1

I am trying to work with a voting database system. I have a form to display all the candidates per candidate type. I'm still trying to to explore that. But this time, I want to try one candidate type, lets say for Chairperson, I want to display all candidate names for that type in the ballot form. However, there's an error with the line where i declare $query and made query statements, can somebody know what it is. I am very certain that my syntax is correct.

 function returnAllFromTable($table) {
 include 'connect.php';
 $data = array ();
 $query = 'SELECT * FROM ' . $table. 'WHERE candidateId=1'; //ERROR
 $mysql_query = mysql_query ( $query, $conn );
 if (! $mysql_query) {
 die ( '<a href="../../">Go Back</a><br>Unable to retrieve data from table ' . $table );
 } else {
 while ( $row = mysql_fetch_array ( $mysql_query ) ) {
 $data [] = $row;
 }
 }
 return $data;
 }
Adrian Cid Almaguer
7,79113 gold badges44 silver badges66 bronze badges
asked Dec 4, 2015 at 3:02
1
  • You're probably missing a space between the table name and WHERE. Try calling print_r($query) to see what's actually in there. Also, don't use mysql driver yada yada obsolete yada use mysqli or PDO. Commented Dec 4, 2015 at 3:08

1 Answer 1

1

As @Darwin von Corax says, I sure that you have a problem between $table and WHERE

Your query:

$query = 'SELECT * FROM ' . $table. 'WHERE candidateId=1';

If $table = 'Chairperson';

You have:

'SELECT * FROM ChairpersonWHERE candidateId=1';

The your query should be:

 $query = 'SELECT * FROM ' . $table. ' WHERE candidateId=1';
answered Dec 4, 2015 at 3:42
Sign up to request clarification or add additional context in comments.

1 Comment

@adrianquevada a plasure ;-)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.