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

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\Ap

P: 2
Hi..
I am new here and new to php too..
Can anyone help me to check where is the error?
This is the warning coming after I click submit for update data..

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\AppServ\www\pqs\guard\update_staff1.php on line 25

And this is my code for update.

update_staff.php
Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script src="datetimepicker_css.js"></script>
  3. </head>
  4.  
  5. <?php
  6. $con = mysql_connect("localhost","root","root");
  7. if (!$con)
  8.   {
  9.   die('Could not connect: ' . mysql_error());
  10.   }
  11.  
  12. mysql_select_db("pqs", $con);
  13. $ref1 = $_REQUEST['ref1'];
  14. $result = mysql_query("SELECT Staff_name, Staff_id_no, Staff_jawatan, Staff_dept, Staff_purpose, staff_date, Staff_time_in, Staff_Time_out FROM staffdb WHERE Staff_id = '$ref1' LIMIT 0,1");
  15. ?>
  16.  
  17. <script type="text/javascript">
  18. function show_alert()
  19. {
  20. var msg = "Successful : Your data saved";
  21. alert(msg);
  22. }
  23. </script>
  24.  
  25. <form name="form1" method="post" action="update_staff1.php">
  26.  
  27. <p>&nbsp;</p>
  28. <table width="476" border="0" align="center">
  29.   <tr>
  30.     <th colspan="3" scope="col"><div align="center">Rekod Staff Masuk Selepas Waktu Bekerja </div>
  31.         <div align="left"></div></th>
  32.   </tr>
  33.  
  34.     <?php while($row = mysql_fetch_array($result))
  35.                 {
  36.                 ?>
  37.  
  38.     <input type="hidden" name="Staff_id" value="<?php echo $ref1; ?>" />
  39.   <tr>
  40.     <th width="150" scope="row"><div align="right">Nama</div></th>
  41.     <td width="5"><div align="center"><strong>:</strong></div></td>
  42.     <td width="299"><div align="left">
  43.       <input name="Staff_name" type="text" id="Staff_name" value="<?php echo $row['Staff_name'];?>" size="40">
  44.     </div></td>
  45.   </tr>
  46.   <tr> 
  47.     <th scope="row"><div align="right">No. Pass </div></th>
  48.     <td><div align="center"><strong>:</strong></div></td>
  49.     <td><div align="left">
  50.       <input name="Staff_id_no" type="text" id="Staff_id_no" value="<?php echo $row['Staff_id_no'];?>" size="40">
  51.     </div></td>
  52.   </tr>
  53.   <tr>
  54.     <th scope="row"><div align="right">Jawatan</div></th>
  55.     <td><div align="center"><strong>:</strong></div></td>
  56.     <td><div align="left">
  57.       <input name="Staff_jawatan" type="text" id="Staff_jawatan" value="<?php echo $row['Staff_jawatan'];?>" size="40">
  58.     </div></td>
  59.   </tr>
  60.   <tr>
  61.     <th scope="row"><div align="right">Jabatan</div></th>
  62.     <td><div align="center"><strong>:</strong></div></td>
  63.     <td><div align="left">
  64.       <input name="Staff_dept" type="text" id="Staff_dept" value="<?php echo $row['Staff_dept'];?>" size="40">
  65.     </div></td>
  66.   </tr>
  67.   <tr>
  68.     <th scope="row"><div align="right">Tujuan</div></th>
  69.     <td><div align="center"><strong>:</strong></div></td>
  70.     <td><div align="left">
  71.       <textarea name="Staff_purpose" cols="40" id="Staff_purpose"><?php echo $row['Staff_purpose'];?></textarea>
  72.     </div></td>
  73.   </tr>
  74.   <tr>
  75.     <th scope="row"><div align="right">Tarikh</div></th>
  76.     <td><div align="center"><strong>:</strong></div></td>
  77.     <td><div align="left">
  78.       <input name="staff_date" type="text" id="staff_date" value="<?php echo $row['staff_date'];?>" />
  79.       <a href="javascript:NewCssCal('staff_date','yyyymmdd','arrow')" title="Click on the calendar to enter date"> <img src="http://bytes.com/submit/images/cal.gif" width="16" height="16" alt="Pick a date" /></a> </div></td>
  80.   </tr>
  81.   <tr>
  82.     <th scope="row"><div align="right">Masa masuk </div></th>
  83.     <td><div align="center"><strong>:</strong></div></td>
  84.     <td><div align="left">
  85.       <input name="Staff_time_in" type="text" id="Staff_time_in" value="<?php echo $row['Staff_time_in'];?>" />
  86.       <a href="javascript:NewCssCal('Staff_time_in','24','true of false','arrow')" title="Click on the calendar to enter date"> <img src="http://bytes.com/submit/images/cal.gif" width="16" height="16" alt="Pick a time" /></a> </div></td>
  87.   </tr>
  88.   <tr>
  89.     <th scope="row"><div align="right">
  90.       <div align="right">Masa keluar </div>
  91.     </div></th>
  92.     <td><div align="center"><strong>:</strong></div></td>
  93.     <td><div align="left">
  94.       <input name="Staff_Time_out" type="text" id="Staff_Time_out" value="<?php echo $row['Staff_Time_out'];?>" />
  95.       <a href="javascript:NewCssCal('Staff_Time_out','24','true of false','arrow')" title="Click on the calendar to enter date"> <img src="http://bytes.com/submit/images/cal.gif" width="16" height="16" alt="Pick a time" /></a> </div></td>
  96.   </tr>
  97.     <?php }?>
  98.  
  99.   <tr>
  100.     <th colspan="3" scope="row"><div align="right"></div>
  101.         <div align="center"></div>
  102.       <div align="left"></div></th>
  103.   </tr>
  104.   <tr>
  105.     <th colspan="3" scope="row"> <div align="center">
  106.       <input name="update" type="submit" id="update" value="Update" onclick="show_alert()"/>
  107.       <input name="back" type="submit" id="back" value="Back"/>
  108.     </div>
  109.         <div align="center"></div>
  110.       <div align="left"></div></th>
  111.   </tr>
  112. </table>
  113.  
  114. <?php 
  115. mysql_close($con);
  116. ?>
  117. </form>
update_staff1.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if (isset($_POST['submit'])){
  3.  
  4. $link = mysql_connect("localhost","root","root") or die ("Could not connect to the Database Server!");
  5. $db = mysql_select_db("pqs", $link) or die ("Could not select Database!");
  6.  
  7. $Staff_id = $_POST['Staff_id'];
  8. $Staff_id_no = $_POST['Staff_id_no'];
  9. $Staff_name = $_POST['Staff_name'];
  10. $Staff_purpose = $_POST['Staff_purpose'];
  11. $Staff_time_in = $_POST['Staff_time_in'];
  12. $Staff_Time_out = $_POST['Staff_Time_out'];
  13. $Staff_dept = $_POST['Staff_dept'];
  14. $Staff_jawatan = $_POST['Staff_jawatan'];
  15. $staff_date = $_POST['staff_date'];
  16.  
  17. $result=mysql_query("UPDATE staffdb SET Staff_id_no = '$Staff_id_no', Staff_name = '$Staff_name', Staff_purpose = '$Staff_purpose', Staff_time_in = '$Staff_time_in', Staff_Time_out = '$Staff_Time_out', Staff_dept = '$Staff_dept', Staff_jawatan = '$Staff_jawatan', staff_date = '$staff_date' WHERE Staff_id = '$Staff_id'");
  18. }
  19.  
  20. if($result){
  21.  
  22. echo "<script type='text/javascript'>window.location='index.php?page=list_staff.php'</script>";
  23. }
  24.  
  25. mysql_close($link);
  26. ?>
  27.  
Can somebody help me to find the error?
Really needs your help.
Thanks in advance.. :)
Sep 27 '11 #1
Share this Question
Share on Google+
2 Replies


100+
P: 1,059
It is suppose to...
because you have created $link variable in the if condition, but you closed your link outside the link condition,

if the condition failed then, your link wont be created but will try to release it. fix it
Sep 27 '11 #2

P: 2
It's still same when I put the $link inside the if condition.
There is no error occur but the database not updated and going to be blank form too..
So, do you know anywhere can I fix the error?Still don't get the error..
Sep 27 '11 #3

Post your reply

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

Browse more PHP Questions on Bytes