googlit Posted October 11, 2012 Share Posted October 11, 2012 Hi all, im wanting to create a basic update script which pulls data from two tables and then puts data to two tables. i am currently getting : Notice: Undefined index: product_id in edit.php on line 26 SQL: select * from jos_vm_product, jos_vm_product_price WHERE jos_vm_product.product_id AND jos_vm_product_price.product_id= >> 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 '' at line 1 this is the code i have: my update script which displays the records in the table with a link to the edit form <?php //include database configuration include 'config_open_db.php'; //selecting records $sql="select jos_vm_product.product_id, jos_vm_product.product_name, jos_vm_product.product_s_desc, jos_vm_product_price.product_id, jos_vm_product_price.product_price from jos_vm_product, jos_vm_product_price"; //query the database $rs=mysql_query($sql) or die($sql.">>".mysql_error()); //count how many records found $num=mysql_num_rows($rs); if($num>0){ //check if more than 0 record found echo "<table border='1'>"; echo "<tr>"; echo "<th>Product name</th>"; echo "<th>Product Tag Line</th>"; echo "<th>Product Price</th>"; echo "<th>Action</th>"; echo "</tr>"; //retrieve ocontents while($row=mysql_fetch_array($rs)){ extract($row); echo "<tr>"; echo "<td>{$product_name}</td>"; echo "<td>{$product_s_desc}</td>"; echo "<td>{$product_price}</td>"; echo "<td>"; echo "<a href='edit.php?id={$product_id}'>Edit</a>"; echo "</td>"; echo "</tr>"; } echo "</table>"; }else{ //if no records echo "No records found."; } ?> and my edit form (edit.php) <?php include 'config_open_db.php'; //check if an action was set isset($_POST['action']) ? $action=$_POST['action'] : $action=""; if($action=="edit"){ //update the record $sql="update jos_vm_product, jos_vm_product_price set product_name='{$_POST['product_name']}', product_s_desc='{$_POST['product_s_desc']}', product_price='{$_POST['product_price']}', product_weight={$_POST['product_weight']}' where product_id={$_POST['id']}"; if(mysql_query($sql)){ echo "<div>Record was edited.</div>"; }else{ die("SQL: ".$sql." >> ".mysql_error()); } } $id=$_REQUEST['product_id']; //the user id $sql="select * from jos_vm_product, jos_vm_product_price WHERE jos_vm_product.product_id AND jos_vm_product_price.product_id={$id}"; $rs=mysql_query($sql) or die("SQL: ".$sql." >> ".mysql_error()); $num=mysql_num_rows($rs); if($num>0){ $row=mysql_fetch_assoc($rs); extract($row); ?> <!--we have our html form here where new user information will be entered--> <form action='#' method='post' border='0'> <table> <tr> <td>Product Name</td> <td><input type='text' name='product_name' value='<?php echo $product_name; ?>' /></td> </tr> <tr> <td>Product Tag Line</td> <td><input type='text' name='product_s_desc' value='<?php echo $product_s_desc; ?>' /></td> </tr> <tr> <td>Product Price</td> <td><input type='text' name='product_price' value='<?php echo $product_price; ?>' /></td> </tr> <tr> <td>Product_weight</td> <td><input type='text' name='product_weight' value='<?php echo $product_weight; ?>' /></td> <tr> <td></td> <td> <!-- so that we could identify what record is to be updated --> <input type='hidden' name='id' value='<?php echo $id ?>' /> <!-- we will set the action to edit --> <input type='hidden' name='action' value='edit' /> <input type='submit' value='Edit' /> </td> </tr> </table> </form> <?php }else{ echo "<div>User with this id is not found.</div>"; } echo "<a href='update.php'>Back To List</a>"; ?> i also need to limit the results to 30 and add pages for next 30 results etc but am unsure how.... any help will be greatly appreciated.. Quote Link to comment https://forums.phpfreaks.com/topic/269350-crud-basic-script-help/ Share on other sites More sharing options...
Beeeeney Posted October 11, 2012 Share Posted October 11, 2012 Surely from those errors you can see where the problem lies? Quote Link to comment https://forums.phpfreaks.com/topic/269350-crud-basic-script-help/#findComment-1384479 Share on other sites More sharing options...
googlit Posted October 11, 2012 Author Share Posted October 11, 2012 (edited) If i had, i wouldn't be here would i? i error states issue with the query however the query runs without issue in navicat/phpmyadmin Edited October 11, 2012 by googlit Quote Link to comment https://forums.phpfreaks.com/topic/269350-crud-basic-script-help/#findComment-1384481 Share on other sites More sharing options...
googlit Posted October 11, 2012 Author Share Posted October 11, 2012 Ok so staring at it for a few more minutes has made me realise the error of my ways: } $id=$_REQUEST['product_id']; //the user id should have been: } $id=$_REQUEST['id']; //the user id but how do i limit results in the querry?? Quote Link to comment https://forums.phpfreaks.com/topic/269350-crud-basic-script-help/#findComment-1384482 Share on other sites More sharing options...
MDCode Posted October 11, 2012 Share Posted October 11, 2012 You will need to learn pagination if you are going to display on one file but to get started just add LIMIT 30 to the query. Quote Link to comment https://forums.phpfreaks.com/topic/269350-crud-basic-script-help/#findComment-1384484 Share on other sites More sharing options...
googlit Posted October 11, 2012 Author Share Posted October 11, 2012 ok, thanks for that, my intention is to have more than 30 records so is there a way to limit per page and to auto calculate the number of pages and asign links etc etc..... can you point me in the right direction thanks for your help so far.... Quote Link to comment https://forums.phpfreaks.com/topic/269350-crud-basic-script-help/#findComment-1384485 Share on other sites More sharing options...
premiso Posted October 11, 2012 Share Posted October 11, 2012 http://www.phpfreaks.com/tutorial/basic-pagination Quote Link to comment https://forums.phpfreaks.com/topic/269350-crud-basic-script-help/#findComment-1384532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.