Jump to content

jlindsey

Members
  • Posts

    13
  • Joined

  • Last visited

jlindsey's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am stuck on this one little mysql query. I have two columns named FamilyID and username. My first query is easy because it searches through the whole table for the Family ID that a user is trying to create. If the Family ID that they are trying to create has been created, an errormsg will come up saying, "Family Id has already been created". That works great! My second query is the one I cannot get to work and I know it is because of my very limited skills. What I need is for the query to see if the column FamilyID has data, or if it has no data and I need the search narrowed to the user that is logged in. The variable for the user logged in is $user and the column name is username. So if the the user that is logged in has data in their FamilyID column, I want an errormsg that says "You have already created a Family ID.". If it does not then I obviously want the script to continue. Also FamilyID column is varchar and not init inside the database. Below is what I have so far for my script and the problem area is in bold. <?php if ($_POST['postgift']) { $Family = $_POST['FamilyID']; $password = $_POST['password']; $getretypepass = $_POST['retypepass']; if ($Family) { if ($password) { if ($getretypepass) { if ( $password === $getretypepass ) { require("./connect-mysql.php"); $query = mysql_query("SELECT * FROM users WHERE FamilyID='$Family'"); $numrows = mysql_num_rows($query); if ($numrows == 0) { $query = mysql_query("SELECT FamilyID FROM users WHERE username='$user'"); $numrows = mysql_num_rows($query); if ($numrows == 0) { $password = md5(md5("j3k4k3".$password."j4j4lk")); $query = ("UPDATE users SET FamilyID='$_POST[FamilyID]', fampassword='$password' WHERE username='$user'"); if (!mysql_query($query)) { die('Error: ' . mysql_error()); } echo 'You Have Created a Family ID. <a href="member.php" style=color:#000000>Click here</a> to go back to Family Christmas Lists'; } else $errormsg = "You Have Already Created A Family."; } else $errormsg = "That Family ID has already been Created."; mysql_close(); } else $errormsg = "Your passwords did not match."; } else $errormsg = "You must re-enter your password."; } else $errormsg = "You Must Create a password for the Family ID."; } else $errormsg = "You Must Enter a Family ID."; } echo "<form action='./createfamilyid.php' method='post'> <table> <tr> <td></td> <td><font color='red'>$errormsg</font></td> </tr> <tr> <td><b>Family ID:</b></td> <td><input type='text' size='25' name='FamilyID'></td> </tr> <tr> <td><b>Password:</b></td> <td><input type='password' name='password' value='' /></td> </tr> <tr> <td><b>Retype Password:</b></td> <td><input type='password' name='retypepass' value='' /></td> </tr> <tr> <td></td> <td><input type='submit' name='postgift' value='Create Family ID' /></td> </tr> </table> </form>"; ?>
  2. My problem is I am having trouble narrowing down a search in a query. Here is my query below. $query = mysql_query("SELECT * FROM users WHERE FamilyID='$Family' AND username='$user'"); $numrows = mysql_num_rows($query); if ($numrows == 0) { } else $errormsg = "You Have Already Created A Family."; Basically what I need is for the query to find the FamilyID and Username row using the variable $user which is the current user that is logged in. The if statement then asks if the FamilyID row is empty, then proceed, if not then echo out an errormsg. The problem is that $numrows will obviously look at both the FamilyID and username row and will always echo out the errormsg instead of proceeding through the rest of the script. The username field is always going to be filled with data. What I need is a query that will select from the user that is currently logged in but also narrow it down by the FamilyID row. If that FamilyID row is empty, then I want the script to proceed. If not I want it to echo out an errormsg. Any Help would be much appreciated.
  3. I need the code which basically allows a user to view data in the database except for their own. What happens is people can view a gift registry by searching. I want them to be able to pull up everyone else s data except their own. I have posted the script below. <?php if($_GET) { $searchTerm = $_GET['keyword']; $searchTerm2 = $_GET['keyword2']; $dbuser = $_GET['FirstName']; $dbuser1 = $_GET['LastName']; if ($searchTerm) { if ($searchTerm2) { $connect = mysql_connect("localhost","#####","#####"); if($connect) { mysql_select_db("users",$connect); $query = "SELECT * FROM users WHERE FirstName='$searchTerm' AND LastName='$searchTerm2'"; $results = mysql_query($query); while($row = mysql_fetch_array($results)) { $output .= "<b>First Name:</b> " . $row['FirstName'] . "<br />"; $output .= "<b>Last Name:</b> " . $row['LastName'] . "<br />"; $output .= "<b>User ID:</b> " . $row['userid'] . "<br />"; $output .= "<b>City:</b> " . $row['city'] . "<br />"; $output .= "<b>State:</b> " . $row['state'] . "<br />"; $output .= "<b>Christmas Wish List Below:</b> " . "<br />"; $output .= "<b>(If the family member has included a link, you can get to the web site by clicking the gift.)</b> " . "<br />"; $output .= "<a href=".$row['Link'] . ">".$row['Gift'] . "</a>"; $output .= $row['purchased_gift'] . "</a><br>"; $output .= "<a href=".$row['Link2'] . ">".$row['Gift2'] . "</a>"; $output .= $row['purchased_gift2'] . "</a><br>"; $output .= "<a href=".$row['Link3'] . ">".$row['Gift3'] . "</a>"; $output .= $row['purchased_gift3'] . "</a><br>"; $output .= "<a href=".$row['Link4'] . ">".$row['Gift4'] . "</a>"; $output .= $row['purchased_gift4'] . "</a><br>"; $output .= "<a href=".$row['Link5'] . ">".$row['Gift5'] . "</a>"; $output .= $row['purchased_gift5'] . "</a><br>"; $output .= "<a href=".$row['Link6'] . ">".$row['Gift6'] . "</a>"; $output .= $row['purchased_gift6'] . "</a><br>"; $output .= "<a href=".$row['Link7'] . ">".$row['Gift7'] . "</a>"; $output .= $row['purchased_gift7'] . "</a><br>"; $output .= "<a href=".$row['Link8'] . ">".$row['Gift8'] . "</a>"; $output .= $row['purchased_gift8'] . "</a><br>"; $output .= "<a href=".$row['Link9'] . ">".$row['Gift9'] . "</a>"; $output .= $row['purchased_gift9'] . "</a><br>"; $output .= "<a href=".$row['Link10'] . ">".$row['Gift10'] . "</a>"; $output .= $row['purchased_gift10'] . "</a><br>"; $output .= "<a href=".$row['Link11'] . ">".$row['Gift11'] . "</a>"; $output .= $row['purchased_gift11'] . "</a><br>"; $output .= "<a href=".$row['Link12'] . ">".$row['Gift12'] . "</a>"; $output .= $row['purchased_gift12'] . "</a><br>"; $output .= "<a href='purchasegifts2.php' style=color:#090000>PURCHASE GIFTS HERE</a><br>"; } echo $output; } else { die(mysql_error()); } } else echo "You Must Enter a Last Name."; } else echo "You Must Enter a First Name."; } mysql_close($connect); ?>
  4. $UpdateQuery = "UPDATE users SET purchased_gift=$_POST[purchased_gift]' WHERE userid='$searchTerm'"; Forgot a ' in front of =$_POST[
  5. OK I did some cleaning up to the script, Still cannot get the second form which is located inside the script to work. I moved the first form outside my php tags and it call on the data just fine and pulls up the correct information that is needed. After the search is complete a user can then enter data into a new form that was displayed by the first search. Except my script is not updating my database to whatever it is that I entered in the form. But if I go into the database and manually enter it, the information is then displayed on the form where I need to update information. So obviously I am doing something wrong with this script. I cleaned it up a bunch so it should be easier to read. Thank You for any help. <form action = "" method = "GET"> <input type = "text" name = "keyword" /> <input type = "submit" name = "searchbtn" value = "Search Gift Registry" /> </form> <br></br> <?php if($_GET) { $searchTerm = $_GET['keyword']; $connect = mysql_connect("localhost","#####","######"); if($connect) { mysql_select_db("users",$connect); $query = "SELECT * FROM users WHERE userid='$searchTerm'"; $results = mysql_query($query); while($row = mysql_fetch_array($results)) { $output .= "<b>First Name:</b> " . $row['FirstName'] . "<br />"; $output .= "<b>Last Name:</b> " . $row['LastName'] . "<br />"; $output .= "<b>User ID:</b> " . $row['userid'] . "<br />"; } echo $output; if (isset($_POST['submitbtn'])){ $UpdateQuery = "UPDATE users SET purchased_gift=$_POST[purchased_gift]' WHERE userid='$searchTerm'"; mysql_query($UpdateQuery, $connect); }; $query = "SELECT * FROM users WHERE userid='$searchTerm'"; $myData = mysql_query($query, $connect); echo '<form method="post" action="">'; // Table header. echo '<table align="center" cellspacing="0" cellpadding="5" border="2"> <tr> <td align="center"><b>Gifts</b></td> <td align="center"><b>Purchase Gifts</b></td> </tr>'; while ($row = mysql_fetch_array($myData)) { echo "<tr>"; echo "<td>" . $row['Gift'] . "</td>"; echo ' <td align="left"><input type="text" size="25" name="purchased_gift" value="'.$row['purchased_gift'].'"></td> </tr>'; echo "<tr>"; echo "<td>" . $row['Gift2'] . "</td>"; echo ' <td align="left"><input type="text" size="25" name="purchased_gift2" value="'.$row['purchased_gift2'].'"></td> </tr>'; } echo '</table>'; echo '<br /><div align="center"><input type="submit" name="Submit" value="Update Gift Registry" /></div> <input type="hidden" name="submitbtn" value="submitbtn" />'; echo '</form>'; } else { die(mysql_error()); } } mysql_close($connect); ?>
  6. What about my two forms? First form works but second does not. The second form basically keeps calling for the first for which makes sense. So how can I differentiate between the two forms?
  7. Well that is where I'm having trouble, cant figure out what to do with my updatequery or where to put it. I left it out of the script above hoping someone would help me with the updatequery. I updated the script above with the updatequery but I know it needs work. Just getting into php so learning as I go.
  8. I know what the issue is, I just can't figure out the solution. The problem is I have a page which searches for users in a database by their User ID. That is the first form that is processed and it works great. It finds the user and outputs the correct information. The second form is then supposed to let users enter data and then update the database. Only it doesn't update the database at all. I know the issue has something to do with how I'm processing two forms on one page. I just can't seem to get the second form to work and update the database. I think I am this close to getting this worked out I just need a little hope with the script below. <?php $form = "<form id='search' action='./purchasegifts.php' method='get'> <label>User ID: <input type='text' name='keyname' /> </label> <input type='submit' name='viewgift' value='Search Gift Registry' /> </form>"; echo $form; echo "<br></br>"; $searchTerm = trim($_GET['keyname']); //check whether the name parsed is empty if($searchTerm == "") { echo ""; exit(); } //database connection info $host = "localhost"; //server $db = "users"; //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 $sql = "SELECT * FROM users WHERE userid='$searchTerm'"; $myData = mysqli_query($link, $sql); $myData2 = mysqli_query($link, $sql); $myData3 = mysqli_query($link, $sql); if(mysqli_num_rows($myData) >= 1) { echo '<table align="center" cellspacing="0" cellpadding="5" border="2"> <tr> <td align="center"><b>First Name</b></td> <td align="center"><b>Last Name</b></td> </tr>'; while($row = mysqli_fetch_array($myData2)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "<br></br>"; if (isset($_POST['updatebtn'])){ $UpdateQuery = "UPDATE users SET purchased_gift='$_POST[purchased_gift]' WHERE username='$username'"; mysql_query($UpdateQuery, $link); }; echo '<form id="update" method="post" action="purchasegifts.php">'; // Table header. echo '<table align="center" cellspacing="0" cellpadding="5" border="2"> <tr> <td align="center"><b>Gifts</b></td> <td align="center"><b>Purchase Gifts</b></td> </tr>'; { while ($row = mysqli_fetch_array($myData3)) { echo "<tr>"; echo "<td>" . $row['Gift'] . "</td>"; echo ' <td align="left"><input type="text" size="25" name="purchased_gift" value="'.$row['purchased_gift'].'"></td> </tr>'; echo "<tr>"; echo "<td>" . $row['Gift2'] . "</td>"; echo ' <td align="left"><input type="text" size="25" name="purchased_gift2" value="'.$row['purchased_gift2'].'"></td> </tr>'; } } echo '</table>'; echo '<br /><div align="center"><input type="submit" name="Submit" value="Purchase Gifts" /></div> <input type="hidden" name="updatebtn" value="updatebtn" />'; echo '</form>'; mysqli_close($link); } else echo "There was no matching record for the User ID " . $searchTerm; ?>
  9. The site is www.familychristmaslists.com. That might help you out a bit.
  10. 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.
  11. 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.
  12. 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.
×
×
  • 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.