Topshed Posted September 30, 2008 Share Posted September 30, 2008 I have a snippet of code I use many times to find a record, but suddenly it won't work on one of my tables using PHP 5 MySQL 5 Table = Depot Fields : Dname Varchar (25) Dcode = CHAR (2) <?php $tble = 'depot'; $xname = 'Mychoice'; ?> include_once("../includes/my_conn.php"); $connect = mysqli_connect($host,$account,$password) OR DIE("Error !! Unable to connect to database"); $db = mysqli_select_db($connect,"$dbname") OR DIE( "Unable to select database "); $db="SELECT * FROM $tble WHERE dname LIKE $xname"; echo $db; echo $dcode; echo $dname; if ($result = mysqli_query($connect,$db)) { if (mysqli_num_rows($result)) { while ($row = mysqli_fetch_assoc($result)){ ?> <table width="1020" border="4" cellspacing="0" cellpadding="1"> <tr> <th>Depot<br />.................................................... it appears to work fine up to echo $db; where it prints SELECT * FROM depot WHERE dname LIKE Mychoice Notice: Undefined variable: dcode in D:\hshome\topshed\londontrolleybus.com\PHPME\DepotFW.php on line 28 Notice: Undefined variable: dname in D:\hshome\topshed\londontrolleybus.com\PHPME\DepotFW.php on line 29 These 2 variables all ways work on my other scripts and I cannot see what I am doing Wrong ! Please help ! Thanks Roy... Quote Link to comment Share on other sites More sharing options...
ratcateme Posted September 30, 2008 Share Posted September 30, 2008 what are $dcode and $dname ment to be? you are not telling the script what thet are. Scott. Quote Link to comment Share on other sites More sharing options...
Topshed Posted September 30, 2008 Author Share Posted September 30, 2008 Thank you for the quick reply Aaaarghhhh They were supposed to be debug assists Stupid me Revised snippet $tble = 'depot'; $xname = 'Fulwell'; ?> </div> <!-- InstanceEndEditable --> <?php include_once("../includes/TrollyGal_conn.php"); $connect = mysqli_connect($host,$account,$password) OR DIE("Error !! Unable to connect to database"); // $db = mysqli_select_db($connect,"$dbname") OR DIE( "Unable to select database "); $db="SELECT * FROM $tble WHERE dname LIKE $xname"; echo $db; if ($result = mysqli_query($connect,$db)) { if (mysqli_num_rows($result)) { while ($row = mysqli_fetch_assoc($result)){ ?> <table width="1020" border="4" cellspacing="0" cellpadding="1"> <tr> <th>Depot<br /> Code</th> <th>Depot<br /> Name</th> <th>Previous<br /> Name</th> <th>Capacity</th> <th>Started</th> <th>Original<br /> <th>Finished Use</th> <th>After Trolleys</th> </tr> <tr> <td><?php print $row['dcode']."\n"; ?></td> <td><?php print$row['dname']."\n"; ?></td> <td><?php print $row['pname']."\n"; ?></td> <td><?php print $row['cap']."\n"; ?></td> <td><?php print $row['opened']."\n"; ?></td> <td><?php print $row['closed']."\n"; ?></td> <td><?php print $row['origin']."\n"; ?></td> <td><?php print $row['final']."\n"; ?></td> </tr> </table> } } ?> </body> </html> Now I just get SELECT * FROM depot WHERE dname LIKE Mychoice and then Nothing, no error msgs Thanks Roy... Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 30, 2008 Share Posted September 30, 2008 LIKE '%$varable_name%' $db="SELECT * FROM $tble WHERE dname LIKE '%$xname%' "; Quote Link to comment Share on other sites More sharing options...
Topshed Posted September 30, 2008 Author Share Posted September 30, 2008 Thank you Thank you That fixed the little bugger Regards Roy... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.