jlindsey Posted November 27, 2012 Share Posted November 27, 2012 The script below allows users to search through a database and display the user that was searched. It then outputs the user information so people who searched for that user can view his or her gift information. What I need help with is that when the outputted information is displayed, I would like the user to be able to click or check mark the data which lies in the database and basically mark the data as purchased. So the next time that user is searched for, It either says the the item was purchased or removes the item from the list period. Let me know if more information is needed like database fields, ect.. I am new to php so any help would be greatly appreciated. The Script is Below. <?php $form = "<form action='./viewgifts.php' method='get'> <label>First Name: <input type='text' name='keyname' /> </label> <label>Last Name: <input type='text' name='keyname2' /> </label> <input type='submit' name='viewgift' value='Search Gift Registry' /> </form>"; echo $form; echo "<br></br>"; $searchTerm = trim($_GET['keyname']); $searchTerm2 = trim($_GET['keyname2']); //check whether the name parsed is empty if($searchTerm == "") { echo "Enter First Name you are searching for."; exit(); } if($searchTerm2 == "") { echo "Enter Last Name you are searching for."; exit(); } //database connection info $host = "localhost"; //server $db = "****"; //database name $user = "******"; //dabases user name $pwd = "******"; //password //connecting to server and creating link to database $link = mysqli_connect($host, $user, $pwd, $db); //MYSQL search statement $query = "SELECT * FROM users WHERE FirstName LIKE '%$searchTerm%' AND LastName LIKE '%$searchTerm2%'"; $results = mysqli_query($link, $query); /* check whethere there were matching records in the table by counting the number of results returned */ if(mysqli_num_rows($results) >= 1) { while($row = mysqli_fetch_array($results)) { $output .= "<b>First Name:</b> " . $row['FirstName'] . "<br />"; $output .= "<b>Last Name:</b> " . $row['LastName'] . "<br />"; $output .= "<b>City:</b> " . $row['city'] . "<br />"; $output .= "<b>State:</b> " . $row['state'] . "<br />"; $output .= "<b>Christmas Wish List Below:</b> " . "<br />"; $output .= "(If the family member has included a link, you can get to the web site by clicking the gift.) " . "<br />"; $output .= "<a href=".$row['Link'] . ">".$row['Gift'] . "</a><br>"; $output .= "<a href=".$row['Link2'] . ">".$row['Gift2'] . "</a><br>"; $output .= "<a href=".$row['Link3'] . ">".$row['Gift3'] . "</a><br>"; $output .= "<a href=".$row['Link4'] . ">".$row['Gift4'] . "</a><br>"; $output .= "<a href=".$row['Link5'] . ">".$row['Gift5'] . "</a><br>"; $output .= "<a href=".$row['Link6'] . ">".$row['Gift6'] . "</a><br>"; $output .= "<a href=".$row['Link7'] . ">".$row['Gift7'] . "</a><br>"; $output .= "<a href=".$row['Link8'] . ">".$row['Gift8'] . "</a><br>"; $output .= "<a href=".$row['Link9'] . ">".$row['Gift9'] . "</a><br>"; $output .= "<a href=".$row['Link10'] . ">".$row['Gift10'] . "</a><br>"; $output .= "<a href=".$row['Link11'] . ">".$row['Gift11'] . "</a><br>"; $output .= "<a href=".$row['Link12'] . ">".$row['Gift12'] . "</a><br>"; } echo $output; } else echo "There was no matching record for the name " . $searchTerm . $searchTerm2; ?> The First Picture attached is what is currently outputted. The Second Picture attached is what I would like the finished product to look similar too. Quote Link to comment https://forums.phpfreaks.com/topic/271265-need-help-with-the-following-php-script-for-web-site/ Share on other sites More sharing options...
NomadicJosh Posted November 27, 2012 Share Posted November 27, 2012 (edited) Let me see if I understand correctly. So you want the database to be updated after the user purchases a particular gift in the registry? Edited November 27, 2012 by parkerj Quote Link to comment https://forums.phpfreaks.com/topic/271265-need-help-with-the-following-php-script-for-web-site/#findComment-1395688 Share on other sites More sharing options...
jlindsey Posted November 27, 2012 Author Share Posted November 27, 2012 Correct. How the site works is a user logs in and can view, update, and create gift registries. I would like users to be able to purchase a gift from a particular user that they searched for in the gift registry and the end result being that they can either purchase a gift or see that that gift has already been purchased. The script shouldn't be that difficult to build I'm just having trouble laying it out in my head. Quote Link to comment https://forums.phpfreaks.com/topic/271265-need-help-with-the-following-php-script-for-web-site/#findComment-1395711 Share on other sites More sharing options...
NomadicJosh Posted November 27, 2012 Share Posted November 27, 2012 Ok, the reason for the question is wouldn't it be dependent on the payment processor you use, so that they payment processor would send something back to the website in or to mark it in the database? I could be wrong but I think that is the best way to go about it. Quote Link to comment https://forums.phpfreaks.com/topic/271265-need-help-with-the-following-php-script-for-web-site/#findComment-1395730 Share on other sites More sharing options...
jlindsey Posted November 27, 2012 Author Share Posted November 27, 2012 No one actually purchases the gifts on my site. They just post what gifts they would like and that is put into the database. The purpose of the purchase the gift selection is to ensure that family & friends don't purchase the gift multiple times. So when a user is searching for a family or friend, that person will come up with the gifts they would like for christmas. I would like a way to remove the gift off the search so that it indicates that the gift was purchased (not on my site) so again it is not purchased multiple times. Quote Link to comment https://forums.phpfreaks.com/topic/271265-need-help-with-the-following-php-script-for-web-site/#findComment-1395744 Share on other sites More sharing options...
jlindsey Posted November 27, 2012 Author Share Posted November 27, 2012 The site is www.familychristmaslists.com. That might help you out a bit. Quote Link to comment https://forums.phpfreaks.com/topic/271265-need-help-with-the-following-php-script-for-web-site/#findComment-1395745 Share on other sites More sharing options...
rbrown Posted November 27, 2012 Share Posted November 27, 2012 you need to have each person have an ID then have a table with the ID | Gift (Optional add Wanted | Got) fields Then search by ID to display gifts. have a check box on submit will delete the gift from the list or if you use the options mark it as bought. Only problem I see is: Getting the correct person (I know of 5 people with the my name in my local area) without giving up too much personal information... way around this is no search capabilities. they have to enter the persons email address. That would stop someone from doing a search and pulling all your data or having idiots messing with the site and say they bought something for them when they didn't. Quote Link to comment https://forums.phpfreaks.com/topic/271265-need-help-with-the-following-php-script-for-web-site/#findComment-1395754 Share on other sites More sharing options...
rbrown Posted November 27, 2012 Share Posted November 27, 2012 Or add a "add to friends list" request the person wanting the gift. Quote Link to comment https://forums.phpfreaks.com/topic/271265-need-help-with-the-following-php-script-for-web-site/#findComment-1395755 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.