MySQL Query not returning specific search parameters via php script -



MySQL Query not returning specific search parameters via php script -

i have php driven page allows me come in search parameters. 1 of these numbers id consists of several digits. when search 1 these specific digits returns results.

i have done exact same statement in phpmyadmin , sql terminal , returns item searched for. suppose problem lies php using submit search query based on html form.

the drop downwards status options works fine - of fields requires input not.

also sure fields submitting database because can view them , finish sql statements them in phpadmin

edit echo result when numericidentider entered , default status of selected: select * table closed != ' '

<?php if($_request['search']) { $sql = "select"; if(strlen($_request['numericidentifier']) > 0) { $sql .= " * table numericidentifier = ".$_request['numericidentifier']; } if(strlen($_request['begindate']) > 0) { $sql .= " * table tdate >= {$_request['begindate']}"; } if(strlen($_request['enddate']) > 0) { $sql .= " * table tdate <= {$_request['enddate']}"; } if($_request['status'] == 'shipped') { $sql .= "* table closed = 'true' "; } if($_request['areacode'] > 0) { $sql .= " * table areacode = {$_request['areacode']}"; } if($_request['status'] == 'recieved') { $sql .= " * table closed != 'true'"; } if($_request['status'] == 'all') { $sql = "select * table closed != '\0'"; } } else { $sql = "select * tickets"; } $res = mysql_query($sql, $conn1); while($a = mysql_fetch_array($res)) { echo "<tr><td>&nbsp;<a href='ticket.php?id=".$a['id']."'>".trim($a['id'])."</a>&nbsp;</td> \n <td> ".$a['name']."</td> \n <td>".date("m/d/y", strtotime($a['ticketdate']))."</td> \n <td>".$a['issue']."</td> \n <td>".showstatus($a['closed'])." </td></tr>"; } ?> </table> </body> </html>

yeesh, sql never work. let's user enters both begindate , and enddate, query be

select * table tdate >= {$_request['begindate']} * table tdate <= {$_request['enddate']}

even if dates entered in mysql form (yyyy-mm-dd), still come out

select * table tdate >= 01/01/2011 * table tdate <= 31/12/2011

notice there's no quotes around dates. mysql see "dates" beingness numbers, beingness divided, you're saying tdate >= 0.0004972... , tdate <= 0.001284...

on top of that, saying * table twice illegal syntax.

your code not checking error states. @ absolute bare minimum should have:

$result = mysql_query($sql) or die(mysql_error());

which tell what's wrong query you've constructed.

and, worst of all, others have said, you're open , vulnerable sql injection attacks, i'm not going go that... query hopeless broken injection attack to the lowest degree of worries.

php mysql

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -