473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Undefined index

20
I want to update my data, so I have this code

admin.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include('config.php');
  3.  
  4.     $bil = 0;
  5.     //$option = '';
  6.     $results = mysql_query("SELECT * FROM pemohon");
  7.     //$option .='<select>';
  8.     //$count=mysql_num_rows($results);
  9.     //
  10.     while ($row = mysql_fetch_array($results, MYSQL_ASSOC))
  11.     {
  12.     $bil++;
  13.  
  14.  
  15.  
  16.     echo "<form name='update $bil' action=update.php method=post>"; ?>
  17.     <tr>
  18.         <td><center><?php echo $bil; ?></center></td>
  19.         <td><?php echo $row['name']; ?></td>
  20.         <td><?php echo $row['unit']; ?></td>
  21.         <td><?php echo $row['telefon']; ?></td>
  22.         <td><?php echo $row['email']; ?></td>
  23.         <td><?php echo $row['data']; ?></td>
  24.         <td><?php echo $row['tujuan']; ?></td>
  25.         <td><?php echo $row['tindakan']; ?></td>
  26.         <td><?php echo $row['agihan']; ?></td>
  27.         <td><input type='submit' name='submit' value='kemaskini'>
  28.             <input type='hidden' name='id' value=<?php echo $row['id']; ?></td>
  29.  
  30.         <!--<td><center><select name="myselect" id="myselect" size="0">
  31.         <option <//?php if( $row['tindakan'] == '-'){ echo "selected";}?> >-</option>
  32.         <option <//?php if( $row['tindakan'] == 'lulus'){ echo "selected";}?> >Diluluskan</option>
  33.         <option <//?php if( $row['tindakan'] == 'taklulus'){ echo "selected";}?> >Tidak Diluluskan</option>
  34.         </select></center></td>
  35.         <td><center><select name="myselect" id="myselect" size="0">
  36.         <option <//?php if( $row['agihan'] == '-'){ echo "selected";}?> >-</option>
  37.         <option <//?php if( $row['agihan'] == 'a'){ echo "selected";}?> >Encik A</option>
  38.         <option <//?php if( $row['agihan'] == 'b'){ echo "selected";}?> >Puan B</option>
  39.         </select></center></td>-->
  40.     </tr>
  41.  
  42. <?php 
  43. }
update.php
Expand|Select|Wrap|Line Numbers
  1. <div id="welcome">
  2.     <?php
  3.     include('config.php');
  4.  
  5.     $sql = "SELECT * FROM pemohon WHERE id='".$_POST['id']."'";
  6.     $results = mysql_query($sql);
  7.  
  8.     $row = mysql_fetch_array($results);
  9.     //$user = $row['username'];
  10.  
  11.  
  12.     $id = $row['id'];
  13.     $name = $row['name'];
  14.     $jawatan = $row['jawatan'];
  15.     $unit = $row['unit'];
  16.     $kementerian = $row['kementerian'];
  17.     $telefon = $row['telefon'];
  18.     $faks = $row['faks'];
  19.     $email = $row['email'];
  20.     $data = $row['data'];
  21.     $tujuan = $row['tujuan'];
  22.     $tarikh = $row['tarikh'];
  23.     $tindakan = $row['tindakan'];
  24.  
  25.     $id = $_POST['id'];
  26.     $submit = $_POST['submit'];
  27.     ?>
  28.  
  29.     <form name="update" action="update2.php" method="post">
  30.         <table width="763" align="center">
  31.             <tr>
  32.                 <td>No. ID</td>
  33.                 <td>:</td>
  34.                 <td><?php echo "$id"; ?></td>
  35.             </tr>
  36.             <tr>
  37.                 <td width="173">Nama Pemohon</td>
  38.                 <td width="10">:</td>
  39.                 <td width="564"><?php echo "$name"; ?></td>
  40.             </tr>
  41.             <tr>
  42.                 <td>Jawatan</td>
  43.                 <td>:</td>
  44.                 <td><?php echo "$jawatan"; ?></td>
  45.             </tr>
  46.             <tr>
  47.                 <td>Unit/Jabatan/Bahagian</td>
  48.                 <td>:</td>
  49.                 <td><?php echo "$unit"; ?></td>
  50.             </tr>
  51.             <tr>
  52.                 <td>Kementerian/Institusi/Agensi</td>
  53.                 <td>:</td>
  54.                 <td><?php echo "$jawatan"; ?></td>
  55.             </tr>
  56.             <tr>
  57.                 <td>No. Telefon</td>
  58.                 <td>:</td>
  59.                 <td><?php echo "$telefon"; ?></td>
  60.             </tr>
  61.             <tr>
  62.                 <td>No. Faks</td>
  63.                 <td>:</td>
  64.                 <td><?php echo "$faks"; ?></td>
  65.             </tr>
  66.             <tr>
  67.                 <td>E-mail</td>
  68.                 <td>:</td>
  69.                 <td><?php echo "$email"; ?></td>
  70.             </tr>
  71.             <tr>
  72.                 <td>Data/Laporan Yang Dipohon</td>
  73.                 <td>:</td>
  74.                 <td><?php echo "$data"; ?></td>
  75.             </tr>
  76.             <tr>
  77.                 <td>Tujuan</td>
  78.                 <td>:</td>
  79.                 <td><?php echo "$tujuan"; ?></td>
  80.             </tr>
  81.             <tr>
  82.                 <td>Tarikh Permohonan</td>
  83.                 <td>:</td>
  84.                 <td><?php echo "$tarikh"; ?></td>
  85.             </tr>
  86.             <tr>
  87.                 <td>Tindakan</td>
  88.                 <td>:</td>
  89.                 <td><label>
  90.                     <select name="tindakan" id="tindakan">
  91.                     <option selected="selected"></option>
  92.                     <option>Diluluskan</option>
  93.                     <option>Tidak Diluluskan</option>
  94.                     </select>
  95.                     </label>
  96.             </tr>
  97.             <tr>
  98.                 <td>Agihan</td>
  99.                 <td>:</td>
  100.                 <td><label>
  101.                     <select name="agihan" id="agihan">
  102.                     <option selected="selected"></option>
  103.                     <option>Pn. Suryana Binti Embong</option>
  104.                     <option>Pn. Rohaida Binti Ali</option>
  105.                     <option>En. Hasril Rezuan Bin Suboh</option>
  106.                     </select>
  107.                     </label>
  108.             </tr>
  109.  
  110.     <p align="center">
  111.     <input type="hidden" name="noid" value="<?php echo $id; ?>">
  112.     <input type="hidden" name="name" value="<?php echo $name; ?>">
  113.     <input name="submit" type="submit" id="submit" value="Kemaskini" />
  114.  
  115.     </p>
  116.     </form>
  117.     </div>
update2.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $name = $_POST['name'];
  4.  
  5. //if (!isset($_POST['id'])) {
  6.       $id = $_POST['id'];
  7. //} else {
  8. //      $id = 999999999;
  9. //}
  10.  
  11. //$tarikh = $_POST['tarikh'];
  12. $tindakan = $_POST['tindakan'];
  13. $agihan = $_POST['agihan'];
  14.  
  15. $connection = mysql_connect("localhost","root","") or die ("Could Not Connect To Server".mysql_error());
  16. $selection = mysql_select_db("permohonan_data") or die ("Could Not Connect To Database".mysql_error());
  17.  
  18. //$sql= "UPDATE pemohon SET tarikh='$tarikh', tindakan='$tindakan', agihan='$agihan', WHERE id='$noid'";
  19. $sql= "UPDATE pemohon SET tindakan='$tindakan', agihan='$agihan', WHERE id='$id'";
  20. $result = mysql_query($sql) or die (mysql_error());
  21.  
  22. if($result)
  23. {   
  24. ?>
  25.     <script language="javascript">
  26.     alert("Permohonan <?php echo "$name"; ?> telah dikemaskini");
  27.     location.href="admin.php";
  28.     </script>
  29.  
  30. <?php
  31. }
  32.  
  33. ?>
but it turned out to be errors which I didn't know what to do. please help me

this is the errors,

Notice: Undefined index: id in C:\wamp\www\FORM\update2.php on line 6

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 id=''' at line 1
Feb 18 '14 #1
15 1645
POST is not sending any variable named "id" , please check you HTML form.
Feb 18 '14 #2
leesyaa
20
but I have the id? :(

Expand|Select|Wrap|Line Numbers
  1. <div id="welcome">
  2.     <?php
  3.     include('config.php');
  4.  
  5.     $sql = "SELECT * FROM pemohon WHERE id='".$_POST['id']."'";
  6.     $results = mysql_query($sql);
  7.  
  8.     $row = mysql_fetch_array($results);
  9.     //$user = $row['username'];
  10.  
  11.  
  12.     $id = $row['id'];
  13.     $name = $row['name'];
  14.     $jawatan = $row['jawatan'];
  15.     $unit = $row['unit'];
  16.     $kementerian = $row['kementerian'];
  17.     $telefon = $row['telefon'];
  18.     $faks = $row['faks'];
  19.     $email = $row['email'];
  20.     $data = $row['data'];
  21.     $tujuan = $row['tujuan'];
  22.     $tarikh = $row['tarikh'];
  23.     $tindakan = $row['tindakan'];
  24.  
  25.     $id = $_POST['id'];
  26.     $submit = $_POST['submit'];
  27.     ?>
  28.  
  29.     <form name="update" action="update2.php" method="post">
  30.         <table width="763" align="center">
  31.             <tr>
  32.                 <td>No. ID</td>
  33.                 <td>:</td>
  34.                 <td><?php echo "$id"; ?></td>
  35.             </tr>
  36.             <tr>
  37.                 <td width="173">Nama Pemohon</td>
  38.                 <td width="10">:</td>
  39.                 <td width="564"><?php echo "$name"; ?></td>
  40.             </tr>
  41.             <tr>
  42.                 <td>Jawatan</td>
  43.                 <td>:</td>
  44.                 <td><?php echo "$jawatan"; ?></td>
  45.             </tr>
  46.             <tr>
  47.                 <td>Unit/Jabatan/Bahagian</td>
  48.                 <td>:</td>
  49.                 <td><?php echo "$unit"; ?></td>
  50.             </tr>
  51.             <tr>
  52.                 <td>Kementerian/Institusi/Agensi</td>
  53.                 <td>:</td>
  54.                 <td><?php echo "$jawatan"; ?></td>
  55.             </tr>
  56.             <tr>
  57.                 <td>No. Telefon</td>
  58.                 <td>:</td>
  59.                 <td><?php echo "$telefon"; ?></td>
  60.             </tr>
  61.             <tr>
  62.                 <td>No. Faks</td>
  63.                 <td>:</td>
  64.                 <td><?php echo "$faks"; ?></td>
  65.             </tr>
  66.             <tr>
  67.                 <td>E-mail</td>
  68.                 <td>:</td>
  69.                 <td><?php echo "$email"; ?></td>
  70.             </tr>
  71.             <tr>
  72.                 <td>Data/Laporan Yang Dipohon</td>
  73.                 <td>:</td>
  74.                 <td><?php echo "$data"; ?></td>
  75.             </tr>
  76.             <tr>
  77.                 <td>Tujuan</td>
  78.                 <td>:</td>
  79.                 <td><?php echo "$tujuan"; ?></td>
  80.             </tr>
  81.             <tr>
  82.                 <td>Tarikh Permohonan</td>
  83.                 <td>:</td>
  84.                 <td><?php echo "$tarikh"; ?></td>
  85.             </tr>
  86.             <tr>
  87.                 <td>Tindakan</td>
  88.                 <td>:</td>
  89.                 <td><label>
  90.                     <select name="tindakan" id="tindakan">
  91.                     <option selected="selected"></option>
  92.                     <option>Diluluskan</option>
  93.                     <option>Tidak Diluluskan</option>
  94.                     </select>
  95.                     </label>
  96.             </tr>
  97.             <tr>
  98.                 <td>Agihan</td>
  99.                 <td>:</td>
  100.                 <td><label>
  101.                     <select name="agihan" id="agihan">
  102.                     <option selected="selected"></option>
  103.                     <option>Pn. Suryana Binti Embong</option>
  104.                     <option>Pn. Rohaida Binti Ali</option>
  105.                     <option>En. Hasril Rezuan Bin Suboh</option>
  106.                     </select>
  107.                     </label>
  108.             </tr>
  109.  
  110.     <p align="center">
  111.     <input type="hidden" name="noid" value="<?php echo $id; ?>">
  112.     <input type="hidden" name="name" value="<?php echo $name; ?>">
  113.     <input name="submit" type="submit" id="submit" value="Kemaskini" />
  114.  
  115.     </p>
  116.     </form>
  117.     </div>
Feb 18 '14 #3
Dormilich
8,658 Expert Mod 8TB
but I have the id? :(
where ?
Feb 18 '14 #4
leesyaa
20
its not the $id = $_POST['id']?
Feb 18 '14 #5
Dormilich
8,658 Expert Mod 8TB
but PHP tells you there is no $_POST['id'] (and I agree with that).
Feb 18 '14 #6
leesyaa
20
@Dormilich can you please tell me where I code wrong? :(
Feb 18 '14 #7
Dormilich
8,658 Expert Mod 8TB
in your HTML form.
Feb 18 '14 #8
Luuk
1,047 Expert 1GB
Change line #4 from
Expand|Select|Wrap|Line Numbers
  1. $id = $_POST['id'];
to something like:
Expand|Select|Wrap|Line Numbers
  1. if (!isset($_POST['id']) {
  2.        $id = $_POST['id']; 
  3. } else {
  4.        $id = 999999999;
and........
Dont ask where '999999999' is coming from ;)
Feb 18 '14 #9
leesyaa
20
@Luuk it's still displaying the same error :(
Feb 19 '14 #10
Dormilich
8,658 Expert Mod 8TB
show your actual code.
Feb 19 '14 #11
leesyaa
20
@dormilich I have update the code, see above :)
Feb 19 '14 #12
Dormilich
8,658 Expert Mod 8TB
weeelll, if you uncomment Luuk’s code, essentially resulting in the original code, what else do you expect than the original error?
Feb 19 '14 #13
leesyaa
20
@Dormilich, ah I forget to mention, but I test Luuk's code already, which is resulting the same error.
Feb 19 '14 #14
Dormilich
8,658 Expert Mod 8TB
then you’re not or wrongly using Luuk’s code. it is coded exactly to prevent that error. (that it does not fix the real cause is a different matter)
Feb 19 '14 #15
Luuk
1,047 Expert 1GB
Some info is missing here
- the actual 'complete' code (don't change the first post, just make a new entry with the last version of your code )
- the actual error message (not a description of this error message, please simply copy/paste the message here)

I, and presumably Dormlich also, have no crystal ball..... ;)
Feb 22 '14 #16

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

Similar topics

1
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still...
5
by: news.bigpond.com | last post by:
getting errors Notice: Undefined index: name in F:\uni\Software engineering\assignment4\guestbook.php on line 6 the variable $name is declared as $name = _POST; What could be causing this?...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
3
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
5
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my...
3
by: sickboy | last post by:
$channels=$_GET; if (empty($channels)) { $channels='blank'; } changechannels($channels); $theatre=$_GET; if (empty($theatre)) { $theatre='splash'; } changetheatre($theatre); $info=$_GET; if...
3
by: razvanel442 | last post by:
Hi all i am new here! I take a look on forum but i don't found a the answer for my problem ok this is my problem: Line47:$user = $_GET; Line48:$pass = $_GET; Line49:$char = $_GET;
3
by: mediator | last post by:
Hello I have a php contact email form on my a ecommerce shop website ! I am getting a Undefined index error messages coming from the top of the php code, the email form its self works fine, ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.