Jump to content

scmeeker

Members
  • Posts

    153
  • Joined

  • Last visited

    Never

Everything posted by scmeeker

  1. Thanks everyone for your help! It's working great now.
  2. In my form, I want to compare passwords to each other before inserting a new record. I can't seem to get this going. Here is the code from the form: <tr> <td><span class="blackfont">Password:</span></td> <td><input type="password" name="password" /> </td> </tr> <tr> <td><span class="blackfont">Reenter Password:</span> </td> <td><input type="password" name="checkpassword" /></td> </tr> <tr> And here is the form's "<form action="insert5.php" method="post">" the "insert5.php" code that goes with the form: <?php $con = mysql_connect("","","", ""); if (!$con) { die('Could not connect: ' . mysql_error()); } $test_name = "password"; $sub_name = "checkpassword"; while ($test_name == $sub_name) { mysql_select_db("lery", $con); $sql="INSERT INTO artist (username, password, email, terms) VALUES ('$_POST[username]','$_POST[password]','$_POST[email]', '$_POST[terms]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; } mysql_close($con) ?>
  3. Thank you...thank you...thank you...swisse! It worked! I was struggling and struggling with that one for several hours yesterday until I just crashed and decided to come back to it today with a refreshed mind. Glad I did. Thank you.
  4. I'm still having no luck with this. I'm going to post more, as I realized I didn't post another file that may help. Here is the user login form: <?php session_start(); $_SESSION['username'] = $_POST['username'];?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Art</title> <link href="styles/lery2.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- a:link { color: #09C; text-decoration: none; } a:visited { text-decoration: none; color: #09C; } a:hover { text-decoration: underline; } a:active { text-decoration: none; } --> </style></head> <div align="center"> <body> <div class="mainbody"> <div class="header1"></div> <div class="storeeditleftsidebar"><br /> <br /> </div> <br /> <br /> <br /> <br /> <span class="titlefont">Member sign in </span><br /> <span class="blackfont"><br /> sign in here. </span><br /> <br /> <table width="300" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> <tr> <form name="form1" method="post" action="checklogin.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="username" type="text" id="username"</td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="password" type="password" id="password"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Login"></td> </tr> </table> </td> </form> </tr> </table> Then the reference file for the form where it says"action = checklogin.php" is here: <?php session_start(); $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name="artist"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from form $myusername=$_POST['username']; $mypassword=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("username"); session_register("password"); header("location:listtest5.php"); } else { header ("location:userlogin_error.php"); } ?> Then there is the page where the session variable "username" is being sent and printed: <?php session_start(); //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=\"{$_SERVER['PHP_SELF']}?cat_id={$cats['cat_id']}\">{$cats['cat_title']} <br /></a>\n"; if ($cats['cat_id']==$selected_cat) { //get items $get_items_sql = "SELECT id, photo, username, title, price, date FROM product WHERE cat_id = '{$selected_cat}' ORDER BY date $pages->limit"; $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 = "items3.php?id={$items['id']}"; $item_title = stripslashes($items['title']); $item_price = $items['price']; $item_photo = $items['photo']; $item_username = $items['username']; $item_date = $items['date']; $content .= ""; list($width) = getimagesize($item_photo); // set the maximum width of the image here $maxWidth = 100; if ($width > $maxWidth); $content .= "<table width=\"603\" border=\"0\"><tr><td width=\"101\"> <a href=\"{$item_url}\"> <img alt=\"Image\" border=0 width=\"{$maxWidth}\" src=\"{$item_photo}\" /></a><td width=\"201\"> <a href=\"{$item_url}\">{$item_title}</a></td> <td width=\"109\">{$item_username}</td><td width=\"101\"> {$item_date}</td><td width=\"99\"> \${$item_price} USD </td></tr></table>"; $content .= "\n"; } $content .= "</ul>\n"; } } } } ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Art</title> <link href="styles/sgallery2.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- a:link { color: #09C; text-decoration: none; } a:visited { text-decoration: none; color: #09C; } a:hover { text-decoration: underline; } a:active { text-decoration: none; } --> </style></head> <div align="center"> <body> <div class="mainbody"> <div class="header1"> [color=red]<?php echo $_SESSION['username']; ?>[/color]</div> <div class="leftsidebar"><span class="titles"> Art Categories</span><br /> <br /> <?php echo $categoryList; ?> <br />
  5. Okay, I tried that without luck still. Here is the code for part of the user login form dealing with the input values: <form name="form1" method="post" action="checklogin.php"> <td> <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td colspan="3"></td> </tr> <tr> <td width="78">Username</td> <td width="6">:</td> <td width="294"><input name="username" type="text" id="username"></td> </tr> <tr> <td>Password</td> <td>:</td> <td><input name="password" type="password" id="password"></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Login"></td> </tr> And then at the top of the next page I've put: <?php session_start(); $_SESSION['username'] = $username; and in the HTML section put: <?php echo $_SESSION['username'];?> and I also tried: <?php echo $_SESSION[$username];?> and: <?php echo $username;?> with none of those working yet.
  6. Okay, at the top of my page I put: <?php session_start(); $_SESSION['username'] = 'username'; because I assume that the value is "username"? And then in the HTML code I put: <?php echo $_SESSION['username']; ?> When this is in, it simply prints out "username" literally and not the actual username. Hmmmm...and I've tried it several different ways....without luck.
  7. I know this must sound ridiculous but am I supposed to have session variable at the top of my "login page"? Just thought of that.
  8. $_SESSION['username'] = 'value'; When you say 'value', do I put that in the way it is or does it need to be changed because it is still coming up blank? Thanks.
  9. I'm trying to get the username from a login form to carry over to the next page and have the username show on top of the next using the session variables. I'll show my page in sections: At the top of the php part I have: <?php session_start(); session_register ("username"); $HTTP_SESSION_VARS ["username"] = $username; Then at the top of the html section I have: <?php echo "$username" ?> There are no errors but nothing is showing up when I login successfully. Any ideas? Any help with session variable is greatly appreciated because I'm new to PHP and have been looking and looking on the web without success. Thanks!
  10. Thanks so much for both of you're help but I got it worked out! I ended up getting some different code...that one wasn't working out so well.
  11. I don't have the cookie set up on listtest5.php yet. At this point I'm really trying to get it to redirect to another page of my choice after verification of the username and password. I tried removing the cookie to test that but it still didn't work.
  12. I'm creating a very basic user login form. After verifying the username and password, I would like it to go to another page: listtest5.php. It keeps going back to the original login (userlogin.html)even when using a valid username and password. How do I get it to redirect to listtest5.php after a successful login? Thanks for your help! if ((!isset($_POST["username"])) || (!isset($_POST["password"]))) { header("Location: listtest5.php"); exit; } //connect to server and select database $mysqli = mysqli_connect("localhost", "", "", ""); //create and issue the query $sql = "SELECT username, password FROM table WHERE username = '".$_POST["username"]."' AND password = PASSWORD('".$_POST["password"]."')"; $result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli)); //get the number of rows in the result set; should be 1 if a match if (mysqli_num_rows($result) == 1) { header("location:listtest5.php"); exit(); //set authorization cookie setcookie("auth", "1", 0, "/", "whereever.com", 0); } else { //redirect back to login form if not authorized header("Location: userlogin.html"); exit; } ?>
  13. That was it! Perfect. I was looking on the left for typos and it was on the right...of course. Thank you harkly.
  14. For some reason when echoing the $content, the price ($item_price) doesn't show up. Everything else works perfect (so far ). I would appreciate another set of eyes on this. Thanks!! //validate item $get_item_sql = "SELECT p.id, p.photo, p.username, p.title, p.date, p.price, p.location, p.store_id, s.store_id, s.username, s.store_name, s.location, s.news, s.websites FROM store AS s LEFT JOIN product AS p on s.store_id = p.store_id WHERE s.store_id = '".$_GET["store_id"]."'"; $get_item_res = mysqli_query($mysqli, $get_item_sql) or die(mysqli_error($mysqli)); if (mysqli_num_rows($get_item_res) < 1) { //invalid item $display_block .= "<p><em>Invalid item selection.</em></p>"; } else { $content .= "<ul>\n"; //valid item, get info while ($item_info = mysqli_fetch_array($get_item_res)) { $item_url = "items3.php?id={$items['id']}"; $cat_id = $item_info['cat_id']; $cat_title = strtoupper(stripslashes($item_info['cat_title'])); $store_id = $item_info['store_id']; $item_title = $item_info['title']; $item_store_name = $item_info['store_name']; $item_price = $items_info['price']; $item_photo = $item_info['photo']; $item_date = $item_info['date']; $item_username = $item_info['username']; $item_news = $item_info['news']; $item_websites = $item_info['websites']; $item_location = $item_info['location']; $item_store_id = $item_info['store_id']; $content .= ""; list($width) = getimagesize($item_photo); // set the maximum width of the image here $maxWidth = 100; if ($width > $maxWidth); $content .= "<table width=\"603\" border=\"0\"><tr><td width=\"101\"> <a href=\"{$item_url}\"> <img alt=\"Image\" border=0 width=\"{$maxWidth}\" src=\"{$item_photo}\" /></a><td width=\"201\"> <a href=\"{$item_url}\">{$item_title}</a></td> <td width=\"109\">{$item_username}</td><td width=\"101\"> {$item_date}</td><td width=\"99\"> \${$item_price} USD </td></tr></table>"; $content .= "\n";
  15. Resolved! I changed the s.store_id = p.id to s.store_id = p.store_id. Thanks anyway!
  16. I'm trying to join these two tables and its not pulling the information from the "product" table into the "store". I'm not able to access info I requested from the "product" table. Here is the code and hopefully you can help. I'm rather new to PHP and MySql so your help is very appreciated. Thanks!! $get_item_sql = "SELECT p.id, p.photo, p.username, p.title, p.date, p.location, p.store_id, s.store_id, s.username, s.store_name, s.location, s.news, s.websites FROM store AS s LEFT JOIN product AS p on s.store_id = p.id WHERE s.store_id = '".$_GET["store_id"]."'";
  17. I used this code for creating a single breadcrumb trail. Do I need to modify this in order to make it work throughout? Is there another way? I'm new to PHP so your advice is much appreciated. Thanks! $display_block .= "<p><strong><em>You are viewing:</em><br/> <a href=\"listtest5.php?cat_id=".$cat_id."\">".$cat_title."</a> > ".$item_title."</strong></p> <table cellpadding=\"3\" cellspacing=\"3\"> <tr>";
  18. I was able to incorporate a breadcrumbs moving from one page to the next but not multiple pages. Any suggestions?
  19. I would like to incorporate breadcrumbs into my website and was wondering if someone could point me in the right direction for some good reference pages? I'm not having much luck with googling. I saw a couple out there and I would like to be able to test this on my server at home and not have to upload it to a live server yet. Any suggestions? Thanks!
  20. Thanks SO much mjdamato! It worked perfect. I really appreciate it.
  21. Thanks mjdamato for the changes. I posted it but is still giving me the same problem, the items under the main category are still dropping underneath. I've tried using the "echo" and placing the "$display_block .= "</ul>";" out into the right center of the page it shows ALL the menu information, including the categories. I'm rather new to PHP and this has got me in a stump. I'm trying to get the information from: $item_url = "items3.php?id={$items['id']}"; $item_title = stripslashes($items['title']); $item_price = $items['price']; $item_photo = $items['photo']; $display_block .= "<li>"; $display_block .= "<a href=\"{$item_url}\">{$item_title}</a> (\${$item_price})"; $display_block .= "</li>\n"; to be displayed to another area of the page rather than right underneath the particular category but it doesn't want to let go.
  22. On my web page, I'm trying to have a list of clickable links on the left side of the page and then when you click one of those links(categories), it will list the items associated with that category on right. I'm able to have the category links come up on the left...no problem. When I click the category the items drop below it and show all the specific items. I want it to show up in the right/middle of the page...so I moved the code appropriately. Now when I click a category link on the left it only shows the very LAST item in the database rather then all of them associated with the category. So I'm wondering how I can make it show all the items rather than just the last one when I move the code to a different part of the page. Here is my code: //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) { $display_block = "<p><em>Sorry, no categories to browse.</em></p>"; } else { while ($cats = mysqli_fetch_array($get_cats_res)) { $cat_id = $cats['cat_id']; $cat_title = ($cats['cat_title']); $display_block .= "<a href=\"".$_SERVER["PHP_SELF"]."?cat_id=".$cat_id."\">".$cat_title." <br /></a>"; if (isset($_GET["cat_id"])) { if ($_GET["cat_id"] == $cat_id) { //get items $get_items_sql = "SELECT id, photo, title, price FROM product WHERE cat_id = '".$cat_id."' 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) { $display_block = "<p><em>Sorry, no items in this category.</em></p>"; } else { $display_block .= "<ul>"; while ($items = mysqli_fetch_array($get_items_res)) { $item_id = $items['id']; $item_photo = $items['photo']; $item_title = stripslashes($items['title']); $item_price = $items['price']; $display_block .= "<a href=\"items3.php?id=".$item_id."\">".$item_title."</a></strong> (\$".$item_price.")</li>"; } $display_block .= "</ul>"; }
  23. Thanks Rw. I tried what you suggested but all the records are still coming up. I was also confused when you said "//then know off the array reference." What did you mean by that? $res = mysqli_query($mysqli, $sql); $num_rows = mysqli_num_rows($res); $pages->items_total = $num_rows;// then know off the array reference Any other suggestions? Thanks for your help.
  24. I'm trying to add the Paginator script to my web page and it's almost there BUT it's bringing up all the records from my database instead of the select number of records. I'm posting my PHP code below (purposely leaving out my MySql connections), then I've attached the PHP reference file: paginator.class.php that's referenced in the code. Thanks for your help! <?php include('paginator.class.php'); $mysqli = mysqli_connect("", "", "", ""); if (mysqli_connect_errno()) { printf("Connect falied: %s\n", mysqli_connect_error()); exit (); } else { $sql = "SELECT * FROM product"; $res = mysqli_query($mysqli, $sql); $num_rows = mysqli_fetch_array($res); $pages = new Paginator; $pages->items_total = $num_rows[0]; $pages->mid_range = 9; // Number of pages to display. Must be odd and > 3 $pages->paginate(); if ($res) { while ($newArray = mysqli_fetch_array($res, MYSQLI_ASSOC)) { $detail = $newArray['id']; $photo = $newArray['photo']; $id = $newArray['title']; $price = $newArray['price']; list($width) = getimagesize($photo); // set the maximum width of the image here $maxWidth = 100; if ($width > $maxWidth) echo "<p><a href=\"painting.php\"><img alt=\"Image\" width=\"{$maxWidth}\" src=\"{$photo}\" /></a>"; echo " Title: ".$id." Price: ".$price."<br/"; } }else { printf("Could not retrieve records: %s\n", mysqli_error($mysqli)); } mysqli_free_result($res); mysqli_close($mysqli); } ?> <br /> <br /> <?php echo $pages->display_pages(); echo "<span class=\"\">".$pages->display_jump_menu().$pages->display_items_per_page()."</span>"; echo "<p class=\"paginate\">Page: $pages->current_page of $pages->num_pages</p>\n"; ?> <br /> [attachment deleted by admin]
×
×
  • 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.