View Single Post
Old 02-27-2008, 11:54 PM   #1 (permalink)
StevenF
The Contributor
 
Join Date: Jan 2008
Posts: 87
Thanks: 49
StevenF is on a distinguished road
Default Searching DB Problem

I have another small problem :( I'll start off by showing the code I have so far:

PHP Code:
                        <tr>
                        <
td>Artist:</td>
                        <
td><input type="text" name="cd_artist" value="" /></td>
                        </
tr>
                        
                        <
tr>
                        <
td>Title:</td>
                        <
td><input type="text" name="cd_title" value="" /></td>
                        </
tr>
                        
                        <
tr>
                        <
td>Price:</td>
                        <
td><input type="text" name="cd_price" value="£" /></td>
                        </
tr>
                        
                        <
tr>
                        <
td>Image No:</td>
                        <
td><input type="text" name="cd_image_name" value="" /></td>
                        </
tr>
                    
                        <
tr>
                        <
td>&nbsp;</td>
                        <
td><input type="submit" value="Save" name="submit" /></td
PHP Code:
//setting variables to grab data from the form
        
$search_artist mysql_real_escape_string($_POST['search_artist']);
        
$search_title mysql_real_escape_string($_POST['search_title']);
        
        
//Create query to return all if data is matched
        
$query "SELECT * FROM products WHERE cd_artist = $search_artist AND cd_title = $search_title";
        
$result mysql_query($query);

        
//Check to see how many rows exist
        
$num mysql_numrows($result);
        
        
//Check to see if we found 1 row with that page name
        
if( mysql_num_rows($result) == ) {
        
        
//Store each returned column in a variable
        
$cd_artist mysql_result ($result0"cd_artist");
        
$cd_title mysql_result ($result0"cd_title");
        
$cd_price mysql_result ($result0"cd_price");
        
$cd_image_name mysql_result ($result0"cd_image_name");
    
                echo (
"
                <form>
                    <table>
                        <tr>
                            <td>Artist:</td>
                            <td><input type=\"text\" name=\"\" value=\" 
$cd_artist \" /></td>
                        </tr>
                        
                        <tr>
                            <td>Title:</td>
                            <td><input type=\"text\" name=\"\" value=\" 
$cd_title \" /></td>
                        </tr>
                        
                        <tr>
                            <td>Price</td>
                            <td><input type=\"text\" name=\"\" value=\" 
$cd_price \" /></td>
                        </tr>
                        
                        <tr>
                            <td>Img Name</td>
                            <td><input type=\"text\" name=\"\" value=\" 
$cd_image_name \" /></td>
                        </tr>
                        
                        <tr>
                            <td>&nbsp;</td>
                            <td><input type=\"submit\" name=\"\" value=\"Submit\" />
                        </tr>
                    </table>
                </form>"
);
            
            
                
                    } else {
                     
                    
//Error array
                    
$errors = array();
                
                    
//Check that the following exist
                    
if(!$cd_artist) {
                        
$errors[] = "<strong>Artist not found!</strong>";
                    }
                    
                    if(!
$cd_title) {
                        
$errors[] = "<strong>Title not found!<br /></strong>";
                    }
                    
                    
//Split errors up and show them
                    
if (count($errors) > 0) {
                        foreach(
$errors AS $error) {
                            echo 
$error "<br>\n";
                            }
                        }
                        
                    
//GO to....
                    
header('Refresh: 3; url=UpdateExistingProduct.php');
                    }    
?> 


When I enter numbers into the forum (example an entry with Artist = 1 and Title =2) it will return the results in the the other form. When I use letters instead (example an entry with Artist = a and Title = b) it won't work. I'm presented with two errors and I'm not sure why...

Quote:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\WOS\www\TUCS\do_update.php on line 21

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\WOS\www\TUCS\do_update.php on line 24
Artist not found!
I know there's quite a lot of code there, sorry.
__________________
My Personal and Photo Blog

Last edited by StevenF : 02-28-2008 at 12:33 AM.
StevenF is offline  
Reply With Quote