Peterod Posted August 26, 2010 Share Posted August 26, 2010 heres the code... <?php mysql_connect("localhost","peter","tizer") or die("Error: ".mysqlerror()); mysql_select_db("matquant"); //replace TestTable with the name of your table //also in a real app you would get the id dynamically $idtochange=$_POST['idtochange']; $sql="select * from `quantites` where id = $idtochange"; $query=mysql_query($sql); while ($row=mysql_fetch_array($query)){ $id = $row['id']; $material = $row['material']; $quantity = $row['quantity']; $unit = $row['unit']; //we will echo these into the proper fields } mysql_free_result($query); ?> <html> <head> <title>Edit material list</title> <link href="css/quant1.css" rel="stylesheet" type="text/css"> </head> <body> <div id="leftcol"> <form "method="post"> <p><br/> <input type="text"value="1" name="idtochange" > <p> <input type="submit"value="submit changes"/> </form> <form action="changequan.php"method="post"> <p>Material Id currently active<br/> <input type="text"value="<?php echo $id;?>" name="id" disabled/> </p> <p> Enter new material name: </p> <input type="text"value="<?php echo $material;?>" name="material"/> <br/> change quantity: <input type="text"value="<?php echo $quantity;?>" name="quantity"/> <br/> unit of mesurement for quantity<br/> <input type="text"value="<?php echo $unit;?>" name="unit"/> <br/> </p> <input type="submit"value="submit changes"/> </form> </div> <div id="rightcol"><?php // make connection mysql_connect ("localhost", "peter", "tizer") or die ('I cannot connect to the database becuase: ' . mysql_error()); mysql_select_db ("matquant"); // build query $query = mysql_query("SELECT * FROM `quantites` ORDER BY `id` ASC"); // display results while ($row = mysql_fetch_array($query)) { echo "<br /> ..... " .$row ['id']. " ....... " .$row ['material']. " ...... " .$row['quantity']. " ...... " .$row['unit']. "<br />";} echo mysql_error(); ?> <a href="index.html">Home </a> <p> <a href="quanform.php">Insert new material and quantity form</a></p></div> </body> </html> I'm struggling with php. Any help anyone can give would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/211840-simple-code-cant-see-problem/ Share on other sites More sharing options...
trq Posted August 26, 2010 Share Posted August 26, 2010 You forgot to describe your actual problem. Quote Link to comment https://forums.phpfreaks.com/topic/211840-simple-code-cant-see-problem/#findComment-1104192 Share on other sites More sharing options...
fortnox007 Posted August 26, 2010 Share Posted August 26, 2010 I just quickly looked because you didnt provide a problem, but this is what i noticed so far. <input type="text"value="1" name="idtochange" > is missing an endtag. so it should look like: <input type="text"value="1" name="idtochange" /> your submit button doens't have a name so it should look more like: <input type="submit" name="submit" value="submit changes" /> Quote Link to comment https://forums.phpfreaks.com/topic/211840-simple-code-cant-see-problem/#findComment-1104202 Share on other sites More sharing options...
MadTechie Posted August 26, 2010 Share Posted August 26, 2010 Check line 72 of all files on your server, if the problem isn't then please re-clarify the problem Quote Link to comment https://forums.phpfreaks.com/topic/211840-simple-code-cant-see-problem/#findComment-1104204 Share on other sites More sharing options...
Peterod Posted August 27, 2010 Author Share Posted August 27, 2010 thanks for that, its getting late lol. I am new to php and miss the obvious bits. Sorry about the crap original post. I will try to describe my problem better. I am simply trying to make a form that will update materials in a list. my page has the form on 1 side and the list on the right. I want to enter an ID in the first instance and then for the form to be populated with the data in the table with the id. I have 2 files . the form page and , ill call it the update engine.... The form page is below (between the horizontal rules. and throws the following errors on load. Notice: Undefined index: idtochange in C:\wamp\www\parkhall\changequanform.php on line 11 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\changequanform.php on line 17 Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\changequanform.php on line 31 [code=php:0]<?php mysql_connect("localhost","peter","tizer") or die("Error: ".mysqlerror()); mysql_select_db("matquant"); //replace TestTable with the name of your table //also in a real app you would get the id dynamically $idtochange=$_POST['idtochange']; // <<<<<<<<<<<<<<<<<<<<<<< line 11 $sql="select * from `quantites` where 'id' = $idtochange"; $query=mysql_query($sql); while ($row=mysql_fetch_array($query)){ $id = $row['id']; $material = $row['material']; $quantity = $row['quantity']; $unit = $row['unit']; //we will echo these into the proper fields } mysql_free_result($query); ?> <html> <head> <title>Edit material list</title> <link href="css/quant1.css" rel="stylesheet" type="text/css"> </head> <body> <div id="leftcol"> <form "method="post"> <p><br/> <input type="text"value="1" name="idtochange" /> <p> <input type="submit"value="submit changes"/> </form> <form action="changequan.php"method="post"> <p>Material Id currently active<br/> <input type="text"value="<?php echo $id;?>" name="id" disabled/> </p> <p> Enter new material name: </p> <input type="text"value="<?php echo $material;?>" name="material"/> <br/> change quantity: <input type="text"value="<?php echo $quantity;?>" name="quantity"/> <br/> unit of mesurement for quantity<br/> <input type="text"value="<?php echo $unit;?>" name="unit"/> <br/> </p> <input type="submit"value="submit changes"/> </form> </div> <div id="rightcol"><?php // make connection mysql_connect ("localhost", "peter", "tizer") or die ('I cannot connect to the database becuase: ' . mysql_error()); mysql_select_db ("matquant"); // build query $query = mysql_query("SELECT * FROM `quantites` ORDER BY `id` ASC"); // display results while ($row = mysql_fetch_array($query)) { echo "<br /> ..... " .$row ['id']. " ....... " .$row ['material']. " ...... " .$row['quantity']. " ...... " .$row['unit']. "<br />";} echo mysql_error(); ?> <a href="index.html">Home </a> <p> <a href="quanform.php">Insert new material and quantity form</a></p></div> </body> </html> [/code] Again, the errors on load of above.... to save scrolling Notice: Undefined index: idtochange in C:\wamp\www\parkhall\changequanform.php on line 11 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\changequanform.php on line 17 Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\changequanform.php on line 31 When I use the first form submit button, it works and updates the id for the second form section, and populates the text boxes with the data. this is the other file, the php for the formpage. <?php mysql_connect("localhost","peter","tizer") or die ("Error: ".mysqlerror()); mysql_select_db("matquant"); $id=$_POST['id']; $material=$_POST['material']; $quantity=$_POST['quantity']; $unit=$_POST['unit']; $sql="UPDATE `quantites` SET `material` = '$material',`quantity` = '$quantity',`unit` = '$unit' WHERE `quantites`.`id` = '$id' LIMIT 1"; mysql_query($sql)or die("Error: ".mysql_error()); echo"Database updated. <a href='changequanform.php'>Return to edit info</a>"; ?> It throws errors when I submit the second part of the form and I have just changes something and broken it further. Any help will be graciously recieved. Regards Peter Quote Link to comment https://forums.phpfreaks.com/topic/211840-simple-code-cant-see-problem/#findComment-1104221 Share on other sites More sharing options...
MadTechie Posted August 27, 2010 Share Posted August 27, 2010 Post doesn't contain idtochange, check your form Quote Link to comment https://forums.phpfreaks.com/topic/211840-simple-code-cant-see-problem/#findComment-1104226 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.