sandbudd Posted June 26, 2008 Share Posted June 26, 2008 I get this error mysql_num_rows(): supplied argument is not a valid MySQL. Here is line 197 where is if (mysql_num_rows($result) == 0) // table is empty echo '<ul><li>No Clients Available</li></ul>'; <?php $db_host = 'localhost'; // don't forget to change $db_user = 'anodizi_dan'; $db_pwd = 'pavilion111'; $database = 'anodizi_pass'; $table = 'ae_gallery'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // This function makes usage of // $_GET, $_POST, etc... variables // completly safe in SQL queries function sql_safe($s) { if (get_magic_quotes_gpc()) $s = stripslashes($s); return mysql_real_escape_string($s); } // If user pressed submit in one of the forms if ($_SERVER['REQUEST_METHOD'] == 'POST') { // cleaning title field $title = trim(sql_safe($_POST['title'])); $customer = trim(sql_safe($_POST['customer'])); $company = trim(sql_safe($_POST['company'])); $address = trim(sql_safe($_POST['address'])); $city = trim(sql_safe($_POST['city'])); $state = trim(sql_safe($_POST['state'])); $zip = trim(sql_safe($_POST['zip'])); $email = trim(sql_safe($_POST['email'])); $phone = trim(sql_safe($_POST['phone'])); $fax = trim(sql_safe($_POST['fax'])); $type2 = trim(sql_safe($_POST['type2'])); $type3 = trim(sql_safe($_POST['type3'])); $burnish = trim(sql_safe($_POST['burnish'])); $chromate = trim(sql_safe($_POST['chromate'])); $hex = trim(sql_safe($_POST['hex'])); $impregnation = trim(sql_safe($_POST['impregnation'])); $strip = trim(sql_safe($_POST['strip'])); $part = trim(sql_safe($_POST['part'])); $description = trim(sql_safe($_POST['description'])); $alloy = trim(sql_safe($_POST['alloy'])); $quantity = trim(sql_safe($_POST['quantity'])); $spec = trim(sql_safe($_POST['spec'])); $color = trim(sql_safe($_POST['color'])); $repeat = trim(sql_safe($_POST['repeat'])); $isearch = trim(sql_safe($_POST['isearch'])); $idir = trim(sql_safe($_POST['idir'])); $referral = trim(sql_safe($_POST['referral'])); $yellow = trim(sql_safe($_POST['yellow'])); $trade = trim(sql_safe($_POST['trade'])); $other = trim(sql_safe($_POST['other'])); $notes = trim(sql_safe($_POST['notes'])); if ($title == '') // if title is not set $title = '(empty title)';// use (empty title) string if ($_POST['password'] != $password) // cheking passwors $msg = 'Error: wrong upload password'; else { if (isset($_FILES['photo'])) { @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']); // Get image type. // We use @ to omit errors if ($imtype == 3) // cheking image type $ext="png"; // to use it later in HTTP headers elseif ($imtype == 2) $ext="jpeg"; elseif ($imtype == 1) $ext="gif"; else $msg = 'Error: unknown file format'; if (!isset($msg)) // If there was no error { $data = file_get_contents($_FILES['photo']['tmp_name']); $data = mysql_real_escape_string($data); // Preparing data to be used in MySQL query mysql_query("INSERT INTO {$table} SET ext='$ext', title='$title', customer='$customer', company='$company', address='$address', city='$city', state='$state', zip='$zip', email='$email', phone='$phone', fax='$fax', type2='$type2', type3='$type3', burnish='$burnish', chromate='$chromate', hex='$hex', impregnation='$impregnation', strip='$strip', part='$part', description='$description', alloy='$alloy', quantity='$quantity', spec='$spec', color='$color', repeat='$repeat', isearch='$isearch', idir='$idir', referral='$referral', yellow='$yellow', trade='$trade', other='$other', notes='$notes', data='$data'"); $msg = 'Success: image uploaded'; } } elseif (isset($_GET['title'])) // isset(..title) needed $msg = 'Error: file not loaded';// to make sure we've using // upload form, not form // for deletion if (isset($_POST['del'])) // If used selected some photo to delete { // in 'uploaded images form'; $id = intval($_POST['del']); mysql_query("DELETE FROM {$table} WHERE id=$id"); $msg = 'Photo deleted'; } } } elseif (isset($_GET['show'])) { $id = intval($_GET['show']); $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(image_time), data FROM {$table} WHERE id=$id LIMIT 1"); if (mysql_num_rows($result) == 0) die('no image'); list($ext, $image_time, $data, $customer, $company, $address, $city, $state, $zip, $email, $phone, $fax, $type2, $type3, $burnish, $chromate, $hex, $impregnation, $strip, $part, $description, $alloy, $quantity, $spec, $color, $repeat, $isearch, $idir, $referral, $yellow, $trade, $other, $notes) = mysql_fetch_row($result); $send_304 = false; if (php_sapi_name() == 'apache') { // if our web server is apache // we get check HTTP // If-Modified-Since header // and do not send image // if there is a cached version $ar = apache_request_headers(); if (isset($ar['If-Modified-Since']) && // If-Modified-Since should exists ($ar['If-Modified-Since'] != '') && // not empty (strtotime($ar['If-Modified-Since']) >= $image_time)) // and grater than $send_304 = true; // image_time } if ($send_304) { // Sending 304 response to browser // "Browser, your cached version of image is OK // we're not sending anything new to you" header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304); exit(); // bye-bye } // outputing Last-Modified header header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT', true, 200); // Set expiration time +1 year // We do not have any photo re-uploading // so, browser may cache this photo for quite a long time header('Expires: '.gmdate('D, d M Y H:i:s', $image_time + 86400*365).' GMT', true, 200); // outputing HTTP headers header('Content-Length: '.strlen($data)); header("Content-type: image/{$ext}"); // outputing image echo $data; exit(); } ?> <html><head> <title>FWA Admin</title> <style type="text/css"> <!-- .style1 { font-size: 24px; font-weight: bold; } --> </style> </head> <body> <div align="center"><span class="style1"> <br> RFQ Client Information </p> </span></div> <form action="<?=$PHP_SELF?>" method="post"> <!-- This form is used for image deletion --> <?php $result = mysql_query("SELECT id, image_time, title, customer, company, address, city, state, zip, email, phone, fax, type2, type3, burnish, chromate, hex, impregnation, strip, part, description, alloy, quantity, spec, color, repeat, isearch, idir, referral, yellow, trade, other, notes FROM {$table} ORDER BY id DESC"); if (mysql_num_rows($result) == 0) // table is empty echo '<ul><li>No Clients Available</li></ul>'; else { echo '<ul>'; while(list($id, $image_time, $title, $customer, $company, $address, $city, $state, $zip, $email, $phone, $fax, $type2, $type3, $burnish, $chromate, $hex, $impregnation, $strip, $part, $description, $alloy, $quantity, $spec, $color, $repeat, $isearch, $idir, $referral, $yellow, $trade, $other, $notes) = mysql_fetch_row($result)) { // outputing list echo "<table align=\"center\" border=1 bordercolordark=\"#777777\" width=\"60% \" bordercolorlight=\"#dddddd\" bgcolor=\"BBBBBB\">"; echo "<tr><td width=\"50%\"><font size=\"3\" color=red>Name:</font> <medium>{$customer}</medium></td>"; echo "<td><font size=\"3\" color=red>Company:</font> <medium>{$company}</medium></td></tr>"; echo "<tr><td><font size=\"3\" color=red>Address:</font> <medium>{$address}</medium></td></li>"; echo "<td><font size=\"3\" color=red>City:</font> <medium>{$city}</medium></td></tr></li>"; echo "<tr><td><font size=\"3\" color=red>State:</font> <medium>{$state}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Zip:</font> <medium>{$zip}</medium></td></tr></li>"; echo "<tr><td colspan=\"2\"><font size=\"3\" color=red>Email:</font> <medium>{$email}</medium></td></tr></li>"; echo "<tr><td><font size=\"3\" color=red>Phone:</font> <medium>{$phone}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Fax:</font> <medium>{$fax}</medium></li></td></tr>"; echo "<tr><td colspan=\"2\"><font size=\"2\" color=blue>Process Requested</font></tr></td>"; echo "<tr><td><font size=\"3\" color=red>Type II:</font> <medium>{$type2}</td></medium></li>"; echo "<td><font size=\"3\" color=red>Type III:</font> <medium>{$type3}</medium></tr></td></li><br><br>"; echo "<tr><td><font size=\"3\" color=red>Burnish:</font> <medium>{$burnish}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Chromate:</font> <medium>{$chromate}</medium></td></tr></li>"; echo "<tr><td><font size=\"3\" color=red>Chromate Hex Free:</font> <medium>{$hex}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Impregnation:</font> <medium>{$impregnation}</medium></td></tr></li>"; echo "<tr><td colspan=\"2\"><font size=\"3\" color=red>Strip:</font> <medium>{$strip}</medium></td></tr></li>"; echo "<tr><td colspan=\"2\"><font size=\"3\" color=red>Part Number:</font> <medium>{$part}</medium></td></tr></li>"; echo "<tr><td colspan=\"2\"><font size=\"3\" color=red>Part Description:</font> <medium>{$description}</medium></td></tr></li>"; echo "<tr><td><font size=\"3\" color=red>Alloy:</font> <medium>{$alloy}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Quantity:</font> <medium>{$quantity}</medium></td></tr></li>"; echo "<tr><td><font size=\"3\" color=red>Specifications:</font> <medium>{$spec}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Color:</font> <medium>{$color}</medium></td></tr></li>"; echo "<tr><td colspan=\"2\"><font size=\"2\" color=blue>How Did You Hear About Us?</font></td></tr>"; echo "<tr><td><font size=\"3\" color=red>Repeat Customer:</font> <medium>{$repeat}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Internet Search:</font> <medium>{$isearch}</medium></td></tr></li>"; echo "<tr><td><font size=\"3\" color=red>Internet Directory:</font> <medium>{$idir}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Referral:</font> <medium>{$referral}</medium></td></tr></li>"; echo "<tr><td><font size=\"3\" color=red>Yellow Pages:</font> <medium>{$yellow}</medium></td></li>"; echo "<td><font size=\"3\" color=red>Trade Show:</font> <medium>{$trade}</medium></td></tr></li>"; echo "<tr><td colspan=\"2\"><font size=\"3\" color=red>Other:</font> <medium>{$other}</medium></td></tr></li>"; echo "<tr><td colspan=\"2\"><font size=\"3\" color=red>Notes:</font> <medium>{$notes}</medium></td></tr></li>"; echo "<tr><td colspan=\"2\"><font size=\"3\" color=red>File Upload:</font> <a href='{$PHP_SELF}?show={$id}'>{$title}</a> – "; echo "<small>{$image_time}</small></td></tr></li>"; echo "<tr><td colspan=\"2\"><input type='submit' name='del' value='{$id}'> <-Click To Delete Record <font size=\"3\" color=red>(Once Record Is Deleted It Cannot Be Recovered) </font></td></tr>"; } echo '</ul>'; } ?> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/112032-solved-mysql_num_rows-supplied-argument-is-not-a-valid-mysql/ Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 add mysql_error() to the code: $result = mysql_query("SELECT id, image_time, title, customer, company, address, city, state, zip, email, phone, fax, type2, type3, burnish, chromate, hex, impregnation, strip, part, description, alloy, quantity, spec, color, repeat, isearch, idir, referral, yellow, trade, other, notes FROM {$table} ORDER BY id DESC") or die("Query Error: ".mysql_error()); if (mysql_num_rows($result) == 0) // table is empty echo '<ul><li>No Clients Available</li></ul>'; else Link to comment https://forums.phpfreaks.com/topic/112032-solved-mysql_num_rows-supplied-argument-is-not-a-valid-mysql/#findComment-575048 Share on other sites More sharing options...
sandbudd Posted June 26, 2008 Author Share Posted June 26, 2008 Now I get this error? Query Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' isearch, idir, referral, yellow, trade, other, notes FROM ae_gallery ORDER BY i' at line 1 Link to comment https://forums.phpfreaks.com/topic/112032-solved-mysql_num_rows-supplied-argument-is-not-a-valid-mysql/#findComment-575055 Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 a yes....REPEAT is a reserved word in mysql. if you want to use it as a column name, you need to wrap it in backticks: `repeat` (that is on the same key as a a tilda: ~) $result = mysql_query("SELECT id, image_time, title, customer, company, address, city, state, zip, email, phone, fax, type2, type3, burnish, chromate, hex, impregnation, strip, part, description, alloy, quantity, spec, color, `repeat`, isearch, idir, referral, yellow, trade, other, notes FROM {$table} ORDER BY id DESC") to be safe, i usually wrap all my fields with backticks. also, if you are selecting all the columns, you can always just keep it simple and use *: $result = mysql_query("SELECT * FROM {$table} ORDER BY id DESC") Link to comment https://forums.phpfreaks.com/topic/112032-solved-mysql_num_rows-supplied-argument-is-not-a-valid-mysql/#findComment-575071 Share on other sites More sharing options...
sandbudd Posted June 26, 2008 Author Share Posted June 26, 2008 that did it great...thanks Link to comment https://forums.phpfreaks.com/topic/112032-solved-mysql_num_rows-supplied-argument-is-not-a-valid-mysql/#findComment-575086 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.