php - Syntax error with mysql when trying to fetch data from database using options in drop down list -
when select option retrieve data db, error message:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 1.
why that? there's nothing @ line 1? also, teach me how search in retrieved data?
example. if choose option 1 "antal narvaro" , press ok-button, following sql-query execute: select * mytable fran = 'besok';
once i've retrieved data, want further search in information name, age , on. otherwise i'm grateful execute following sql-queries choosing option in drop down list press ok-button.
i'm new php , html, in advance!
<html> <head> <title>aifind</title> <link rel="stylesheet" href="style.css"> <script type="text/javascript" src="logic.js"></script> </head> <body> <h1><img src="https://imagizer.imageshack.us/v2/278x186q90/844/k32d.png" height="70" width="100" alt="aifind-logo copy"></h1> </body> </html> <?php include "connection.php"; $sql = "select"; if (isset($_post['search'])) { $search_term = mysql_real_escape_string($_post['search_box']); switch($_post['filter']) { default: $sql .= " "; break; case 1: $sql .= " * mytable fran = 'besök'; "; break; case 2: $sql .= " * mytable fran = 'bok'; "; break; case 3: $sql .= " postort, count(*) mytable aaa_diam != "; $sql .= " 'missing' group postort; "; break; case 4: $sql .= " *, count(*) mytable aaa_diam = 'missing'"; $sql .= " group postort"; break; case 5: $sql .= " count(*) antal_over_30 mytable "; $sql .= " aaa_diam > 30 , aaa_diam != 'missing' , "; $sql .= " aaa_diam != 'n.a' , aaa_diam != 'missing'"; break; case 6: $sql .= " count(*) antal_over_30 mytable "; $sql .= " aaa_diam > 50 , aaa_diam != 'missing' , "; $sql .= " aaa_diam != 'n.a' , aaa_diam != 'missing'"; break; case 7: $sql .= ""; break; } } $query = mysql_query($sql) or die(mysql_error()); ?> <!--sökrutan där sökord matas in --> <form name="select_filter" method="post" action="vgr_data_display.php"> <select id="dropdown" name="filter"> <option value=""></option> <option value="1">antal narvaro</option> <option value="2">antal franvaro</option> <option value="3">antal narvaro: destination</option> <option value="4">antal franvaro: destination</option> <option value="5">antal a_diam > 3cm</option> <option value="6">antal a_diam > 5cm</option> <option value="7">antal franvaro: procent</option> </select> <!--search bar search term input --> <input id="search_box" type="text" name="search_box" value="" /> <input id="submit" type ="submit" name ="search" value ="ok"> </form> <table style="margin:auto;" id="table" border='1'> <tr> <th>id</th> <th>f_ar</th> <th>postnr</th> <th>postort</th> <th>vardgivare</th> <th>team</th> <th>orsak</th> <th>planerat_datum</th> <th>fran</th> <th>aaa_diam</th> </tr> <?php while($row = mysql_fetch_array($query)) { ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo $row['f_ar']; ?></td> <td><?php echo $row['postnr']; ?></td> <td><?php echo $row['postort']; ?></td> <td><?php echo $row['vardgivare']; ?></td> <td><?php echo $row['team']; ?></td> <td><?php echo $row['orsak']; ?></td> <td><?php echo $row['planerat_datum']; ?></td> <td><?php echo $row['fran']; ?></td> <td><?php echo $row['aaa_diam']; ?></td> </tr> <?php } ?>
Comments
Post a Comment