zpupster Posted April 5, 2017 Share Posted April 5, 2017 Hello PHP Freaks, First Post: I am writing a page to UPDATE some table fields. this works OK! //Select Query $result = mysql_query( "SELECT products.products_id AS id, products_description.products_name AS name, products.products_quantity AS quantity, products.products_weight AS weight, products.products_price AS price FROM products, products_description WHERE products.products_id=products_description.products_id;") or die(mysql_error()); //$sql = SELECT products.products_id, products_description.products_name, products.products_price, //products.products_quantity, products.products_weight` //FROM //`products` //JOIN `products_description WHERE products.products_id = products_description.products_id echo "<table width='90%'>"; echo "<tr>"; echo "<th width='8%'>Id</th>"; echo "<th width='30%'>Name</th>"; echo "<th width='15%'>Quantity</th>"; echo "<th width='15%'>Weight</th>"; echo "<th width='15%'>Price</th>"; echo "<th width='7%'>Update</th></tr></table>"; while($row = mysql_fetch_array ($result)) { echo "<table width='90%'>"; echo "<tr><form action = update.php method = post><td width='8%'>"; echo $row['id']; echo "</td><td width='50%'>"; echo $row['name']; echo "</td><td width='5%'><input type=text name=quantity value='".$row['quantity']."'></td>"; echo "<td width='10%'><input type=text name=weight value='".$row['weight']."'></td>"; echo "<td width='10%'><input type=text name=price value='".$row['price']."'></td>"; echo "<td width='7%'><input type=submit value='Update'></td>"; echo "</form></tr></table>"; } ?> This is giving Error-Not Updated //Update Query $result = "UPDATE products INNER JOIN products_description ON (products.products_id = products_description.products_id) SET id ='.$id.', name ='.$name.,' , quantity = '$_POST[quantity]', weight = '$_POST[weight]', price= '$_POST[price]', WHERE 'products.products_id' = 'products_description.products_id'"; //Execute Query if (mysql_query($result)) header("Location: davesConnectDB.php"); else echo "Not Updated!"; ?> It was updating but in the wrong record, I have been working on this for a long time. Help is greatly appreciated. TY, Zpupster Link to comment Share on other sites More sharing options...
ginerjm Posted April 5, 2017 Share Posted April 5, 2017 Turn on php error checking and you should see a bunch of syntax errors due to the missing quotes all over your html. Are you really trying to create a separate table for each record in the query result? Link to comment Share on other sites More sharing options...
benanamen Posted April 5, 2017 Share Posted April 5, 2017 What you really need to do is get rid of that obsolete, insecure and dangerous code and start using PDO like you should be. https://phpdelusions.net/pdo And for gawd sake, stop echoing HTML. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.