Jump to content

[SOLVED] ?Silly Problem


Topshed

Recommended Posts

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...

 

Link to comment
Share on other sites

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...

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.