TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 02-27-2008, 11:54 PM   #1 (permalink)
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
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:32 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design