Click here to Skip to main content
14,241,662 members
Rate this:
Please Sign up or sign in to vote.
See more:
Am getting the error that says "
Notice: Undefined index: text1 
"
<div class="formRow">
                            <div class="grid2"><label><?php echo $lang['Timezone']; ?>:</label></div>
                            <div class="grid10">
                               <?php
				$query_timezone1=mysql_query("SELECT * FROM tbl_timezone WHERE id!='$db_timezone_id' ORDER BY timezone ASC");
				$option_timezone1="";
				while($row=mysql_fetch_array($query_timezone1)) {
				$option_timezone1 .= "<option value='$row[id]'";
				$option_timezone1 .= ">". $row['text1'] ." ". $row['timezone'] ."</option>";  }
				?>    
				<select name="timezone" id="timezone"  data-placeholder="Choose" class="select" tabindex="2" style="width:100%;">
                                <?php if($db_timezone_id!=0){echo "<option value='$db_timezone_id'>$db_timezone_code1 $db_timezone_timezone</option>"; }else{echo"<option value=''></option> ";}?>
				<?php echo $option_timezone1; ?>
				</select>
                            </div>             
                    </div>


What I have tried:

i have tried to identify the source of the error but all in vain
Posted
Updated 1-Oct-17 23:11pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

Your data returned from the select statement does not have a 'text1' column -> $row['text1']

Run your query and see what actual column names you have.
   
Comments
Member 10578733 2-Oct-17 5:01am
   
thanks for the response,do i have to create a row in my database?
Mehdi Gholam 2-Oct-17 5:03am
   
If you need the 'text1' column then yes, create the column.
Rate this:
Please Sign up or sign in to vote.

Solution 2

$query_timezone1=mysql_query("SELECT * FROM tbl_timezone WHERE id!='$db_timezone_id' ORDER BY timezone ASC");


Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
PHP: SQL Injection - Manual[^]

SQL Injection[^]
SQL Injection Attacks by Example[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
   
Comments
Member 10578733 2-Oct-17 5:14am
   
thanks for the advise on sql injection and will try to resolve it
Rate this:
Please Sign up or sign in to vote.

Solution 3

First of all, remove the *, add column name instead, for better practice:
example:

-- the no no
SELECT * FROM tbl_;

-- suggested
SELECT COL_1, COL_2,...,COL_3 FROM tbl_;


mysql_fetch_array()[^] returns both 0 base indexing and column name indexing. On the other hand mysql_fetch_assoc()[^]

I prefer mysql_fetch_assoc, (one less indexing)

For understanding why your are not getting why you are missing column,
use
print_r($row);



further suggestion, Stop using mysql_* functions, try mysqli_*; better yet use mysqli class[^]

try using mysqli::prepare[^]. SQL injection is a real problem.

Take a look at SQL injection
   
Comments
Member 10578733 2-Oct-17 5:28am
   
Thanks for the advise and i will make changes to my code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100