Jump to content

webweever

Members
  • Posts

    71
  • Joined

  • Last visited

    Never

Everything posted by webweever

  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>
  16. Good catches, it's always great to have another set of eyes. I fixed the table name and the $password and still get the same error. mysql_num_rows(): supplied argument is not a valid MySQL result resource in myaccount.php on line 175 Current username and password do no match. Line 175 is: if(mysql_num_rows($result)){ <?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 password FROM members WHERE username='$username' and password = '".md5($password)."'"); if(mysql_num_rows($result)){ if($newpassword==$confirmpassword){ $sql=mysql_query("UPDATE members SET password='$newpassword' where username='$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."; } } ?> That check_input function for my form looks like this: function check_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } Could it be the function that's causing the problem and which is more secure; escape strings or the function I'm using?
  17. I'm trying to write a script that changes my user passwords. I store the passwords in the DB as a md5 hash. My code is below, I keep getting error that the original username and password do not match. I require that the original credentials match so I can verify that I'm changing the password for the correct user. I suspect my problem is here but I'm not sure: $result = mysql_query("SELECT password FROM $tbl_name WHERE username='$username' and password = '".md5($pass)."'"); <?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 password FROM $tbl_name WHERE username='$username' and password = '".md5($pass)."'"); if(mysql_num_rows($result)){ if($newpassword==$confirmpassword){ $sql=mysql_query("UPDATE $tbl_name SET password='$newpassword' where username='$username'"); if($sql) { echo "Password Changed"; } else { // In case when problem while updating your new password echo "Error changing password, please email webmaster@mydomain.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"> <h1></h1> <h2>More text goes here.</h2> </div> <div class="container"> <!-- All protected data goes in here --> <?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>'; } ?> <!-- End: All protected data goes in here --> </div> <div class="container tutorial-info"> Footer goes here. </div> </div> </div> Any ideas?
  18. I'm trying to do a couple of things using the dropdown list below. I have a table with id, rank, and amount. 1. I need to echo the amount that corresponds to the rank selected from the dropdown list. 2. I also need to put the amount value in a variable so I can do some math with it later on. I've got the dropdown pulling the rank values from the db just not sure how to make it do the rest I'm trying to do. Any help would be greatly appreciated <?php db($host,$db_name,$user,$pass); function db($host,$db_name,$user,$pass) { global $link; $link=mysql_connect ("$host","$user","$pass"); if(!$link){die("Could not connect to MySQL");} mysql_select_db("$db_name",$link) or die ("could not open db".mysql_error()); } $sql="SELECT * FROM dlaw"; $result=mysql_query($sql); $options=""; while ($row=mysql_fetch_array($result)) { $rank=$row["rank"]; $options.="<OPTION VALUE=\"$rank\">".$rank.'</option>'; } ?> <SELECT NAME=rank><OPTION VALUE=0>Select Rank<?=$options?></SELECT>
  19. My bad, looks like nettuts had a link to the one they use. Didnt see that earlier. http://alexgorbatchev.com/wiki/SyntaxHighlighter
  20. I'm looking for an editor that will allow me to add PHP code to a post similar to what is done here. http://net.tutsplus.com/tutorials/php/supercharge-your-css-with-php-under-the-hood/ Anyone have any ideas?
  21. I'm trying to sort my results based on the value of $average_vote, is this possible? I haven’t been able to find any type of example in the forum or via Professor Google. <?php include("includes/db.php"); $sql = "SELECT * FROM ratings JOIN markers ON markers.marker_id = ratings.id LIMIT 5 "; $result = mysql_query($sql) or trigger_error('Select SQL failed.', E_USER_ERROR); $num_rows = mysql_num_rows($result); if ($num_rows < 1) { echo '<span class="text">Error</span>'; }else { while ($row = mysql_fetch_assoc($result)) { $total_votes = $row['total_votes']; $total_value = $row['total_value']; $average_vote = $total_value / $total_votes; echo '<span class="text"><b>'.$row['name'].'</b><br/>Fan Rating: '.$average_vote.'</span><br/><br/>'; } } ?>
  22. Ok, I rehacked this thing out. It works, am I leaving anything out? edit.php <link rel="stylesheet" type="text/css" href="../css/style.css" /> <?php include_once("../includes/db.php"); // Catch the passed in Marker ID $marker_id = ($_GET['marker_id']); if (!isset($_GET['marker_id'])) { die("No marker id found"); } else { //Code to pull the marker from the DB //display the marker to be edited $result = mysql_query("SELECT * FROM markers WHERE marker_id = '$marker_id'"); //run the while loop that grabs the marker based on the marker_id while($row=mysql_fetch_array($result)) { //grab all the info for the marker $marker_id=$row["marker_id"];//Marker_id from the DB $name=$row["name"];//Name from the DB $street=$row["street"];//Street from the DB $city=$row["city"];//City from the DB $state=$row["state"];//State from the DB $zip=$row["zip"];//Zip from the DB $url=$row["url"];//Url from the DB $lat=$row["lat"];//Lat from the DB $lng=$row["lng"];//Lng from the DB $type=$row["type"];//Type from the DB $length=$row["length"];//Length from the DB $marker_cat=$row["marker_cat"];//Current Category from the DB } ?> <!-- End Code to pull marker values from the DB --> <!-- Create the form populated with the values from the DB --> <form action="update.php" method="post"> <span class="text"><b>Marker ID:<br> <INPUT TYPE="TEXT" NAME="marker_id" VALUE="<?php echo $marker_id; ?>" SIZE=50><br> Name:<br> <INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $name ?>" SIZE=50><br> Street:<br> <INPUT TYPE="TEXT" NAME="street" VALUE="<?php echo $street?>" SIZE=50><br> City:<br> <INPUT TYPE="TEXT" NAME="city" VALUE="<?php echo $city?>" SIZE=50><br> State:<br> <INPUT TYPE="TEXT" NAME="state" VALUE="<?php echo $state?>" SIZE=50><br> Zip:<br> <INPUT TYPE="TEXT" NAME="zip" VALUE="<?php echo $zip?>" SIZE=50><br> URL:<br> <INPUT TYPE="TEXT" NAME="url" VALUE="<?php echo $url?>" SIZE=50><br> Latitude:<br> <INPUT TYPE="TEXT" NAME="lat" VALUE="<?php echo $lat?>" SIZE=50><br> Longitude:<br> <INPUT TYPE="TEXT" NAME="lng" VALUE="<?php echo $lng?>" SIZE=50><br> Type:<br> <INPUT TYPE="TEXT" NAME="type" VALUE="<?php echo $type?>" SIZE=50><br> Length:<br> <INPUT TYPE="TEXT" NAME="length" VALUE="<?php echo $length?>" SIZE=50><br> Category:<br> <INPUT TYPE="TEXT" NAME="marker_cat" VALUE="<?php echo $marker_cat?>" SIZE=50><br> Created Date:</b></span><br> <INPUT TYPE="TEXT" NAME="created_date" VALUE="<?php echo date ("Y-m-j");?>" SIZE=50><br> <input type="submit" name="submitmarker" value="Submit"><input type="reset" name="resetForm" value="Clear Form"> </form> <?php } ?> <a href="admin.php">Back to list</a> update.php <link rel="stylesheet" type="text/css" href="../css/style.css" /> <span class="text"> <?php require("../includes/db.php"); $marker_id = mysql_real_escape_string($_POST["marker_id"]); $name = mysql_real_escape_string($_POST["name"]); $street = mysql_real_escape_string($_POST["street"]); $city = mysql_real_escape_string($_POST["city"]); $state = mysql_real_escape_string($_POST["state"]); $zip = mysql_real_escape_string($_POST["zip"]); $url = mysql_real_escape_string($_POST["url"]); $lat = mysql_real_escape_string($_POST["lat"]); $lng = mysql_real_escape_string($_POST["lng"]); $type = mysql_real_escape_string($_POST["type"]); $length = mysql_real_escape_string($_POST["length"]); $marker_cat = mysql_real_escape_string($_POST["marker_cat"]); $created_date = mysql_real_escape_string($_POST["created_date"]); $sql = "UPDATE markers SET marker_id = '$marker_id' , name = '$name' , street = '$street' , city = '$city', state = '$state', zip = '$zip', url = '$url', lat = '$lat', lng = '$lng', marker_cat = '$marker_cat', type = '$type', length = '$length', created_date = '$created_date' WHERE marker_id = '$marker_id'"; mysql_query($sql) or die ("Error: ".mysql_error()); echo "Thank you! Information updated."; ?> <br><br> <?php echo $marker_id. '<br>'; echo $name.'<br>'; echo $city.'<br>'; echo $state.'<br>'; echo $zip.'<br>'; echo $url.'<br>'; echo $lat.'<br>'; echo $lng.'<br>'; echo $marker_cat.'<br>'; echo $type.'<br>'; echo $length.'<br>'; echo $created_date; ?> <br> <a href="admin.php">Back to list</a> </span>
  23. Easiest way I've found to do it is use Yahoo weather RSS feeds and run them through Simplepie. Or you could put that link in an Iframe on your site like this: <iframe name="weather" src="http://www.assamtribune.com/weather.html"></iframe>
  24. I've been looking at my code for hours and can't find what the problem is. The form appears to work correctly but it does not update the data in the DB. I don't get any errors. <html> <head> <title>Edit Marker</title> <?php include_once("../includes/db.php"); $marker_id = $_REQUEST['marker_id']; $sql = "SELECT * FROM markers WHERE marker_id = '$marker_id'"; $result = MYSQL_QUERY($sql); $numberOfRows = MYSQL_NUMROWS($result); if ($numberOfRows==0) { ?> Sorry. No records found !! </head> <body> <?php } else if ($numberOfRows>0) { $i=0; $marker_id = MYSQL_RESULT($result,$i,"marker_id"); $name = MYSQL_RESULT($result,$i,"name"); $street = MYSQL_RESULT($result,$i,"street"); $city = MYSQL_RESULT($result,$i,"city"); $state = MYSQL_RESULT($result,$i,"state"); $zip = MYSQL_RESULT($result,$i,"zip"); $url = MYSQL_RESULT($result,$i,"url"); $lat = MYSQL_RESULT($result,$i,"lat"); $lng = MYSQL_RESULT($result,$i,"lng"); $marker_cat = MYSQL_RESULT($result,$i,"marker_cat"); $type = MYSQL_RESULT($result,$i,"type"); $length = MYSQL_RESULT($result,$i,"length"); } ?> <center><h1> Edit Marker</h1></center> <form name="UpdateMarker" method="POST" action="<?php echo $_SERVER['PHP_SELF']?>"> <table width="700" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="308"><div align="right"><font style="font-size: .75em; font-family: verdana;" type="text"><b> </b></font></div></td> <td width="390"><input type="hidden" name="marker_id" value="<?php echo $marker_id; ?>"></td> </tr> <tr> <td width="308"><div align="right"><font style="font-size: .75em; font-family: verdana;" type="text"><b>Name: </b></font></div></td> <td width="390"><input name="name" id="name" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $name; ?>"></td> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>Street: </b></font></div></td> <td><input name="street" id="street" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $street; ?>"></td> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>City: </b></font></div></td> <td><input name="city" id="city" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $city; ?>"></td> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>State: </b></font></div></td> <td><input name="state" id="state" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $state; ?>"></td> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>Zip: </b></font></div></td> <td><input name="zip" id="zip" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $zip; ?>"></td> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>URL: </b></font></div></td> <td><input name="url" id="url" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $url; ?>"></td> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>Latitude: </b></font></div></td> <td><input name="lat" id="lat" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $lat; ?>"></td> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>Longitude: </b></font></div></td> <td><input name="lng" id="lng" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $lng; ?>"></td> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>Category: </b></font></div></td> <td><input name="marker_cat" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $marker_cat; ?>"> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>Type: </b></font></div></td> <td><input name="type" id="type" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $type; ?>"> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>Length: </b></font></div></td> <td><input name="length" id="length" size="35" style="font-size: .75em; font-family: verdana;" type="text" value="<?php echo $length; ?>"> </tr> <tr> <td><div align="right"><font style="font-size: .75em; font-family: verdana;"><b>Edit Category:</b></font></div></td> <td> <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("maps", $con) or die('Failed to select database'); $sql = "SELECT * FROM category"; $result = mysql_query($sql); $options = ""; while ($row = mysql_fetch_array($result)) { $catname = $row['cat_name']; //$cat_id=$row["cat_id"]; $options .= "<OPTION VALUE=\"$catname\">$catname</option>"; } if (isset($_POST['list']) && is_array($_POST['list'])) { $items = implode(", ", $_POST['list']); $sql="UPDATE markers SET marker_id = '$marker_id' , name = '$name' , street = '$street' , city = '$city', state = '$state', zip = '$zip', url = '$url', lat = '$lat', lng = '$lng', marker_cat = '$items', type = '$type', length = '$length' WHERE marker_id = '$marker_id'"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } } ?> <SELECT NAME="list[]" size="8" multiple style="width:150px;" ><?php echo $options?></SELECT> </td> </tr> <tr> <td><br/><br/></td> <td> <div align="left"> <input type="submit" name="submitmarker" value="Submit"> <input type="reset" name="resetForm" value="Clear Form"> </div> </td> </tr> </table> <center><a href="admin.php">Back to Admin Page</a></center> </body> </html> <?php } mysql_close($con); ?>
×
×
  • 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.