balkan7 Posted October 27, 2006 Share Posted October 27, 2006 i have create litle script but i have just only table from datebase, so my problem is not take query values from fields in mysql, only show field key and date, and help me how to finish my litle script and create category for my products, here is competed script:base.sql[code]CREATE TABLE products ( id int(5) NOT NULL auto_increment, key varchar(25) NOT NULL default '', product varchar(65) NOT NULL default '', detail longtext NOT NULL, select varchar(65) NOT NULL default '', date varchar(25) NOT NULL default '', new varchar(25) NOT NULL default '',category varchar(65) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM AUTO_INCREMENT=1 ; [/code]config.php[code]<?php$dbhost = "localhost";$dbname = "xxx";$dbuser = "xxx";$dbpassword = "xxx";$title = "Products";$add = "Add new Product";$key1 = "Key";$product1 = "Product";$detail1 = "Detail";$new1 = "New";$select1 = "Select";$category1 = "Category";$date1 = "Date";?>[/code]index.php[code]<?php include("config.php"); // Connect to server and select database. $db = mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server "); mysql_select_db("$dbname")or die("cannot select DB"); $sql = "SELECT * FROM products ORDER BY id DESC"; $result = mysql_query($sql,$db) or die(mysql_error()); ?> <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title><?php echo $title; ?></title> </head> <body bgcolor="#C0C0C0"> <div align="center"> <table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0"> <tr> <td bordercolor="#808080"> <p> </p> <p> </td> </tr> </table> <table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF"> <tr> <td bordercolor="#808080"> </td> </tr> </table> <?php // Start looping table row while($rows = mysql_fetch_array($result)){ ?> <table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0"> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600"> <p align="center"><?php echo $key1; ?></td> <td bordercolor="#808080" style="border-style: solid; border-width: 1px" bgcolor="#FF6600"> <p align="center"><?php echo $product1; ?></php></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600"> <p align="center"><?php echo $detail1; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600"> <p align="center"><?php echo $select1; ?></td> </tr> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <p align="center"> <?php echo $rows['key']; ?></td> <td bordercolor="#808080" style="border-style: solid; border-width: 1px"> <p align="center"><?php echo $rows['product']; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <p align="center"> <?php echo $rows['detail']; ?><?php echo $rows['new']; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <p align="center"> <?php echo $rows['select']; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <p align="center"> <?php echo $rows['category']; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <p align="center"> <?php echo $rows['date']; ?></td> </tr> </table> </div> <div align="center"> <table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF"> <tr> <td bordercolor="#808080"> <p align="center"> </p> <p align="center"></p> <p align="center"> </td> </tr> </table> </div> </body> </html> <?php } ?>[/code]add.php[code]<?php include("config.php"); ?> <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title><?php $title; ?></title> </head> <body bgcolor="#C0C0C0"> <div align="center"> <table border="1" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0"> <tr> <td bordercolor="#808080"> <p> </p> <p> </td> </tr> </table> <table border="1" width="90%" cellpadding="0" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF"> <tr> <td bordercolor="#808080"> </td> </tr> </table> <table border="0" width="90%" style="border-left-style: solid; border-left-width: 2px; border-right: 2px solid #FFFFFF; border-top-style: solid; border-top-width: 2px; border-bottom: 2px solid #FFFFFF" cellpadding="0"> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080" bgcolor="#FF6600" colspan="2"> <p align="center"><?php echo $add; ?></td> </tr> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <?php echo $key1; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <input type="hidden" name="key" size="53" /></td> </tr> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <?php echo $product1; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <input type="text" name="product" size="53" /></td> </tr> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <?php echo $detail1; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <textarea rows="4" cols="45" name="detail"></textarea></td> </tr> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <?php echo $new1; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <input type="checkbox" name="new" value="new"></td> </tr> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <?php echo $select1; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <select size="1" name="select"> <option selected>- Select -</option> <option>1</option> <option2</option> <option3</option> <option4</option> <option5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> </select></td> </tr> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <?php echo $category1; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <select size="1" name="category"> <option selected>- Category -</option> <option>Name 1</option> <option>Name 2</option> <option>Name 3</option> </select></td> </tr> <tr> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <?php echo $date1; ?></td> <td style="border-style: solid; border-width: 1px" bordercolor="#808080"> <?php echo $date; ?></td> </tr> </table> <table border="1" width="90%" cellpadding="0" style="border: 2px solid #FFFFFF"> <tr> <td bordercolor="#808080"> <p align="center"><br> <form id="form1" name="form1" method="post" action="add.php"> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Clear"><br> </td> <tr> <td width="70%" align=right> <div align="center"> <?php $db = mysql_connect("$dbhost", "$dbuser", "$dbpassword")or die("cannot connect server "); mysql_select_db("$dbname")or die("cannot select DB"); if($_POST['Submit']) { $string = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $key = ""; for($i=0; $i<5; $i++){ $y = rand(0,strlen($string)-1); $key .= $string[$y]; } $product = $_POST['product']; $detail = $_POST['detail']; $select = $_POST['select']; $date = date("d/m/y h:i:s"); $new = $_POST['new']; $category = $_POST['category']; $sql = "INSERT INTO `products` (`id`, `key`, `product`, `detail`, `select`, `date`, `new`, `category`) VALUES ('', '$key', '$product', '$detail', '$select', '$date', '$new', '$category')" or die('insert into is wrong'); mysql_query($sql,$db) or die('query is wrong.'); print "Product Added Successfull."; } ?> </div></td> </tr> </table> </div> </body> </html>[/code] Quote Link to comment Share on other sites More sharing options...
balkan7 Posted October 27, 2006 Author Share Posted October 27, 2006 view demo: [code]http://www.prerodbalab.org/test/index.php[/code][code]http://www.prerodbalab.org/test/add.php[/code] Quote Link to comment Share on other sites More sharing options...
balkan7 Posted October 27, 2006 Author Share Posted October 27, 2006 can someone help me ? 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.