By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

update profile cannot function: Notice: Undefined index: company_ID

100+
P: 127
I have do a update profile for company where they can update after view their profile, but it cannot function... I need to submit the whole job portal soon, but still got many problem in my coding, could someone help me... Thanks a lot..
Below is the error:
Notice: Undefined index: company_ID in C:\Apache2\Apache2\htdocs\comProfile_update.php on line 28
where line 28 is
[PHP]if(is_numeric($_GET['company_ID'])) {[/PHP]


My whole coding as below:
[PHP]<?php
error_reporting(E_ALL);
//ob_start();
session_start();

//connect to server and select database
$conn=mysql_connect('localhost','root','')
or die(mysql_error());
mysql_select_db('ums e-job portal', $conn) or die(mysql_error());

if (isset($_POST['submit'])){//handle the form
//define query
$query= "UPDATE company SET companyName='$_POST[companyName]', companyType='$_POST[companyType]', conatctName='$_POST[contactName]', contactNum='$_POST[contactNum]', fax='$_POST[fax]', contactAdd='$_POST[contactAdd]',
city='$_POST[city]', postcode='$_POST[postcode]', state='$_POST[state]', country='$_POST[country]', description='$_POST[description]',
WHERE company_ID={$_SESSION['company_ID']}";
$r= mysql_query($query); //execute the query.

//report on the result.
if(mysql_affected_rows()==1){
print'<p>The profile has been updated.</p>';
} else{
print'<p>Could not update the profile because:<b>'.mysql_error().'</b>. The query was $query.</p>';
}

}else{//Display the entry in a form.

//check for a valid entry ID
if(is_numeric($_GET['company_ID'])) {
//define the query.
$query= "SELECT * FROM company WHERE company_ID={$_GET['company_ID']}";
if ($r = mysql_query($query)) { //run the query.
$row=mysql_fetch_array($r) ; //retrieve the information
?>
<form action='comProfile_update.php' method='post'>
<div align='center'><font size='+3' face='Verdana'><strong>COMPANY
PROFILE </strong> </font></div>

<table width="600" border="0">

<tr>
<td width="217"><font color="#000000" face="Verdana">Company Name<font color="#FF0000">*</font>
</font></td>
<td width="30"><div align="center"><strong>:</strong></div></td>
<td width="339"><input name="companyName" type="text" maxlength="20" value=".$row['companyName']."></td>
</tr>
<tr>
<td><font color="#000000" face="Verdana">Company Type</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><select name="companyType">
<option selected>".$row['companyType']."</option>
<option>Employer</option>
<option>Recruiter</option>
</select></td>
</tr>
<tr>
<td><font color="#000000" face="Verdana">Contact Name<font color="#FF0000">*</font></font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input type="text" name="contactName" value=".$row['contactName']."></td>
</tr>
<tr>
<td><font color="#000000" face="Verdana">Contact Number<font color="#FF0000">*</font></font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input name="contactNum" type="text" maxlength="11" value=".$row['contactNaum']."></td>
</tr>
<tr>
<td><font color="#000000" face="Verdana">Fax</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input name="fax" type="text" maxlength="11" value=".$row['fax']."></td>
</tr>
<tr>
<td><font color="#000000" face="Verdana">Contact Address<font color="#FF0000">*</font></font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><textarea name="contactAdd" cols="33" rows="3">".$row['contactAdd']."</textarea></td>
</tr>
<tr>
<td><font color="#000000" face="Verdana">City</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input name="city" type="text" maxlength="50" value=".$row['city']."></td>
</tr>
<tr>
<td><font color="#000000" face="Verdana">Postcode</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input name="postcode" type="text" maxlength="5" value=".$row['postcoode']."></td>
</tr>
<tr>
<td><font color="#000000" Face="Verdana">State</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input type="text" name="state" value=".$row['state']."></td>
</tr>
<tr>
<td><font color="#000000" Face="Verdana">Country</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><input name="country" type="text" value=".$row['country']."></td>
</tr>
<tr>
<td><font color="#000000" face="Verdana">Description</font></td>
<td><div align="center"><strong>:</strong></div></td>
<td><textarea name="description" cols="33" rows="3">".$row['description']."</textarea></td>
</tr>
</tr>
</table>
<p>
</div>
<p>
<input type='hidden' name='company_ID' value=".$_GET['company_ID'].">
<input name='submit' type='submit' id='submit' value='Update Profile'>
</p>
</div>
<?
}else{//couldnt get information.
print'<p>Could not retrieve the entry because:<b>'.mysql_error().'</b>. The query was $query.</p>';
}
} else{//No ID set
print'<p><b>You must have made a mistake in using this page.</b></p>';
}
} //End of main IF.

mysql_close(); //close the database connection.
?>

[/PHP]
Feb 11 '07 #1
Share this Question
Share on Google+
12 Replies


ronverdonk
Expert 2.5K+
P: 4,258
The message displayed is just a notice, not an error.
Expand|Select|Wrap|Line Numbers
  1. Notice: Undefined index: company_ID in C:\Apache2\Apache2\htdocs\comProfile_update.php on line 28
Your code will continue, so your thread title is not correct.

You get this message because you have set
Expand|Select|Wrap|Line Numbers
  1. error_reporting(E_ALL);
.
The proper way to handle this is checking if this $_GET array key/value is defined at all, like [php] if (isset($_GET['company_ID'])) {[/php]
Ronald :cool:
Feb 11 '07 #2

100+
P: 127
The message displayed is just a notice, not an error.
Expand|Select|Wrap|Line Numbers
  1. Notice: Undefined index: company_ID in C:\Apache2\Apache2\htdocs\comProfile_update.php on line 28
Your code will continue, so your thread title is not correct.

You get this message because you have set
Expand|Select|Wrap|Line Numbers
  1. error_reporting(E_ALL);
.
The proper way to handle this is checking if this $_GET array key/value is defined at all, like [php] if (isset($_GET['company_ID'])) {[/php]
Ronald :cool:

Sorry, is it change
[PHP]if(is_numeric($_GET['company_ID'])) { [/PHP]
to
[PHP] if (isset($_GET['company_ID'])) { [/PHP]

But the output is:
You must have made a mistake in using this page.

where it execute line 118-120
line 118-120 is
[PHP] else{//No ID set
print'<p><b>You must have made a mistake in using this page.</b></p>';
}[/PHP]


What should i do now??
I have no idea now, i'm a newbie in php, but i need to do a job portal like jobstreet for my university within 2.5 month by myself, if not i cannot graduate... I need to pass up the job portal 2 more week from now, im very nervous now.. This forum is the solution for me to solve my coding problem, i really don't what to do.. Thanks a lot...
Feb 11 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
So you have not set the company_ID, right? Or did you test it with the numeric company id?

Ronald :cool:
Feb 11 '07 #4

100+
P: 127
So you have not set the company_ID, right? Or did you test it with the numeric company id?

Ronald :cool:
I have edit my php code as below:
[PHP]<?php
session_start();
ob_start();


//connect to server and select database
$conn=mysql_connect('localhost','root','')
or die(mysql_error());
mysql_select_db('ums e-job portal', $conn) or die(mysql_error());

if (isset($_POST['submit'])){//handle the form
//define query
$query= "UPDATE company SET companyName='$_POST[companyName]', companyType='$_POST[companyType]', conatctName='$_POST[contactName]', contactNum='$_POST[contactNum]', fax='$_POST[fax]', contactAdd='$_POST[contactAdd]',
city='$_POST[city]', postcode='$_POST[postcode]', state='$_POST[state]', country='$_POST[country]', description='$_POST[description]',
WHERE company_ID={$_SESSION['company_ID']}";
$r= mysql_query($query); //execute the query.

//report on the result.
if(mysql_affected_rows()==1){
print'<p>The profile has been updated.</p>';
} else{
print'<p>Could not update the profile because:<b>'.mysql_error().'</b>. The query was $query.</p>';
}

}else{//Display the entry in a form.

//check for a valid entry ID
if (isset($_SESSION['company_ID'])) {
//define the query.
$query= "SELECT * FROM company WHERE company_ID={$_SESSION['company_ID']}";
if ($r = mysql_query($query)) { //run the query.
$row=mysql_fetch_array($r) ; //retrieve the information



echo"<form action='comProfile_update.php' method='post'>
<div align='center'><font size='+3' face='Verdana'><strong>COMPANY PROFILE </strong></font></div>
<table width='600' border='0'>
<tr>
<td colspan='3'><font color='#000000' face='Verdana'><strong>Update Your Company Information</strong></font></td>
</tr>
<tr>
<td width='217'><font color='#000000' face='Verdana'>Company Name<font color='#FF0000'>*</font>
</font></td>
<td width='30'><div align='center'><strong>:</strong></div></td>
<td width='339'><input name='companyName' type='text' maxlength='20' value=".$row['companyName']."></td>
</tr>
<tr>
<td><font color='#000000' face='Verdana'>Company Type</font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><select name='companyType'>
<option selected>".$row['companyType']."</option>
<option>Employer</option>
<option>Recruiter</option>
</select></td>
</tr>
<tr>
<td><font color='#000000' face='Verdana'>Contact Name<font color='#FF0000'>*</font></font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><input type='text' name='contactName' value=".$row['contactName']."> </td>
</tr>
<tr>
<td><font color='#000000' face='Verdana'>Contact Number<font color='#FF0000'>*</font></font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><input name='contactNum' type='text' maxlength='11' value=".$row['contactNum']."></td>
</tr>
<tr>
<td><font color='#000000' face='Verdana'>Fax</font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><input name='fax' type='text' maxlength='11' value=".$row['fax']."></td>
</tr>
<tr>
<td><font color='#000000' face='Verdana'>Contact Address<font color='#FF0000'>*</font></font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><textarea name='contactAdd' cols='33' rows='3'>".$row['contactAdd']."</textarea></td>
</tr>
<tr>
<td><font color='#000000' face='Verdana'>City</font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><input name='city' type='text' maxlength='50' value=".$row['city']."></td>
</tr>
<tr>
<td><font color='#000000' face='Verdana'>Postcode</font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><input name='postcode' type='text' maxlength='5' value=".$row['postcode']."></td>
</tr>
<tr>
<td><font color='#000000' Face='Verdana'>State</font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><input type='text' name='state' maxlength='30' value=".$row['state']."></td>
</tr>
<tr>
<td><font color='#000000' Face='Verdana'>Country</font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><input name='country' type='text' value=".$row['country']."></td>
</tr>
<tr>
<td><font color='#000000' face='Verdana'>Description</font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><textarea name='description' cols='33' rows='3>".$row['description']."</textarea></td>
</tr>
</table>
<div>
<p>
<input type='hidden' name='company_ID' value=".$_SESSION['company_ID'].">
<input name='submit' type='submit' id='submit' value='Update Profile'>
</p>
</div>";

}else{//couldnt get information.
print'<p>Could not retrieve the entry because:<b>'.mysql_error().'</b>. The query was $query.</p>';
}
} else{//No ID set
print'<p><b>You must have made a mistake in using this page.</b></p>';
}
} //End of main IF.

mysql_close(); //close the database connection.
?>[/PHP]

It does call out the data after the user login, but at the the output of field description as below:
</p>
</div>

And it din't call out the data from database, and the update profile button also din't have..
Emm.. is it the problem in
[PHP]<div>
<p>
<input type='hidden' name='company_ID' value=".$_SESSION['company_ID'].">
<input name='submit' type='submit' id='submit' value='Update Profile'>
</p>
</div>";[/PHP]
?? How to change the code??
Thanks..
Feb 14 '07 #5

ronverdonk
Expert 2.5K+
P: 4,258
Your error is in the following statement where you do not close the single quotes in the rows='3> part:

[php]<td><textarea name='description' cols='33' rows='3>".$row['description']."</textarea></td>[/php]

This statement must be:

[php]<td><textarea name='description' cols='33' rows='3'>".$row['description']."</textarea></td>[/php]

Ronald :cool:
Feb 14 '07 #6

100+
P: 127
Your error is in the following statement where you do not close the single quotes in the rows='3> part:

[php]<td><textarea name='description' cols='33' rows='3>".$row['description']."</textarea></td>[/php]

This statement must be:

[php]<td><textarea name='description' cols='33' rows='3'>".$row['description']."</textarea></td>[/php]

Ronald :cool:

Thanks a lot, Ronald... It already can click the update button...
But it the update still cannot function. The ouput show:
Could not update the profile because:You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE company_ID=2' at line 3. The query was $query.

I think is from the code below:
[PHP] //report on the result.
if(mysql_affected_rows()==1){
print'<p>The profile has been updated.</p>';
} else{
print'<p>Could not update the profile because:<b>'.mysql_error().'</b>. The query was $query.</p>';
} [/PHP]
But how to edit it?? Thanks and sorry always ask the simple question, but i really don't know how to repair it...Thanks..
Feb 14 '07 #7

ronverdonk
Expert 2.5K+
P: 4,258
The first error that springs up in your UPDATE statement is the one with the comma at the end :
Expand|Select|Wrap|Line Numbers
  1. city='$_POST[city]', postcode='$_POST[postcode]', state='$_POST[state]', country='$_POST[country]', description='$_POST[description]', 
remove that comma, because it generates an SQL error.

Ronald :cool:
Feb 14 '07 #8

100+
P: 127
The first error that springs up in your UPDATE statement is the one with the comma at the end :
Expand|Select|Wrap|Line Numbers
  1. city='$_POST[city]', postcode='$_POST[postcode]', state='$_POST[state]', country='$_POST[country]', description='$_POST[description]', 
remove that comma, because it generates an SQL error.

Ronald :cool:
Thanks a lot, Ronald... It work well, thanks a lot...:)
Feb 14 '07 #9

ronverdonk
Expert 2.5K+
P: 4,258
I am glad you got that working (at last).

Ronald :cool:
Feb 14 '07 #10

100+
P: 127
I am glad you got that working (at last).

Ronald :cool:
Sorry, may i ask 1 more question? Below is a list menu which is 1 part of update function, and when i code as below, it won't show either employer or recruiter although it is either one in database.
Expand|Select|Wrap|Line Numbers
  1. <tr> 
  2.       <td>Company Type:</td>
  3.             <td><select name='companyType'>
  4.           <option VALUE=></option>
  5.           <option VALUE=Employer>Employer</option>
  6.           <option VALUE=Recruiter>Recruiter</option>
  7.         </select></td>
  8.     </tr>
And when i code as code below, it will repeat the option. For example, if the company is employer, it will show:
Employer
Employer
Recruiter

or if the company is recruiter, it will show:
Recruiter
Employer
Recruiter

code is as below:
Expand|Select|Wrap|Line Numbers
  1. <tr> 
  2.       <td>Company Type:</td>
  3.       <td><select name='companyType'>
  4.           <option selected>".$row['companyType']."</option>
  5.           <option>Employer</option>
  6.           <option>Recruiter</option>
  7.         </select></td>
  8.     </tr>
So, how should i code, if i want the option is choose according to data store in mysql, and is it not repeated as case 2.
Can you give me some guildeline?
Thanks a lot..:)
Feb 14 '07 #11

ronverdonk
Expert 2.5K+
P: 4,258
The 'normal' method to populate a dropdown is something like this:
[php]
// connect to server and db MySQL
// execute query
if (!$res=mysql_query("SELECT column_name from table GROUP BY column_name")
or die ("Invalid query: ".mysql_error());
// start the dropdown
echo '<select id="name" name="name">';
echo '<option value="">Select here</option>';
// populate dropdown from table
while ($row=mysql_fetch_assoc($res)) {
$opt=$row['colum_name'];
echo "<option value='$opt'>$opt</option>";
}
// close the drop down
echo '</select>';[/php]

Ronald :cool:
Feb 14 '07 #12

100+
P: 127
The 'normal' method to populate a dropdown is something like this:
[php]
// connect to server and db MySQL
// execute query
if (!$res=mysql_query("SELECT column_name from table GROUP BY column_name")
or die ("Invalid query: ".mysql_error());
// start the dropdown
echo '<select id="name" name="name">';
echo '<option value="">Select here</option>';
// populate dropdown from table
while ($row=mysql_fetch_assoc($res)) {
$opt=$row['colum_name'];
echo "<option value='$opt'>$opt</option>";
}
// close the drop down
echo '</select>';[/php]

Ronald :cool:

Sorry, i try to put it in my code but it appear an error..
Parse error: parse error, unexpected ';' in C:\Apache2\Apache2\htdocs\comProfile_update.php on line 52

Which line 52 is
Expand|Select|Wrap|Line Numbers
  1.  if (!$res=mysql_query("SELECT companyType from job GROUP BY companyType") 
  2.     or die ("Invalid query: ".mysql_error());
I dunno is it i'm put it in the wrong way... I add the code within the echo statement that to display the form
I put the code as below:
[PHP]<?php
session_start();
ob_start();


//connect to server and select database
$conn=mysql_connect('localhost','root','')
or die(mysql_error());
mysql_select_db('ums e-job portal', $conn) or die(mysql_error());

if (isset($_POST['submit'])){//handle the form
//define query
$query= "UPDATE company SET companyName='$_POST[companyName]', companyType='$_POST[companyType]', contactName='$_POST[contactName]', contactNum='$_POST[contactNum]', fax='$_POST[fax]', contactAdd='$_POST[contactAdd]',
city='$_POST[city]', postcode='$_POST[postcode]', state='$_POST[state]', country='$_POST[country]', description='$_POST[description]'
WHERE company_ID={$_SESSION['company_ID']}";
$r= mysql_query($query); //execute the query.

//report on the result.
if(mysql_affected_rows()==1){
print'<p>The profile has been updated.</p>';
} else{
print'<p>Could not update the profile because:<b>'.mysql_error().'</b>. The query was $query.</p>';
}

}else{//Display the entry in a form.

//check for a valid entry ID
if (isset($_SESSION['company_ID'])) {
//define the query.
$query= "SELECT * FROM company WHERE company_ID={$_SESSION['company_ID']}";
if ($r = mysql_query($query)) { //run the query.
$row=mysql_fetch_array($r) ; //retrieve the information




echo"<form action='comProfile_update.php' method='post'>
<div align='center'><font size='+3' face='Verdana'><strong>COMPANY PROFILE </strong></font></div>
<table width='600' border='0'>
<tr>
<td colspan='3'><font color='#000000' face='Verdana'><strong>Update Your Company Information</strong></font></td>
</tr>
<tr>
<td width='217'><font color='#000000' face='Verdana'>Company Name<font color='#FF0000'>*</font>
</font></td>
<td width='30'><div align='center'><strong>:</strong></div></td>
<td width='339'><input name='companyName' type='text' maxlength='50' value='".$row['companyName']."'></td>
</tr>";

// execute query
if (!$res=mysql_query("SELECT companyType from job GROUP BY companyType")
or die ("Invalid query: ".mysql_error());

// start the dropdown
echo '<option value="">Select here</option>';
// populate dropdown from table
while ($row=mysql_fetch_assoc($res)) {
$opt=$row['companyType'];
echo "<option value='$opt'>$opt</option>";
}
// close the drop down
echo '</select>';
?>


<?
echo"<tr>
<td><font color='#000000' face='Verdana'>Contact Name<font color='#FF0000'>*</font></font></td>
<td><div align='center'><strong>:</strong></div></td>
<td><input type='text' name='contactName' value='".$row['contactName']."'></td>
</tr>
</table>
<div>
<p>
<input type='hidden' name='company_ID' value=".$_SESSION['company_ID'].">
<input name='submit' type='submit' id='submit' value='Update Profile'>
</p>
</div>";

}else{//couldnt get information.
print'<p>Could not retrieve the entry because:<b>'.mysql_error().'</b>. The query was $query.</p>';
}
} else{//No ID set
print'<p><b>You must have made a mistake in using this page.</b></p>';
}
} //End of main IF.

mysql_close(); //close the database connection.
?>[/PHP]
Thanks...
Feb 17 '07 #13

Post your reply

Sign in to post your reply or Sign up for a free account.