Jump to content

webweever

Members
  • Posts

    71
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

webweever's Achievements

Member

Member (2/5)

0

Reputation

  1. Does this look more appropriate? CREATE TABLE `item` ( `id` int(11) NOT NULL auto_increment, `date` date NOT NULL, `store_id` int(11) NOT NULL, `item` varchar(30) collate latin1_general_ci NOT NULL, `itemprice` decimal(10,2) unsigned NOT NULL, `itemnumber` tinyint(20) NOT NULL, `itemtotalprice` decimal(10,2) NOT NULL, `user_id` int(11) NOT NULL, `item_id` int(11) NOT NULL, PRIMARY KEY (`id`) Foreign Key (item_id) references members(id)); ) ENGINE=MyISAM AUTO_INCREMENT=91 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=91 ; CREATE TABLE `members` ( `id` int(11) NOT NULL auto_increment, `usr` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL, `pass` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL, `email` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL, `regip` varchar(15) character set utf8 collate utf8_unicode_ci NOT NULL, `dt` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `usr` (`usr`), UNIQUE KEY `email` (`email`) ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; CREATE TABLE `lists` ( `id` int(11) NOT NULL auto_increment, `name` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL, `dt` datetime NOT NULL, `user_id` int(11) NOT NULL, PRIMARY KEY (`id`), Foreign Key (user_id) references members(id)); ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; CREATE TABLE `store` ( `id` int(11) NOT NULL auto_increment, `store_name` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`), ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
  2. The basic gist of it is a member can create multiple lists that can contain multiple items from multiple stores.
  3. Does this look like good DB structure? CREATE TABLE `item` ( `item_id` int(11) NOT NULL auto_increment, `user_id` int(20) NOT NULL, `date` date NOT NULL, `store` varchar(30) collate latin1_general_ci NOT NULL, `item` varchar(30) collate latin1_general_ci NOT NULL, `itemprice` decimal(10,2) unsigned NOT NULL, `itemnumber` tinyint(20) NOT NULL, `itemtotalprice` decimal(10,2) NOT NULL, `item_id` int(11) NOT NULL, PRIMARY KEY (`item_id`) Foreign Key (user_id) references members(id)); ) ENGINE=MyISAM AUTO_INCREMENT=91 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=91 ; CREATE TABLE `members` ( `id` int(11) NOT NULL auto_increment, `usr` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL, `pass` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL, `email` varchar(255) character set utf8 collate utf8_unicode_ci NOT NULL, `regip` varchar(15) character set utf8 collate utf8_unicode_ci NOT NULL, `dt` datetime NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `usr` (`usr`), UNIQUE KEY `email` (`email`) ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; CREATE TABLE `lists` ( `list_id` int(11) NOT NULL auto_increment, `name` varchar(32) character set utf8 collate utf8_unicode_ci NOT NULL, `dt` datetime NOT NULL, `user_id` int(11) NOT NULL, PRIMARY KEY (`id`), Foreign Key (user_id) references members(id)); ) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
  4. I did try the original example. It was still inserting empty rows, it would only eval the first row correctly. If the first row was not set and the second was it would not insert either. What I used I look for empties and if it finds one do nothing and move to the next row, else insert into the DB. It seems to work.
  5. This is what I did to get it to work. if(empty($store[$i])){ } else { $values[$i] = "( '{$id[$i]}', '{$store[$i]}', '{$item[$i]}', '{$itemprice[$i]}', '{$itemnumber[$i]}', '{$couponvalue[$i]}', '{$couponsused[$i]}', '{$doubledcoupon[$i]}')"; } If the store field is not set then drop that row, if it is move on to the array. Thanks for all the help.
  6. This is my DB design. CREATE TABLE `item` ( `item_id` int(11) NOT NULL auto_increment, `user_id` int(20) NOT NULL, `store` varchar(30) collate latin1_general_ci NOT NULL, `item` varchar(30) collate latin1_general_ci NOT NULL, `itemprice` decimal(10,2) unsigned NOT NULL, `itemnumber` tinyint(20) NOT NULL, `couponvalue` decimal(10,2) unsigned NOT NULL, `couponsused` tinyint(20) NOT NULL, `doubledcoupon` tinyint(2) NOT NULL, PRIMARY KEY (`item_id`) ) ENGINE=MyISAM AUTO_INCREMENT=50 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=50 ; I need a way to identify that a user has not entered a store in my multi row html. If the user did not select a store the content of the other form fields in that particular row or is that even possible? Can I only evaluate the form fields individually? I guess I really need to evaluate them as a set for each row.
  7. Thanks for the reply wildteen. My rows look like this (store, item, itemprice, itemnumber, etc...), I think what I want to do is make the store required and if a value for store is not entered then drop the corresponding (item, itemprice, itemnumber, etc...) associated with that row. The if statement above will just check the individual form fields.
  8. guilygear, Tried both of those. Maybe I'm not articulating what I'm trying to do. I have an HTML form with say 10 rows each with the following user filled form fields store, item, itemprice, itemnumber, couponvalue, couponsused, doubledcoupon. One row of fields is an item and inserted into the DB in the item table. Well, what if a user only has 5 items to enter in the DB? In this case I would need the script to evaluate the 5 rows of data and ignore the last five that have nothing in them. That is the human logic behind what I need to do. Both the scripts above will still insert empty fields in the DB which obviously is a bad thing.
  9. I have the form / script below that works to add multiple rows of data with one query. One thing I did not think about is what if the first set of form fields are filled and the second is not. Currently the script insert an empty row. I'm sure how I would go about checking for an empty row and if there is an empty row ignore it and do not put it in the DB. Can someone point me in the right direction? <?php // Begin the script for this page if (isset($_POST['submit'])) { //Assign each array to a variable $id = $_POST['id']; $store = $_POST['store']; $item = $_POST['item']; $itemprice = $_POST['itemprice']; $itemnumber = $_POST['itemnumber']; $couponvalue = $_POST['couponvalue']; $couponsused = $_POST['couponsused']; $limit = count($id); $values = array(); // initialize an empty array to hold the values for($i=0;$i<$limit;$i++){ $store[$i] = check_input($store[$i]); $item[$i] = check_input($item[$i]); $itemprice[$i] = check_input($itemprice[$i]); $itemnumber[$i] = check_input($itemnumber[$i]); $couponvalue[$i] = check_input($couponvalue[$i]); $couponsused[$i] = check_input($couponsused[$i]); $values[$i] = "( '{$id[$i]}', '{$store[$i]}', '{$item[$i]}', '{$itemprice[$i]}', '{$itemnumber[$i]}', '{$couponvalue[$i]}', '{$couponsused[$i]}')"; // build the array of values for the query string } $query = "INSERT INTO `item` (user_id, store, item, itemprice, itemnumber, couponvalue, couponsused) VALUES " . implode( ', ', $values ); // Form the query string and add the implod()ed values if (!mysql_query($query,$link)){ die('Error: ' . mysql_error()); } else { $added = "Your items have been added."; } } ?> <div class="pageContent"> <div id="main"> <div class="container"> <?php echo $added; if($_SESSION['id']){ echo '<form action="" method="post">'; echo '<table cellpadding= "4">'; echo '<tr>'; echo '<input type="hidden" name="id[]" id="id[]" value='.$_SESSION['id'].' />'; echo '<td><DIV CLASS="p2"><b>Store</b></div>'; echo '<input type="text" name="store[]" id="store[]" size="15" maxlength="255"/></td>'; echo '<td><DIV CLASS="p2"><b>Item</b></div>'; echo '<input type="text" name="item[]" id="item[]" size="15" maxlength="255"/></td>'; echo '<td><DIV CLASS="p2"><b>Item Price</b></div>'; echo '<input type="text" name="itemprice[]" id="itemprice[]" size="5" maxlength="255"/></td>'; echo '<td><DIV CLASS="p2"><b>Item #</b></div>'; echo '<select name="itemnumber[]" id="itemnumber[]"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select></td>'; echo '<td><DIV CLASS="p2"><b>Coupon Value</b></div>'; echo '<input type="text" name="couponvalue[]" id="couponvalue[]" size="10" maxlength="255"/></td>'; echo '<td><DIV CLASS="p2"><b># Coupons</b></div>'; echo '<select style="width: 60px;" name="couponsused[]" id="couponsused[]"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select></td>'; echo '<td><DIV CLASS="p2"><b>Doubled Coupon</b></div>'; echo '<select style="width: 75px;" name="doubledcoupon[]" id="doubledcoupon[]"><option value="1">Yes</option><option value="0">No</option></td>'; echo '</tr>'; echo '<tr>'; echo '<input type="hidden" name="id[]" id="id[]" value="'.$_SESSION['id'].'" />'; echo '<td><input type="text" name="store[]" id="store[]" size="15" maxlength="255"/></td>'; echo '<td><input type="text" name="item[]" id="item[]" size="15" maxlength="255"/></td>'; echo '<td><input type="text" name="itemprice[]" id="itemprice[]" size="5" maxlength="255"/></td>'; echo '<td><select name="itemnumber[]" id="itemnumber[]"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select></td>'; echo '<td><input type="text" name="couponvalue[]" id="couponvalue[]" size="10" maxlength="255"/></td>'; echo '<td><select style="width: 60px;" name="couponsused[]" id="couponsused[]"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option></select></td>'; echo '<td><select style="width: 75px;" name="doubledcoupon[]" id="doubledcoupon[]"><option value="1">Yes</option><option value="0">No</option></td>'; echo'</tr>'; echo'<tr>'; echo '<input type="submit" name="submit" value="Submit Item">'; echo'</tr>'; echo '</table>'; echo'</form>'; } else { echo '<h1>Please, <a href="index.php">login</a> and come back later!</h1>'; } ?> </div> </div> </div>
  10. Somehow I glossed over those two replies, guess I should have read a little more carefully. PaulRyan's changes worked beautifully although I'm not sure I fully understand why mine only inserted the last item. Need to do a little reading on loops. Thanks again guys
  11. Anyone have any ideas how I can fix this?
  12. I have started the session, it's part of another piece of the page that I didnt include in the post.
  13. Fixed the id piece of it but I move the query inside the loop and it still only inserts the last row. With this arent I counting the instances of the id[] from my form> $limit = count($id); <?php // Begin the script for this page if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form } else { //Assign each array to a variable $id = $_POST['id']; $store = $_POST['store']; $item = $_POST['item']; $itemprice = $_POST['itemprice']; $itemnumber = $_POST['itemnumber']; $couponvalue = $_POST['couponvalue']; $limit = count($id); for($i=0;$i<$limit;$i++){ $id[$i] = $id[$i]; $store[$i] = check_input($store[$i]); $item[$i] = check_input($item[$i]); $itemprice[$i] = check_input($itemprice[$i]); $itemnumber[$i] = check_input($itemnumber[$i]); $couponvalue[$i] = check_input($couponvalue[$i]); $query = "INSERT INTO `item` (user_id, store, item, itemprice, itemnumber, couponvalue) VALUES ('".$id[$i]."','".$store[$i]."', '".$item[$i]."', '".$itemprice[$i]."', '".$itemnumber[$i]."', '".$couponvalue[$i]."')"; } if (!mysql_query($query,$link)){ die('Error: ' . mysql_error()); } else { echo "$row record added"; } } ?>
  14. The code below kind of works, I don't get any errors. It has 2 problems; it only inserts the second row of data I get nothing for the first row. It also does not insert the 4id correctly I just get 1 instead of the actually user id number. I'd appreciate some help, been trying to hack this out for a couple hours. <?php // Begin the script for this page $id = $_SESSION['id']; if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form } else { //Assign each array to a variable $id = $_SESSION['id']; $store = $_POST['store']; $item = $_POST['item']; $itemprice = $_POST['itemprice']; $itemnumber = $_POST['itemnumber']; $couponvalue = $_POST['couponvalue']; $limit = count($id); for($i=0;$i<$limit;$i++){ $id[$i] = $id[$i]; $store[$i] = check_input($store[$i]); $item[$i] = check_input($item[$i]); $itemprice[$i] = check_input($itemprice[$i]); $itemnumber[$i] = check_input($itemnumber[$i]); $couponvalue[$i] = check_input($couponvalue[$i]); } $query = "INSERT INTO `item` (user_id, store, item, itemprice, itemnumber, couponvalue) VALUES ('".$id[$i]."','".$store[$i]."', '".$item[$i]."', '".$itemprice[$i]."', '".$itemnumber[$i]."', '".$couponvalue[$i]."')"; if (!mysql_query($query,$link)){ die('Error: ' . mysql_error()); } else { echo "$row record added"; } } ?> <div class="pageContent"> <div id="main"> <div class="container"> <form action="" method="post"> <table> <tr> <input type="text" name="id[]" id="id[]" value="<?php echo $_SESSION['id'];?>" /> <td><DIV CLASS="p2"><center><b>Store</b></center></div> <input type="text" name="store[]" id="store[]" size="15" maxlength="255"/></td> <td><DIV CLASS="p2"><center><b>Item</b></center></div> <input type="text" name="item[]" id="item[]" size="15" maxlength="255"/></td> <td><DIV CLASS="p2"><center><b>Item Price</b></center></div> <input type="text" name="itemprice[]" id="itemprice[]" size="15" maxlength="255"/></td> <td><DIV CLASS="p2"><center><b>Item Number</b></center></div> <input type="text" name="itemnumber[]" id="itemnumber[]" size="15" maxlength="255"/></td> <td><DIV CLASS="p2"><center><b>Coupon Value</b></center></div> <input type="text" name="couponvalue[]" id="couponvalue[]" size="15" maxlength="255"/></td> </tr> <tr> <input type="text" name="id[]" id="id[]" value="<?php echo $_SESSION['id'];?>" /> <td><input type="text" name="store[]" id="store[]" size="15" maxlength="255"/></td> <td><input type="text" name="item[]" id="item[]" size="15" maxlength="255"/></td> <td><input type="text" name="itemprice[]" id="itemprice[]" size="15" maxlength="255"/></td> <td><input type="text" name="itemnumber[]" id="itemnumber[]" size="15" maxlength="255"/></td> <td><input type="text" name="couponvalue[]" id="couponvalue[]" size="15" maxlength="255"/></td> </tr> </table> <input type="submit" name="submit" value="Submit Item"> </form> </div> </div> </div>
  15. I'm an Idiot... i had the column names wrong. Also had to md5 the new password. Thanks everyone for the help Aside from this I am interested in opinions on the function I'm using to check the form inputs which is more secure or is there a difference? Below is what works if anyone is interested. <?php $username = check_input($_POST['username']); $password = check_input($_POST['password']); $newpassword = check_input($_POST['newpassword']); $confirmpassword = check_input($_POST['confirmpassword']); if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form } else { $result = mysql_query("SELECT pass FROM members WHERE usr='$username' and pass = '".md5($password)."'")or die("Query failed: " . mysql_error()); if(mysql_num_rows($result)){ if($newpassword==$confirmpassword){ $sql=mysql_query("UPDATE members SET pass='".md5($newpassword)."' where usr='$username'"); if($sql) { echo "Password Changed"; } else { // In case when problem while updating your new password echo "Error changing password, please email webmaster@signalwarrant.com"; } } else { // In case when new-password and retype-password do not match echo "New and confirmed password do not match please try again."; } } else { // In case of you have not correct User name and password echo "Current username and password do no match."; } } ?> <div class="pageContent"> <div id="main"> <div class="container"> </div> <div class="container"> <?php if($_SESSION['id']){ echo '<form action="" method="post">'; echo '<h2>Username: </h2><input type="text" name="username" size="50" maxlength="255"><br/>'; echo '<h2>Password: </h2><input type="text" name="password" size="50" maxlength="255"><br/>'; echo '<h2>New Password: </h2><input type="text" name="newpassword" size="50" maxlength="255"><br/>'; echo '<h2>Confirm Password: </h2><input type="text" name="confirmpassword" size="50" maxlength="255"><br/>'; echo '<input type="submit" name="submit" value="Change Password">'; echo '</form>'; } else { echo '<h1>Please, <a href="index.php">login</a> and come back later!</h1>'; } ?> </div>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.