I am trying to code an update sql command which can be seen in the code below, however, i am getting the following error: -

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/qchqsdju/public_html/project/lines/update_line.php on line 40.

The code is: -

<?
// Connect database. 
include("../db/db_connect.php");

// ***** This part will process when you Click on "Submit" button ***** 
if($_POST['Submit']){

// Get parameters from form. 
$barcode=$_POST['barcode'];
$product=$_POST['product'];
$department=$_POST['department'];
$mpl=$_POST['mpl'];
$price=$_POST['price'];

// Do update statement. 
mysql_query("update lines set barcode='$barcode', product='$product', department='$department', mpl='$mpl', price='$price' where barcode='$barcode'");

// Re-direct this page to select.php.
header("location:view_lines.php");
exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php 
$id=$_GET['barcode'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from lines where id='$id'");

// Split records in $result by table rows and put them in $row. 
$row=mysql_fetch_assoc($result);

// Close database connection. 
mysql_close();
?>

Does anyone know why I am getting this error?

Any help will be appreciated.

one thing i suggest you do is do some exception handling with die.

so your it should be like:

mysql_query(your query) or die (mysql_error)... best way to check for errors

I am trying to code an update sql command which can be seen in the code below, however, i am getting the following error: -

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/qchqsdju/public_html/project/lines/update_line.php on line 40.

The code is: -

<?
// Connect database. 
include("../db/db_connect.php");

// ***** This part will process when you Click on "Submit" button ***** 
if($_POST['Submit']){

// Get parameters from form. 
$barcode=$_POST['barcode'];
$product=$_POST['product'];
$department=$_POST['department'];
$mpl=$_POST['mpl'];
$price=$_POST['price'];

// Do update statement. 
mysql_query("update lines set barcode='$barcode', product='$product', department='$department', mpl='$mpl', price='$price' where barcode='$barcode'");

// Re-direct this page to select.php.
header("location:view_lines.php");
exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php 
$id=$_GET['barcode'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from lines where id='$id'");

// Split records in $result by table rows and put them in $row. 
$row=mysql_fetch_assoc($result);

// Close database connection. 
mysql_close();
?>

Does anyone know why I am getting this error?

Any help will be appreciated.

Hello,

Well first of all i suggest you remove the exit on line 20.

Secondly, can I see the code of select.php?

There are a couple of possibliities i suspect:
first, did you forget to NAME your barcode field. If yes, add the name attribute of the name input field like:

<input type = "text" name = "barcode" ..... />

The .... are for other attributes if needed!

Second: Did you mention the method as GET or POST in the form in select.php?

and is it select.php or view_lines.php?

anyway, do reply to me asap!

I am trying to code an update sql command which can be seen in the code below, however, i am getting the following error: -

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/qchqsdju/public_html/project/lines/update_line.php on line 40.

The code is: -

<?
// Connect database. 
include("../db/db_connect.php");

// ***** This part will process when you Click on "Submit" button ***** 
if($_POST['Submit']){

// Get parameters from form. 
$barcode=$_POST['barcode'];
$product=$_POST['product'];
$department=$_POST['department'];
$mpl=$_POST['mpl'];
$price=$_POST['price'];

// Do update statement. 
mysql_query("update lines set barcode='$barcode', product='$product', department='$department', mpl='$mpl', price='$price' where barcode='$barcode'");

// Re-direct this page to select.php.
header("location:view_lines.php");
exit;
}
// ************* End update part *************

// *** Select data to show on text fields in form. ***

// Get id parameter (GET method) from select.php 
$id=$_GET['barcode'];

// Get records in all columns from table where column id equal in $id and put it in $result.
$result=mysql_query("select * from lines where id='$id'");

// Split records in $result by table rows and put them in $row. 
$row=mysql_fetch_assoc($result);

// Close database connection. 
mysql_close();
?>

Does anyone know why I am getting this error?

Any help will be appreciated.

I can added the following code: -

$result=mysql_query("select * from lines where id='$id'");
if (!$result)
  {
  die('Error: ' . mysql_error());
  }

And I now get this error: -
Error: 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 'lines where id=''' at line 1

Can anyone help please?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.