Free Web Hosting Forum
(#1 (permalink))
Old
Member
tr_ellis1973@msn.com is on a distinguished road
 
Posts: 30
Join Date: Feb 2009
Location: DesMoines IA
Default sql query - 04-30-2012, 12:49 AM

I'm getting an error of could not execute the query. not sure what im doing wrong on this query. i'm just messing around with search through a database ofa drink recipe site im building. I wanna use a search option on this website.

PHP Code:
<?php
 $host
="mysql16.000webhost.com";
 
$user ="a7246488_serg91";
 
$password "xxxx";
 
$database ="a7246488_drinks";
    
$connection mysql_connect($host$user$password) or die ("couldn't connect to server");
    
    
        
$db mysql_select_db($database$connection) or die("couldn't select database.");
        
$name "drink"//user types in the name of drink
        
    
$query ="select NAME, INGREDIENTS, INSTRUCTIONS, CATEGORY from a1(1) where NAME = '%$name'";
    
$result mysql_query($query) or die ("Couldn't execute the query.");
    
    
$row mysql_num_rows($result);

        
//display the result of the table
    
$row mysql_fetch_array($result);
    
    
//this is where I think is where im going wrong
    
        
echo'Name:'.$row['name'];
        echo
'<br>Ingredients: '.$row['Ingredients'];
        echo
'<br>instructions: '.$row['Instructions'];
        echo
'<br>category: '.$row['category'];
        echo
'<br>Image: '.$row['image'];
        
?>
HTML Code:
<body>
<FORM action="search.php" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="submit" />
</body>

Last edited by tr_ellis1973@msn.com; 04-30-2012 at 01:22 AM. Reason: pw
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 762
Join Date: Dec 2010
Default 04-30-2012, 02:02 AM

The following code is applicable in case the matching result is just one row.

PHP Code:
<?php 
 $host
="mysql16.000webhost.com"
 
$user ="a7246488_serg91"
 
$password "xxxx"
 
$database ="a7246488_drinks"

 
$connection mysql_connect($host$user$password) or die ("couldn't connect to server");        
 
$db mysql_select_db($database$connection) or die("couldn't select database."); 

 
$name $_POST['term']; //name of the drink entered by a user
         
 
$query ="select NAME, INGREDIENTS, INSTRUCTIONS, CATEGORY from a1(1) where NAME = '%$name%'"
 
$result mysql_query($query) or die ("Couldn't execute the query.");     
    
 
// display $result in an array
 
$row mysql_fetch_array($result);  
 if(
$row) { 
        
        echo
'Name:'.$row['name']; 
        echo
'<br>Ingredients: '.$row['Ingredients']; 
        echo
'<br>instructions: '.$row['Instructions']; 
        echo
'<br>category: '.$row['category']; 
        echo
'<br>Image: '.$row['image'];  
}
else {
echo 
"No matching result!";
}        
?>

Last edited by grace1004; 04-30-2012 at 02:12 AM.
Reply With Quote
(#3 (permalink))
Old
Member
tr_ellis1973@msn.com is on a distinguished road
 
Posts: 30
Join Date: Feb 2009
Location: DesMoines IA
Default RE select query - 04-30-2012, 02:30 AM

I double checked what you did. I think its all correct. Still the same error. something has to be killing the select query. I'm just missing it.

PHP Code:
$host="mysql16.000webhost.com";
 
$user ="a7246488_serg91";
 
$password "xxxx";
 
$database ="a7246488_drinks";
    
$connection mysql_connect($host$user$password) or die ("couldn't connect to server");
    
$db mysql_select_db($database$connection) or die("couldn't select database.");
        
    
$name $_POST["NAME"]; //user types in the name of drink
        
    
$query "select NAME, INGREDIENTS, INSTRUCTIONS, CATEGORY from a1(1) where NAME = '%$name%'";
    
$result mysql_query($query) or die ("Couldn't execute the query.");
    
    
//display the result of the table
    
$row mysql_fetch_array($result); 
    if(
$row)     {
        echo 
'Name: <br />'.$row['name'];
        echo 
'Ingredients:<br />'.$row['Ingredients'];
        echo 
'Instructions:<br /> '.$row['Instructions'];
        echo 
'category: <br />'.$row['category'];
        
        
        
//echo 'Glass: <br/> '.$row['image'];
    
}
else    {
    echo 
"no matching results!";

HTML Code:
<body>
<FORM action="search.php" method="post">
Search: <input type="text" name="NAME" /><br />
<input type="submit" name="submit" value="submit" />
</body>

Last edited by tr_ellis1973@msn.com; 04-30-2012 at 02:33 AM. Reason: left some code out
Reply With Quote
(#4 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 762
Join Date: Dec 2010
Default 04-30-2012, 03:45 AM

Is table name `a1(1)` correct? The table name looks unusual.
Reply With Quote
(#5 (permalink))
Old
Member
tr_ellis1973@msn.com is on a distinguished road
 
Posts: 30
Join Date: Feb 2009
Location: DesMoines IA
Default 04-30-2012, 03:59 AM

yes. I thought it might of been the table name so I changed it to recipes. and im still getting the query failure error.
Reply With Quote
(#6 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 762
Join Date: Dec 2010
Default 04-30-2012, 04:03 AM

Did you check the real table name in your phpmyadmin? Did you change the table name in your phpmyadmin page?
Reply With Quote
(#7 (permalink))
Old
Member
tr_ellis1973@msn.com is on a distinguished road
 
Posts: 30
Join Date: Feb 2009
Location: DesMoines IA
Default 04-30-2012, 04:24 AM

For somew reason its working Know. all I have to do is figure out the lay out and I should be good. Thank you.
Reply With Quote
Reply

Thread Tools
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

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




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com