Use of undefined constant error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SoreE yes
Forum Commoner
Posts: 32
Joined: Wed Oct 11, 2006 3:59 am

Use of undefined constant error

Post by SoreE yes »

Thanking you in advance.
It looks like an array error, but I can't see it.
Myerror message is
  • selecttable is Title
    sname is gift

    Notice: Use of undefined constant ItemID - assumed 'ItemID' in c:\appserv\www\uptodatalinksnew\backendpages\excsearch.php on line 44

    Notice: Use of undefined constant CategoryID - assumed 'CategoryID' in c:\appserv\www\uptodatalinksnew\backendpages\excsearch.php on line 45

    Notice: Use of undefined constant Title - assumed 'Title' in c:\appserv\www\uptodatalinksnew\backendpages\excsearch.php on line 46

    Notice: Use of undefined constant WebSite - assumed 'WebSite' in c:\appserv\www\uptodatalinksnew\backendpages\excsearch.php on line 47

    Notice: Use of undefined constant Precis - assumed 'Precis' in c:\appserv\www\uptodatalinksnew\backendpages\excsearch.php on line 48

    Notice: Use of undefined constant Description - assumed 'Description' in c:\appserv\www\uptodatalinksnew\backendpages\excsearch.php on line 49


The input form is

Code: Select all

<form method="POST" action="excsearch.php">
	<p align="center">
		<font size="2">EDITOR &nbsp;<input style="font-size: 11pt; " name="sname" size="20"></font>
		<select style="font-size: 11pt; " name="selecttable">
		 <OPTION selected value="Title">Title</OPTION>
		 <OPTION value="WebSite">WebSite</OPTION>
		 <OPTION value="Priority">Priority</OPTION>
		 </select>
		 <input type="submit" value="Search">
	</p>
      </form>
The action form is

Code: Select all

<?


$host="localhost";
$user="root";
$passwd="";
$dbname="uptodatalinks";
$tbname="items";
$tbnamec="categories";
$selecttable=$_POST['selecttable'];
$sname=$_POST['sname'];

echo "selecttable is ".$selecttable;
echo "</br>";
echo "sname is ".$sname;
echo "</br>";


mysql_connect($host,$user,$passwd) or die("can not connect");
mysql_select_db($dbname) or die("can not select");

// search //
$sql="select * from $tbname where $selecttable like  '%$sname%'";
$dbquery=mysql_db_query($dbname,$sql);
$num_rows=mysql_numrows($dbquery);


echo "<br><br>";
echo "<body bgcolor=\"#EFEFEF\">";
echo "<blockquote><table border=2 cellspacing=1 width=800>";
echo "<tr bgcolor=\"#ccddee\">";
echo "<td><font size=2>CategoryID</font></td>
             <td><font size=2>Title</font></td>
             <td><font size=2>WebSite</font></td>
             <td><font size=2>Precis</font></td>
             <td><font size=2>Description</font></td>
             <td><font size=2>PictureName</font></td>
             <td><font size=2>Priority</font></td>
             <td><font size=2>Edit</font></td></tr>";
$i=0;
while ($i <$num_rows)
           {
           	$result=mysql_fetch_array($dbquery);
           	$spid=$result[ItemID];
           	$CategoryID=$result[CategoryID];
           	$Title=$result[Title];
           	$WebSite=$result[WebSite];
           	$Precis=$result[Precis];
           	$Description=$result[Description];
           	$PictureName=$result[PictureName];
           	$Priority=$result[Priority];
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Quote your array indices,

Code: Select all

$spid=$result[ItemID] ;

//versus

$spid=$result['ItemID'];
SoreE yes
Forum Commoner
Posts: 32
Joined: Wed Oct 11, 2006 3:59 am

Post by SoreE yes »

Jcart wrote:Quote your array indices,

Code: Select all

$spid=$result[ItemID] ;

//versus

$spid=$result['ItemID'];
Thanks for your quick response. It works fine now. Many thanks.
Post Reply