Jump to content

Cflax

Members
  • Posts

    20
  • Joined

  • Last visited

    Never

Everything posted by Cflax

  1. you can run a check to the session or cookie to see, for example, if the userid is set then use an if empty session userid display the form else display a successful login or whatever you are using the form for example if (empty($_SESSION['user_id'])) { echo '<p class="error">' . $error_msg . '</p>'; ?> <form blah blah blah></form> <?php } else { // Confirm the successful log-in echo('<p class="login">You are logged in as <strong>' . $_SESSION['username'] . '</strong>.</p><p class="login"> You will be redirected in 3 seconds.</p>'); echo '<META HTTP-EQUIV="Refresh" Content="3; URL=index.php">'; } hope this helps, im still pretty new to this
  2. set the value to a if statement that looks to see if that input field has been stored; if so, echo the stored data <label for="price">Price:</label>$ <input type="text" name="price" value="<?php if (!empty($price)) echo $price; ?>" /> hope this helps
  3. did some searching on the internet and didnt find much. i have created an online classifieds website and want all created listings to expire and delete after a certain amount of days. honestly i have no idea where to start with this implementation. cookies were the only thing that even crossed my mind... any ideas? btw each listing is stored in a table called ob_listings
  4. sorry for the late reply... i had already changed the name of the form, but i did just forget to close the form tag XP thanks for the help again guys
  5. I'm not sure why, but once I added a search form in my nav menu, it made my other forms on the website such as login and signup form take them to where the search button would take them. any ideas???
  6. $query = 'select * from ob_listings where categoryid=' . $_POST["category"] . ' and subject like '%$term%' or description like '%$term%''; i want the query to select all from the table ob_listings where categoryid=$_post["category"] AND then from the items that fit that category subject like '%$term%' or description like '%$term%'' not that familiar with sql statements
  7. figured it out, for anyone that cares here is my corrected code in search.php $term = $_POST['term']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "select * from ob_listings where subject like '%$term%' or description like '%$term%' "; $data = mysqli_query($dbc, $query); while ($row = mysqli_fetch_array($data)){ echo 'Subject: '.$row['subject']; echo '<br/> Date: '.$row['date']; echo '<br/> Price: '.$row['price']; echo '<br/> City: '.$row['city']; echo '<br/><br/>'; }
  8. hey guys, i have a search bar i am implementing into my navmenu but keeping getting errors returned and im not sure why This is the code in my navmenu to display the search bar echo '<form action="search.php" method="post">Search: <input type="text" name="term" /> <input type="submit" name="submit" value="Search"/>'; Here is the php file that query's the search $term = $_POST['term']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = mysqli_query("select * from ob_listings where subject like '%$term%' or description like '%$term%' "); while ($row = mysql_fetch_array($dbc, $query)){ echo 'Subject: '.$row['subject']; echo '<br/> Date: '.$row['date']; echo '<br/> Price: '.$row['price']; echo '<br/> City: '.$row['city']; echo '<br/><br/>'; } any help is much appreciated here are the errors being returned Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\vhosts\HeadFirst\ourbazzar\search.php on line 16 (line 16 is the $query) Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\vhosts\HeadFirst\ourbazzar\search.php on line 17 (line 17 is the while loop)
  9. i have a form that has a price field, but if anything other than a decimal (0.00) a zero is entered into the database. There is the problem of people trying to add a dollar sign before their amount. What is the best way to validate a price amount to be entered into the database. The column in the database type is decimal(6,2). Any suggestions?
  10. at this point im open for suggestions for a different way to make my links display only results with a value equal to their name using my navmenu.php file and my viewlistings.php file Keep in mind that I do need to keep the information the link shows dynamic so that if a category is added to the table, a link is created automatically
  11. no, it just displays the first entry it gets on all links...im still unsure of why it i thought "maybe storing the get results as variables in viewlistings.php might lock in JUST the first result" so i tried pulling the info from get everytime i needed it, instead of assigning it a value... still the same problem... here is what i changed viewlistings.php to with still no luck...this way they continue to just show the first result if (isset($_GET['listing_id']) && isset($_GET['subject']) && isset($_GET['description']) && isset($_GET['price']) && isset($_GET['user_id']) && isset($_GET['category_id']) && isset($_GET['date']) && isset($_GET['city']) && isset($_GET['state'])) { /* // Grab the score data from the GET $listing_id = $_GET['listing_id']; $subject = $_GET['subject']; $description = $_GET['description']; $price = $_GET['price']; $user_id = $_GET['user_id']; $category_id = $_GET['category_id']; $date = $_GET['date']; $city = $_GET['city']; $state = $_GET['state'];*/ // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the user data from MySQL $query = 'SELECT * FROM ob_listings WHERE category_id="' . $_GET['category_id'] . '" ORDER BY date DESC'; $data = mysqli_query($dbc, $query); } // Loop through the array of user data, formatting it as HTML echo '<h4>' . $_GET['category_id'] . ':</h4>'; echo '<table><tr><td><strong>Listing</strong></td><td><strong>Location</strong></td><td><strong>Date Posted</strong></td><td><strong>Price</strong></td></tr>'; while ($row = mysqli_fetch_array($data)) { echo '<tr><td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['subject'] . '</a></td>'; echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['city'] . ', ' . $row['state'] . '</a></td>'; echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['date'] . '</a></td>'; echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['price'] . '</a></td></tr>'; } echo '</table>';
  12. *EDIT* i have come to find that the code is kind of working. It's doing what i want it to do, but when viewlistings.php stores the get values its only storing the first get value, resulting in only displaying ONE listing any ideas???
  13. Here is my current navmenu.php i pulls category names from a table and makes them links so if you add a category later, it's automatically added to the menu. That part works. The problem I am running into now, is that i want the the links to store $row1 data via GET (I know its a lot to store there, but it's how im doing it this time around) I thought the following code would successfully store the data i wanted, but when i looked at my viewlistings.php no information is showing up. navmenu.php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query = "SELECT * FROM ob_category"; $data = mysqli_query($dbc, $query); $query1 = "SELECT * FROM ob_listings"; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); $links = array(); while($row=mysqli_fetch_array($data)){ $links[] = '<a href="viewlistings.php?listing_id=' . $row1['listing_id'] . '&subject=' . $row1['subject'] . '&description=' . $row1['description'] . '&price=' . $row1['price'] . '&user_id=' . $row1['user_id'] . '&category_id=' . $row1['category_id'] . '&date=' . $row1['date'] . '&city=' . $row1['city'] . '&state=' . $row1['state'] .'">' . $row['name'] . '</a>'; } echo implode(' &#8226; ', $links); echo '<hr />'; viewlistings.php if (isset($_GET['listing_id']) && isset($_GET['subject']) && isset($_GET['description']) && isset($_GET['price']) && isset($_GET['user_id']) && isset($_GET['category_id']) && isset($_GET['date']) && isset($_GET['city']) && isset($_GET['state'])) { // Grab the score data from the GET $listing_id = $_GET['listing_id']; $subject = $_GET['subject']; $description = $_GET['description']; $price = $_GET['price']; $user_id = $_GET['user_id']; $category_id = $_GET['category_id']; $date = $_GET['date']; $city = $_GET['city']; $state = $_GET['state']; // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the user data from MySQL $query = 'SELECT * FROM ob_listings WHERE category_id="' . $category_id . '" ORDER BY date DESC'; $data = mysqli_query($dbc, $query); } // Loop through the array of user data, formatting it as HTML echo '<h4>' . $cateory_id . ':</h4>'; echo '<table><tr><td><strong>Listing</strong></td><td><strong>Location</strong></td><td><strong>Date Posted</strong></td><td><strong>Price</strong></td></tr>'; while ($row = mysqli_fetch_array($data)) { echo '<tr><td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['subject'] . '</a></td>'; echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['city'] . ', ' . $row['state'] . '</a></td>'; echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['date'] . '</a></td>'; echo '<td><a href="listingdetails.php?listing_id=' . $row['listing_id'] . '&subject=' . $row['subject'] . '&description=' . $row['description'] . '&price=' . $row['price'] . '&date=' . $row['date'] . '&city=' . $row['city'] . '&state=' . $row['state'] . '&user_id=' . $row['user_id'] . '&category_id=' . $row['category_id'] . '"> ' . $row['price'] . '</a></td></tr>'; } echo '</table>'; I would REALLY REALLY appreciate it if someone could help me get this working... its the last part of my site i need to get working before i turn it in thursday. thanks in advance Im almost positive that the problem is in navmenu.php because when I click on the links all the fields are empty in the URL.
  14. hope someone can help me out here, stuck on this page... This page shows the details of the listing they had just clicked on on the previous page. this part works If the person logged in is the person who is looking at the page, the email section does not show. this part works However, the part I cannot get to work, is when the logged in user types their email message and clicks send email. at this point the details of listing stop showing PLZ SOMEONE HELP ME thanks in advance, i hope <?php // Start the session require_once('startsession.php'); // Insert the page header $page_title = 'Listing Details'; require_once('header.php'); require_once('connectvars.php'); // Show the navigation menu require_once('navmenu.php'); if(isset($_POST['submit'])){ $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the user data from MySQL $query1 = 'SELECT email FROM ob_user WHERE username="' . $user_name . '"'; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); $email = $row1['email']; $to = $email; $subject = 'OurBazzar response to' . $subject . ''; $body = $_POST['email']; $headers = 'From: caleb.jordan.flax@gmail.com'; if (mail($to, $subject, $body, $headers)) { echo("<p>Message sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } end(); } if (isset($_GET['listing_id']) && isset($_GET['subject']) && isset($_GET['description']) && isset($_GET['price']) && isset($_GET['date']) && isset($_GET['city']) && isset($_GET['state']) && isset($_GET['user_id']) && isset($_GET['category_id'])) { // Grab the score data from the GET $listing_id = $_GET['listing_id']; $title = $_GET['subject']; $description = $_GET['description']; $price = $_GET['price']; $date = $_GET['date']; $city = $_GET['city']; $state = $_GET['state']; $userid = $_GET['user_id']; $categoryid = $_GET['category_id']; } // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Retrieve the user data from MySQL $query = 'SELECT username FROM ob_user WHERE user_id="' . $userid . '"'; $data = mysqli_query($dbc, $query); $row = mysqli_fetch_array($data); $query1 = 'SELECT name FROM ob_category WHERE category_id="' . $categoryid . '"'; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); $user_name = $row['username']; $category_name = $row1['name']; echo '<table>'; echo '<tr><td colspan="2"><strong>' . $title . '</strong></td></tr>'; echo '<tr><td>Created by: </td><td>' . $user_name . '</td></tr>'; echo '<tr><td>Date created: </td><td>' . $date . '</td></tr>'; echo '<tr><td>Location: </td><td>' . $city . ', ' . $state . '</td></tr>'; echo '<tr><td>Category: </td><td>' . $category_name . '</td></tr>'; echo '<tr><td>Description: </td><td>' . $description . '</td></tr>'; echo '</table>'; if ((isset($_SESSION['username'])) && ($_SESSION['username'] != $user_name)) { ?> <br /> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Send Email to <?php echo $user_name; ?></legend> <label for="email">Message: </label> <input type="text" name="email" /><br /> <input type="submit" value="Send Email" name="submit"> </fieldset> <?php } require_once('footer.php'); ?>
  15. after changing that it works great thank you so much
  16. just saw it, i gave it a try and did not work it returned them all multiple times
  17. i have this while loop making my category links at the top of my page, but i still have the bullet after the last item. ive looked at other examples and CANNOT get mine to follow suit...help plz? $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query1 = "SELECT * FROM ob_category"; $data1 = mysqli_query($dbc, $query1); while($row=mysqli_fetch_array($data1)){ echo '<a href="viewlistings.php">' . $row['name'] . '</a> &#8226; '; }
  18. ya it did but i got it to work from what you said THANK YOU lol <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query1 = "SELECT name FROM ob_category"; $data1 = mysqli_query($dbc, $query1); while($row=mysqli_fetch_array($data1)){ echo '<a href="viewlistings.php">' . $row['name'] . '</a> •'; } ?> now to figure out how to get rid of the bullet separator on the last category
  19. I am trying to make a basic navigation across the top of my pages in my navmenu showing all of the categories in my ob_category table. so if i add a category to the database later, the link in the navmenu is automatically added. this is what i was experimenting with at the moment: <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $query1 = "SELECT * FROM ob_category"; $data1 = mysqli_query($dbc, $query1); $row1 = mysqli_fetch_array($data1); foreach($row1['name'] as $value){ echo '<a href="viewlistings.php">' . $value . '</a> &#8226;'; } ?> not working, I'm not worried about the links working quite yet, its the category names im most concerned about any ideas??
  20. Hello all...fairly new to this php/mysql thing... working on my final project thats due in about 24 hours... and i hit a rut... im making a pretty basic, online classifieds site. users can sign up, login, post new listings and view others listings by clicking on different categories. the problem i am having right now is this...When the user clicks on "My listings" i need it to pull only the listings that were created by that users user_id, which is the primary key in my user_info table...my professor suggested storing it in hidden field through the login submit button...very confused and frustrated... any help is much appreciated...
×
×
  • 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.