Dynamic php vars in mysql, sql- vars get set, but result set is empty? -
i have following code created else, , though seems variables passed, nothing returning in results set; page: http://www.libraries.uc.edu/research/subject_resources/art/db/index.php... search. here code on results page below (edited length). have feeling it's quotes , such, have been overlooking something!
<?php if (!function_exists("getsqlvaluestring")) { function getsqlvaluestring($thevalue, $thetype, $thedefinedvalue = "", $thenotdefinedvalue = "") { if (php_version < 6) { $thevalue = get_magic_quotes_gpc() ? stripslashes($thevalue) : $thevalue; } $thevalue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($thevalue) : mysql_escape_string($thevalue); switch ($thetype) { case "text": $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null"; break; case "long": case "int": $thevalue = ($thevalue != "") ? intval($thevalue) : "null"; break; case "double": $thevalue = ($thevalue != "") ? doubleval($thevalue) : "null"; break; case "date": $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null"; break; case "defined": $thevalue = ($thevalue != "") ? $thedefinedvalue : $thenotdefinedvalue; break; } return $thevalue; } } if (isset($_get['stval'])) { $stval_recordset1 = (get_magic_quotes_gpc()) ? $_get['stval'] : addslashes($_get['stval']); } if (isset($_get['stval'])) { $stval_recordset1 = $_get['stval']; } if (isset($_get['sq'])) { $sq_recordset1 = $_get['sq']; } mysql_select_db($database_daap_photo, $daap_photo); $query_recordset1 = sprintf("select * main %s = %s ", getsqlvaluestring($stval_recordset1, "text"),getsqlvaluestring($sq_recordset1, "text")); $recordset1 = mysql_query($query_limit_recordset1, $daap_photo) or die(mysql_error()); $row_recordset1 = mysql_fetch_assoc($recordset1); ?>
then in body:
<?php print_r($_get); if(isset($_get["stval"])) echo "stval set\n"; if(isset($_get["sq"])) echo "sq set\n"; ?> <table width="100%" border="0" cellpadding="2" cellspacing="2"> <tr bgcolor="#cccccc"> <td colspan="4" bgcolor="#ffffff"><h1>art</h1> <h2>photography images slide collection -search results </h2> <p align="left" class="style1">your search returned <strong></strong> records.<br /> |<br /> </p> <p align="left" class="style1">your search returned no results. please use browsers button search again. </p> <p> first | previous | next | last<br /> <br /> </p></td> <td bgcolor="#ffffff"> </td> </tr> <tr bgcolor="#cccccc"> <td bgcolor="#cccccc"><p><strong>last name </strong></p> </td> <td bgcolor="#cccccc"><strong>first name </strong></td> <td bgcolor="#cccccc"><strong>dates</strong></td> <td bgcolor="#ffffff"> </td> <td bgcolor="#ffffff"> </td> </tr> <tr bgcolor="#cccccc"> <td bgcolor="#ffffff"> </td> <td><strong>nationality</strong></td> <td><strong>subject</strong></td> <td><strong>quantity</strong></td> <td><strong>media</strong></td> </tr> <?php { ?> <tr> <td class="bold"><?php echo $row_recordset1['last_name']; ?></td> <td><?php echo $row_recordset1['first_name']; ?></td> <td><?php echo $row_recordset1['dates']; ?></td> <td> </td> <td> </td> </tr>
etc....
thanks!
try change query to
select * main %s = '%s'
Comments
Post a Comment