mikebyrne Posted March 18, 2008 Share Posted March 18, 2008 I've just created a new page to allow users to input data, press update and the details will go into the database I need help with the php to process this The code I have now is: <form> <!-- top start --> <div id="container"> <div id="line"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div id="containerBg1"> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="titleText">EDIT ITEM</div> <div class="clr"> <!-- --> </div> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- top finish --> <!-- data title start --> <div id="containerBg2"> <div class="padTop2"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="titleBox"> <table width="850" border="0" cellspacing="0" cellpadding="0"> <tr align="left"> <td width="33"> </td> <td width="290" align="left">IMAGE</td> <td width="527">DETAIL</td> </tr> </table> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data title finish --> <!-- 1px space start --> <div id="containerBg1"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- 1px space finish --> <!-- data top start --> <div id="containerBg3"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data top finish --> <!-- data content start --> <div id="containerBg4"> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="padTop1"> <!-- data Left start --> <div class="editLeft"> <!-- picture1 start --> <div class="editLeftBox">PICTURE 1:</div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="editLeftBox"><img src="<?php echo $row['Image'];?>" alt="pic1" width="150" height="200" /></div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="editLeftBox"> <input type="file" name="uploadfile" class="newsUpFile"> </div> <div class="clr"> <!-- --> </div> <!-- picture1 finish --> <div class="padTop50"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- picture2 start --> <div class="editLeftBox">PICTURE 2:</div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="editLeftBox"><img src="<?php echo $row['Image2'];?>" alt="pic1" width="150" height="200" /></div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="editLeftBox"> <input type="file" name="uploadfile" class="newsUpFile"> </div> <div class="clr"> <!-- --> </div> <!-- picture2 finish --> </div> <!-- data Left finish --> <!-- data Right start --> <div class="editRight"> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Product No:</div> <div class="editRightForm"> <!--MAKES PRODUCT NO READ ONLY--> <input type="text" class="itemEditForm02" name="ProductNo" value="<?php echo $row['ProductNo'];?>" /> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Product Name:</div> <div class="editRightForm"> <input name="0" type="text" class="itemEditForm02" name="ProductName" value="<?php echo $row['ProductName'];?>" /> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Description:</div> <div class="editRightForm"> <textarea type="text" class="itemEditForm03" name="something" ><?php echo $row['Description'];?></textarea> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Remarks:</div> <div class="editRightForm"> <input type="text" class="itemEditForm02" name="0" value="" /> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Price:</div> <div class="editRightForm"> <div class="editItemPrice1">€</div> <div class="editItemPrice2"> <input type="text" class="itemEditForm04" name="0" value="<?php echo $row['Price'];?>" /> </div> <div class="clr"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Sale:</div> <div class="editRightForm"> <div class="editRadioLink1"> <input name="link" type="radio" value="yes" /> </div> <div class="editRadioLink2">Yes</div> <div class="editRadioLink3"> <input name="link" type="radio" value="no" checked="checked" /> </div> <div class="editRadioLink4">No - sale price: € </div> <div class="editRadioLink5"> <input type="text" class="newsEditForm02" name="0" value="0" /> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Display:</div> <div class="editRightForm"> <div class="editRadio1"> <input name="display" type="radio" value="yes" checked="checked" /> </div> <div class="editRadio2">show</div> <div class="editRadio3"> <input name="display" type="radio" value="no" /> </div> <div class="editRadio4">hide</div> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop75"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <!-- data Right finish --> </div> <div class="clr"> <!-- --> </div> <div class="padTop11"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="dottedIn"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <!-- btn start --> <div class="clr"> <!-- --> </div> <div class="padTop16"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="btn"> <div id="btnL"><img src="../Admin_files/btn_update.gif" width="73" height="23" /></div> <div id="btnSpace"> <!-- --> </div> <div id="btnR"><img src="../Admin_files/btn_clear.gif" width="73" height="23" /></div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div class="padTop16"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- btn finish --> </div> <div class="clr"> <!-- --> </div> <!-- data content finish --> <!-- data btm start --> <div id="containerBg3"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data btm finish --> </form> </div> <!-- btm start --> <div id="containerBg1"> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div id="container"> <div id="line"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div class="padTop16"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- btm finish --> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 18, 2008 Share Posted March 18, 2008 INSERT INTO `table` (`field1`, `field2`, `field3`, ...) VALUES ('value1','value2','value3', ...) Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 18, 2008 Author Share Posted March 18, 2008 Im just not sure how to code it around the button I know I should use the following require_once("adminconnect.php"); $tbl_name="product"; $sql="INSERT INTO $tbl_name(ProductNo, , ProductName, Description, Price,)VALUES('$ProductNo', '$ProductName', '$Description', '$Price',)"; Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 18, 2008 Share Posted March 18, 2008 It looks like you've got it. Maybe I'm just not understanding. What piece of the puzzle are you missing? Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 18, 2008 Author Share Posted March 18, 2008 Im trying to code it around the button <!-- --> </div> <div id="btn"> <div id="btnL"><img src="../Admin_files/btn_update.gif" width="73" height="23" /></div> <div id="btnSpace"> <!-- --> So not sure how to put everything together ie set the form etc Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 18, 2008 Share Posted March 18, 2008 This? <form action="page.php" method="post"> <!-- other input stuff that you've already got --> <!-- the submit button --> <input type="submit" name="Submit" value="Submit" /> </form> Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 18, 2008 Author Share Posted March 18, 2008 Is there a way to have the submit button using <div id="btnL"><img src="../Admin_files/btn_update.gif" width="73" height="23" /></div>?? Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 19, 2008 Share Posted March 19, 2008 Because you want the picture as the background of the button? CSS #btnL { background: url('../Admin_files/btn_update.gif') no-repeat center center; width: 73px; height: 23px; } HTML <input id="btnL" type="submit" name="Submit" value="" /> Mess around with that as a starting point. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 19, 2008 Author Share Posted March 19, 2008 My code now looks like this but it doesnt seem to post anything to the db and gives no errors <form action="add.php" onsubmit="return valid()" method="post"> <?PHP require_once("adminconnect.php"); $tbl_name="product"; $sql="INSERT INTO $tbl_name(ProductNo, , ProductName, Description, Price,)VALUES('$ProductNo', '$ProductName', '$Description', '$Price',)"; ?> <!-- 1px space start --> <div id="containerBg1"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- 1px space finish --> <!-- data top start --> <div id="containerBg3"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data top finish --> <!-- data content start --> <div id="containerBg4"> <div class="padTop15"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="padTop1"> <!-- data Left start --> <div class="editLeft"> <!-- picture1 start --> <div class="editLeftBox">PICTURE 1:</div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="editLeftBox"><img src="<?php echo $row['Image'];?>" alt="pic1" width="150" height="200" /></div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="editLeftBox"> <input type="file" name="uploadfile" class="newsUpFile"> </div> <div class="clr"> <!-- --> </div> <!-- picture1 finish --> <div class="padTop50"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- picture2 start --> <div class="editLeftBox">PICTURE 2:</div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="editLeftBox"><img src="<?php echo $row['Image2'];?>" alt="pic1" width="150" height="200" /></div> <div class="clr"> <!-- --> </div> <div class="padTop5"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div class="editLeftBox"> <input type="file" name="uploadfile" class="newsUpFile"> </div> <div class="clr"> <!-- --> </div> <!-- picture2 finish --> </div> <!-- data Left finish --> <!-- data Right start --> <div class="editRight"> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Product No:</div> <div class="editRightForm"> <!--MAKES PRODUCT NO READ ONLY--> <input type="text" class="itemEditForm02" name="ProductNo" value="<?php echo $row['ProductNo'];?>" readonly="readonly" /> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Product Name:</div> <div class="editRightForm"> <input name="0" type="text" class="itemEditForm02" name="ProductName" value="<?php echo $row['ProductName'];?>" /> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Description:</div> <div class="editRightForm"> <textarea type="text" class="itemEditForm03" name="something" ><?php echo $row['Description'];?></textarea> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Remarks:</div> <div class="editRightForm"> <input type="text" class="itemEditForm02" name="0" value="" /> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Price:</div> <div class="editRightForm"> <div class="editItemPrice1">€</div> <div class="editItemPrice2"> <input type="text" class="itemEditForm04" name="0" value="<?php echo $row['Price'];?>" /> </div> <div class="clr"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Sale:</div> <div class="editRightForm"> <div class="editRadioLink1"> <input name="link" type="radio" value="yes" /> </div> <div class="editRadioLink2">Yes</div> <div class="editRadioLink3"> <input name="link" type="radio" value="no" checked="checked" /> </div> <div class="editRadioLink4">No - sale price: € </div> <div class="editRadioLink5"> <input type="text" class="newsEditForm02" name="0" value="0" /> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop3"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- dat start --> <div class="editRightBox"> <div class="editRightText">Display:</div> <div class="editRightForm"> <div class="editRadio1"> <input name="display" type="radio" value="yes" checked="checked" /> </div> <div class="editRadio2">show</div> <div class="editRadio3"> <input name="display" type="radio" value="no" /> </div> <div class="editRadio4">hide</div> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <div class="padTop75"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <!-- data Right finish --> </div> <div class="clr"> <!-- --> </div> <div class="padTop11"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="dottedIn"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- data finish --> <!-- btn start --> <div class="clr"> <!-- --> </div> <div class="padTop16"> <!-- --> </div> <div class="clr"> <!-- --> </div> <div id="btn"> <input id="btnL" type="submit" name="Submit" value="" /> <div id="btnSpace"> <!-- --> </div> <div id="btnR"><img src="../Admin_files/btn_clear.gif" width="73" height="23" /></div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <div class="padTop16"> <!-- --> </div> <div class="clr"> <!-- --> </div> <!-- btn finish --> </div> <div class="clr"> <!-- --> </div> <!-- data content finish --> <!-- data btm start --> <div id="containerBg3"> <div class="padTop1"> <!-- --> </div> <div class="clr"> <!-- --> </div> </div> <div class="clr"> <!-- --> </div> <!-- data btm finish --> </form> Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 19, 2008 Share Posted March 19, 2008 1. <?PHP -- does it need to be <?php 2. This doesn't look like it's formatted correctly. $sql="INSERT INTO $tbl_name(ProductNo, , ProductName, Description, Price,)VALUES('$ProductNo', '$ProductName', '$Description', '$Price',)"; Try? $sql="INSERT INTO `$tbl_name` (`ProductNo`, `ProductName`, `Description`, `Price`) VALUES ('$ProductNo', '$ProductName', '$Description', '$Price')"; 3. Where are you even running the query? You need to use the function mysql_query(). Not to say you don't know what you are doing, but maybe you should read an introduction to writing queries. Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 19, 2008 Author Share Posted March 19, 2008 Im using <form action="add.php" onsubmit="return valid()" method="post"> <?PHP require_once("adminconnect.php"); $tbl_name="product"; $sql="INSERT INTO $tbl_name(ProductNo, , ProductName, Description, Price,)VALUES('$ProductNo', '$ProductName', '$Description', '$Price',)"; $result = mysql_query($query) or die (mysql_error()); ?> And Im getting "Query was empty" when the page loads Quote Link to comment Share on other sites More sharing options...
lemmin Posted March 19, 2008 Share Posted March 19, 2008 That is because your query string is in $sql, not $query. Change it to: $result = mysql_query($sql) or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 19, 2008 Author Share Posted March 19, 2008 Thanks Now Imgetting the 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 ' ProductName, Description, Price,)VALUES('', '', '', '',)' at line 1 Quote Link to comment Share on other sites More sharing options...
soycharliente Posted March 19, 2008 Share Posted March 19, 2008 Did you even read my last post?? Look at #2. 2. This doesn't look like it's formatted correctly. $sql="INSERT INTO $tbl_name(ProductNo, , ProductName, Description, Price,)VALUES('$ProductNo', '$ProductName', '$Description', '$Price',)"; Try? $sql="INSERT INTO `$tbl_name` (`ProductNo`, `ProductName`, `Description`, `Price`) VALUES ('$ProductNo', '$ProductName', '$Description', '$Price')"; Quote Link to comment Share on other sites More sharing options...
mikebyrne Posted March 19, 2008 Author Share Posted March 19, 2008 When i press the submit button Im getting the error Duplicate entry '0' for key 1 even if the fields are all blank Quote Link to comment 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.