Jump to content

Need Help With The Following Php Script For Web Site.


jlindsey

Recommended Posts

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 post-134049-0-18734600-1354043943_thumb.jpg is what is currently outputted.

The Second Picture attached post-134049-0-62751700-1354043951_thumb.jpg is what I would like the finished product to look similar too.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.