Jump to content

scmeeker

Members
  • Posts

    153
  • Joined

  • Last visited

    Never

Everything posted by scmeeker

  1. When you say "echo out $sql", do you mean to make the $transaction_id echo (echo $transaction_id)before the insert table? If so, I did and on the next page it printed a different random number. Otherwise, I'm not sure what you meant.
  2. It's inserting everything else into the table perfectly and outputting all the other information fine. Like I said, I tested it with this line of code after the first two ($sql) &($sql2): header("location:finalize.php?username=$username&id=$item_id&transaction_id=$transaction_id"); When doing this, on the next page it generated a new $transaction_id into the URL just fine. It's just not inserting the new random number into the table....it keeps showing up as the same number (which I have no idea where it is getting that number from) even after deleting its presence from my database and resetting my server.
  3. I also tried going back to change the subject line in my original post but couldn't...sorry for the confusion.
  4. When I run it, it does produce a new number when I tested it in the URL but it's not inserting this new random number into the "buyer" table. Here is that section of the code from the previous code I posted: $sql="INSERT INTO buyer (username, email, first_name, last_name, street, street_2, city, state, zip_code, country, transaction_id, date) VALUES ('$username', '$item_email', '$item_first_name', '$item_last_name', '$item_street', '$item_street2', '$item_city', '$item_state', '$item_zip_code', '$item_country', '$transaction_id', CURDATE())";
  5. I've used this before and it worked fine but the mt_rand is not working properly. It keeps producing the same number. I've tested it on with the $_GET to the next page and it produces a unique code but it doesn't want to insert that number into the table, just the other same, repetitive number. $transaction_id = mt_rand() . mt_rand(); $item_email = mysql_real_escape_string($_POST[email]); $item_first_name = mysql_real_escape_string($_POST[first_name]); $item_last_name = mysql_real_escape_string($_POST[last_name]); $item_street = mysql_real_escape_string($_POST[street]); $item_street2 = mysql_real_escape_string($_POST[street_2]); $item_city = mysql_real_escape_string($_POST[city]); $item_state = mysql_real_escape_string($_POST[state]); $item_zip_code = mysql_real_escape_string($_POST[zip_code]); $item_country = mysql_real_escape_string($_POST[country]); $username = $_SESSION['username']; $item_id = $_GET['id']; $item_title = mysql_real_escape_string($_POST[title]); $item_price = mysql_real_escape_string($_POST[price]); $item_shipping_cost = mysql_real_escape_string($_POST[shipping_cost]); $item_in_shipping = mysql_real_escape_string($_POST[in_shipping]); $okay = TRUE; if ($item_country == 'United States'){ $shipping = "$item_shipping_cost"; } else { $shipping = "$item_in_shipping - <span class=\"submissionfont\">International Rate</span>"; } $sql="INSERT INTO buyer (username, email, first_name, last_name, street, street_2, city, state, zip_code, country, transaction_id, date) VALUES ('$username', '$item_email', '$item_first_name', '$item_last_name', '$item_street', '$item_street2', '$item_city', '$item_state', '$item_zip_code', '$item_country', '$transaction_id', CURDATE())"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } $sql2="UPDATE product SET transaction_id='$transaction_id', sold='1', sold_date=CURDATE() WHERE id = '$item_id'"; if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); }
  6. Here is 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 'group FROM artist' at line 1
  7. I can't figure out why I keep getting a syntax error with this part of the code? Am I missing something? Thanks! $get_group = mysql_query("SELECT group FROM artist WHERE username = '".$_GET["username"]."'") or die(mysql_error());
  8. I had to also make a change in the table, then your change worked. Thanks!
  9. I tried removing the quotes but it is still giving me a value of "0" in my database instead of "NULL".
  10. I'm trying to force a NULL value into the database with a hidden value and I can't seem to get it to work. Any suggestions? <input type="hidden" name="inactive" value=""/> I also tried here too: $sql="UPDATE product SET inactive='NULL' WHERE id = '$item_id'";
  11. I'm trying to create a dependent drop down list. If a user picks something from the initial category list, I want the subcategory list to change to populate with its relevant category ID. Kind of like picking a state from the first drop down then the next would populate with all the state's cities. When I print this, it lists individual drop down lists rather than one. Is there another way I should be looking at this? Thanks for your suggestions. //Set the selected category $selected_cat = (isset($_GET["cat_id"])) ? $_GET["cat_id"] : false; //show categories first $result = mysql_query("SELECT cat_id, cat_title FROM category ORDER BY cat_id") or die(mysql_error()); if (mysql_num_rows($result) < 1) { $categoryList = "<p><em>Sorry, no categories to browse.</em></p>"; } else { //Display the categories while ($cats = mysql_fetch_array($result)) { $cat_id = $cats['cat_id']; $cat_title = $cats['cat_title']; $categoryList .= "<select name=\"cat_id\" class=\"blackfont\"> <option value=$cat_id>$cat_title</option></select>"; if ($cats['cat_id']==$selected_cat) { //get items $get_items_sql = mysql_query("SELECT id, cat_id, sub_title FROM sub_category WHERE cat_id = '{$selected_cat}'") or die(mysql_error()); if (mysql_num_rows($get_items_sql) < 1) { $content = "<p><em>Sorry, no items in this category.</em></p>\n"; } else { while ($items = mysql_fetch_array($get_items_sql)) { $cat_id = $cats['cat_id']; $sub_title = $cats['sub_title']; $content .= "<select name=\"sub_id\" class=\"blackfont\"> <option value=$cat_id>$sub_title</option></select>"; }
  12. Is it possible to echo a unique item from the database? For example, if I had this code: $get_item_sql = mysql_query("SELECT id, link_1, link_2, price FROM picks WHERE MONTH(date) = MONTH(CURDATE())") or die(mysql_error()); if (mysql_num_rows($get_item_sql) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { //valid item, get info while ($item_info = mysql_fetch_array($get_item_sql)) { $pick_id = $item_info['id']; $pick_link_1 = $item_info['link_1']; $pick_link_2 = $item_info['link_2']; $pick_price = $item_info['price']; But wanted to echo a unique ID. Say I'm referring to item ID #2 in the table. Can I refer to it in the echo statement? But I don't want it to show up in the browser, just the information that goes with it. I want to print different items in different places throughout the webpage and not in a list.
  13. Got this solved thanks to Crayon Violet's tutorial on PHP Freaks! Thanks for writing great script! http://www.phpfreaks.com/tutorial/basic-pagination
  14. I've got this Pagination script almost working but perhaps with another set of experienced eyes, I can get my problem solved. It works BUT the one problem I'm having is it only displays the "first page number" and then the "ALL" instead of showing all the page numbers for the maximum rows defined per page. Here is the code and I appreciate any suggestions and help (I've purposely left out the d-base connection): require_once 'paginator.class.php'; mysql_connect("", "", "", "") or die(mysql_error()); mysql_select_db("table") or die(mysql_error()); $paginatestuff = mysql_query("SELECT COUNT(*) FROM table") or die(mysql_error()); $pages = new Paginator; $pages->items_total = $paginatestuff; $pages->mid_range = 7; $pages->paginate(); //Set the selected category $selected_cat = (isset($_GET["cat_id"])) ? $_GET["cat_id"] : false; //show categories first $result = mysql_query("SELECT cat_id, cat_title FROM category ORDER BY cat_id") or die(mysql_error()); if (mysql_num_rows($result) < 1) { $categoryList = "<p><em>Sorry, no categories to browse.</em></p>"; } else { //Display the categories while ($cats = mysql_fetch_array($result)) { $categoryList .= "<a href=\"listtest5.php?cat_id={$cats['cat_id']}\">{$cats['cat_title']} <br /></a>\n"; if ($cats['cat_id']==$selected_cat); } //get items $get_items_sql = mysql_query("SELECT id, name, website, city, state, country, date FROM table WHERE MONTH(date) = MONTH(CURDATE()) ORDER BY date $pages->limit") or die(mysql_error()); if (mysql_num_rows($get_items_sql) < 1) { $content = "<p><em>Sorry, no items in this category.</em></p>\n"; } else { $content .= "<ul>\n"; while ($items = mysql_fetch_array($get_items_sql)) { $item_url = $items['website']; $item_title = stripslashes($items['name']); $item_city = $items['city']; $item_state = $items['state']; $item_country = $items['country']; $item_id = $items['id']; $content .= ""; $content .="<table width=\"500\" height=\"50\" border=\"0\"><tr><td width=\"200\"><a href=$item_url target=\"_blank\">$item_title</a></td></tr><tr> <td width=\"200\" class=blackfont>Location: {$item_city}, {$item_state}</td></tr><tr><td class=blackfont>Country: {$item_country}</td></tr><br /> </table>"; $content .= "\n"; } $content .= "</ul>\n"; } } Then here is the pagination class reference file if you need that too for reference: <?php class Paginator{ var $items_per_page; var $items_total; var $current_page; var $num_pages; var $mid_range; var $low; var $high; var $limit; var $return; var $default_ipp = 10; var $querystring; function Paginator() { $this->current_page = 1; $this->mid_range = 7; $this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp; } function paginate() { if($_GET['ipp'] == 'All') { $this->num_pages = ceil($this->items_total/$this->default_ipp); $this->items_per_page = $this->default_ipp; } else { if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp; $this->num_pages = ceil($this->items_total/$this->items_per_page); } $this->current_page = (int) $_GET['page']; // must be numeric > 0 if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1; if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages; $prev_page = $this->current_page-1; $next_page = $this->current_page+1; if($_GET) { $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg; } } if($_POST) { foreach($_POST as $key=>$val) { if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val"; } } if($this->num_pages > 10) { $this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[php_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">« Previous</a> ":"<span class=\"inactive\" href=\"#\">« Previous</span> "; $this->start_range = $this->current_page - floor($this->mid_range/2); $this->end_range = $this->current_page + floor($this->mid_range/2); if($this->start_range <= 0) { $this->end_range += abs($this->start_range)+1; $this->start_range = 1; } if($this->end_range > $this->num_pages) { $this->start_range -= $this->end_range-$this->num_pages; $this->end_range = $this->num_pages; } $this->range = range($this->start_range,$this->end_range); for($i=1;$i<=$this->num_pages;$i++) { if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... "; // loop through all pages. if first, last, or in range, display if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range)) { $this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[php_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> "; } if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... "; } $this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All')) ? "<a class=\"paginate\" href=\"$_SERVER[php_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next »</a>\n":"<span class=\"inactive\" href=\"#\">» Next</span>\n"; $this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[php_SELF]?page=1&ipp=All$this->querystring\">All</a> \n"; } else { for($i=1;$i<=$this->num_pages;$i++) { $this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[php_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> "; } $this->return .= "<a class=\"paginate\" href=\"$_SERVER[php_SELF]?page=1&ipp=All$this->querystring\">All</a> \n"; } $this->low = ($this->current_page-1) * $this->items_per_page; $this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1; $this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page"; } function display_items_per_page() { $items = ''; $ipp_array = array(10,25,50,100,'All'); foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n"; return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[php_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n"; } function display_jump_menu() { for($i=1;$i<=$this->num_pages;$i++) { $option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n"; } return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[php_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n"; } function display_pages() { return $this->return; } } ?>
  15. I would like add subcategories to my main categories. For example: Paintings (would be a main category) oil (sub-category) acrylic (sub-category) watercolor (sub-category) When a user first comes to the webpage, it would list all the main categories. Then, when the user clicks on a main category, the Sub-categories dynamically drop down, pushing down the other main categories (but still being able to view them). I already have a separate sub-category table ready to pull from that match up with the corresponding category. This code, pulls from the category table and lists the main categories along the side and when clicked brings up all matching products according to the category. But now I would like to take it one more step and have the sub-category list drop down under the main category while still bringing up the products under that category. Then a user could choose to sort even further through the products by choosing the sub-category. Hopefully I'm making some sense here. Thanks for your help. //Set the selected category $selected_cat = (isset($_GET["cat_id"])) ? $_GET["cat_id"] : false; //show categories first $result = mysql_query("SELECT cat_id, cat_title FROM category ORDER BY cat_id") or die(mysql_error()); if (mysql_num_rows($result) < 1) { $categoryList = "<p><em>Sorry, no categories to browse.</em></p>"; } else { //Display the categories while ($cats = mysql_fetch_array($result)) { $categoryList .= "<a href=\"listtest5.php?cat_id={$cats['cat_id']}\">{$cats['cat_title']} <br /></a>\n"; if ($cats['cat_id']==$selected_cat) { //get items $get_items_sql = mysql_query("SELECT id, image_upload_box, username, title, price, date FROM product WHERE cat_id = '{$selected_cat}' ORDER BY date $pages->limit") or die(mysql_error());; if (mysql_num_rows($get_items_sql) < 1) { $content = "<p><em>Sorry, no items in this category.</em></p>\n"; } else { $content .= "<ul>\n"; while ($items = mysql_fetch_array($get_items_sql)) { $item_url = "items3.php?id={$items['id']}=username={$items['username']}"; $item_title = stripslashes($items['title']); $item_price = $items['price']; $item_photo = $items['photo']; $item_username = $items['username']; $item_date = $items['date']; $content .= "";
  16. I figured that...after the fact, so I'm going to have to do some research on the differences in the two. If you know of any great online resources, I would appreciate it.
  17. My server doesn't support the mysqli script. I realized that when I uploaded it earlier and it gave me an error for that...not recognizing it. So I changed all the mysqli's to mysql's and the error that I posted before was the result. Sorry for the miscommunication of my posting on that. Here is the code without the "mysqli" included that is still giving me the error. I've purposely left out the db connection info. Thanks for your help. This is the line of code I get the error: $get_cats_res = mysql_query($mysql, $get_cats_sql) or die(mysql_error($mysql)); Here is the rest of the code: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); //connect to database $mysql = mysql_connect("", "", "", ""); //Set the selected category $selected_cat = (isset($_GET["cat_id"])) ? $_GET["cat_id"] : false; //show categories first $get_cats_sql = "SELECT cat_id, cat_title FROM category ORDER BY cat_id"; $get_cats_res = mysql_query($mysql, $get_cats_sql) or die(mysql_error($mysql)); if (mysql_num_rows($get_cats_res) < 1) { $categoryList = "<p><em>Sorry, no categories to browse.</em></p>"; } else { //Display the categories while ($cats = mysql_fetch_array($get_cats_res)) { $categoryList .= "<a href=\"listtest5.php?cat_id={$cats['cat_id']}\">{$cats['cat_title']} <br /></a>\n"; if ($cats['cat_id']==$selected_cat); } //get items $get_items_sql = "SELECT id, title, city, state, country, deadline, brief_description, date FROM table WHERE AND MONTH(date) = MONTH(CURDATE()) ORDER BY date"; $get_items_res = mysql_query($mysql, $get_items_sql) or die(mysql_error($mysql)); if (mysql_num_rows($get_items_res) < 1) { $content = "<p><em>Sorry, no items in this category.</em></p>\n"; } else { $content .= "<ul>\n"; while ($items = mysql_fetch_array($get_items_res)) { $item_url = "detail.php?id={$items['id']}"; $item_title = stripslashes($items['title']); $item_city = $items['city']; $item_state = $items['state']; $item_country = $items['country']; $item_deadline = $items['deadline']; $item_brief_description = $items['brief_description']; $item_id = $items['id']; $content .= ""; $content .="<table width=\"693\" border=\"0\"><tr><td width=\"200\"><a href=$item_url>$item_title</a></td><tr><td class=blackfont width=\"251\">{$item_city}, {$item_state} - {$item_country}</td></tr><tr><td class=blackfont width=\"109\">Deadline: {$item_deadline}</td></tr><tr><td class=\"blackfont\">{$item_brief_description}</td></tr><br /></table>"; $content .= "\n"; } $content .= "</ul>\n"; } } ?>
  18. I took out the db connection details off the posting. In fact, I just ran another test on a different page that worked. It was a form with no initial database call for dynamic information that called on a php page to add a record. It worked perfect. Hmmmmm...this has me stumped.
  19. It's giving me the error at this line of code (sorry I didn't include that before): $get_cats_res = mysqli_query($mysqli, $get_cats_sql) or die(mysqli_error($mysqli));
  20. Here is my code where I'm getting that error, perhaps maybe you might be able to see what I'm not. When I run this on my server here at home, it works perfect but when uploaded live...it give's me the error. I've talked to my Web host but they said it's in my scripting. So I would appreciate if someone could have a look. "Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource " //connect to database $mysqli = mysqli_connect("", "", "", ""); //Set the selected category $selected_cat = (isset($_GET["cat_id"])) ? $_GET["cat_id"] : false; //show categories first $get_cats_sql = "SELECT cat_id, cat_title FROM category ORDER BY cat_id"; $get_cats_res = mysqli_query($mysqli, $get_cats_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_cats_res) < 1) { $categoryList = "<p><em>Sorry, no categories to browse.</em></p>"; } else { //Display the categories while ($cats = mysqli_fetch_array($get_cats_res)) { $categoryList .= "<a href=\"listtest5.php?cat_id={$cats['cat_id']}\">{$cats['cat_title']} <br /></a>\n"; if ($cats['cat_id']==$selected_cat); } //get items $get_items_sql = "SELECT id, title, city, state, country, deadline, brief_description, activationkey, date FROM table WHERE MONTH(date) = MONTH(CURDATE()) ORDER BY date"; $get_items_res = mysqli_query($mysqli, $get_items_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_items_res) < 1) { $content = "<p><em>Sorry, no items in this category.</em></p>\n"; } else { $content .= "<ul>\n"; while ($items = mysqli_fetch_array($get_items_res)) { $item_url = "detail.php?id={$items['id']}"; $item_title = stripslashes($items['title']); $item_city = $items['city']; $item_state = $items['state']; $item_country = $items['country']; $item_deadline = $items['deadline']; $item_brief_description = $items['brief_description']; $item_id = $items['id']; $content .= ""; $content .="<table width=\"693\" border=\"0\"><tr><td width=\"200\"><a href=$item_url>$item_title</a></td><tr><td class=blackfont width=\"251\">{$item_city}, {$item_state} - {$item_country}</td></tr><tr><td class=blackfont width=\"109\">Deadline: {$item_deadline}</td></tr><tr><td class=\"blackfont\">{$item_brief_description}</td></tr><br /></table>"; $content .= "\n"; } $content .= "</ul>\n"; }
  21. Thanks. That showed me the error BUT, I'm confused by the error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource
  22. I'm testing a page live that works perfectly on my local host server but comes up blank when uploaded to my website. Is there an error setting I can turn on on the live web server in MySql? All the tables are correct but still nothing. Any ideas??
  23. I fixed it. Thanks. In code that was just above the code that's shown (the next line above), there was a curly bracket that needed to be switched from open to closed and one had to be removed from the bottom. Thanks Pikachu for noticing my missing quote too. Got it fixed. It's a lot of stress on the brain learning PHP! I appreciate all your help you've given me.
×
×
  • 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.