Jump to content

Recommended Posts

I have a form that I created that pulls data from a table in MySQL database. On submit that data is put into another table. Each time a particular user goes back to that form, I do not want the data that they have already submitted to be an option in the list. Is there a way to do that? Any and all help would be much appreciated.

 

My for code:

 

<form action="submit.php" method="post">
	<ul>
		<li>Username: <?php /*Displays Logged in Users Name*/	echo $_SESSION["usr"];?></li>
		<li>Weekly Pick
					<?php	$query="SELECT name,id FROM PRO";
								$result=mysql_query($query);
								echo "<select name=PRO value='golfer'>Golfers Name</option>";
								while($golfer=mysql_fetch_array($result)){
								echo "<option value='$golfer[name]'>$golfer[name]</option>";
								}
								echo "</select>";?></li>
		<li>Tournament:
					<?php	$query2="SELECT tournament,id FROM 2011_Tournament";
								$result2=mysql_query($query2);
								echo "<select name=2011_Tournament value='tournament'>Tournament</option>";
								while($tournament=mysql_fetch_array($result2)){
								echo "<option value='$tournament[tournament]'>$tournament[tournament]</option>";
								}
								echo "</select>";?></li>
		<li>Backup:
					<?php $query3="SELECT name,id FROM PRO";
							/* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
								$result3 = mysql_query ($query3);
								echo "<select name=PRO2 value='backup'>Golfers Name</option>";
								// printing the list box select command
								while($backup=mysql_fetch_array($result3)){//Array or records stored in $nt
								echo "<option value='$backup[name]'>$backup[name]</option>";
								/* Option values are added by looping through the array */
								}
								echo "</select>";// Closing of list box ?></li>
		<li>Date & Time: <?php date_default_timezone_set('US/Eastern'); $time = date("m-d-Y H:i:s"); echo $time;?></li>
	</ul>
	</form>

Link to comment
https://forums.phpfreaks.com/topic/247714-help-with-a-php-form/
Share on other sites

If I understand you correctly, when you go back to the form, add a condition to the query that checks that the info is not in the other table. Ex:

 

SELECT * FROM Table1 WHERE Field NOT IN (SELECT * FROM Table2)

 

Hope I understood you correctly.  :shrug:

When the form is loaded I it check for the "logged in user" and automatically populate the Username field in the form. How do I check the other table for the specified username that is currently logged into the system as well as previous form entries of the golfer?

When the form is loaded I it check for the "logged in user" and automatically populate the Username field in the form. How do I check the other table for the specified username that is currently logged into the system as well as previous form entries of the golfer?

 

Ok, I think I get you. You want to make sure it's not in the other table AND that the user is a valid/registered user or whatever.

 

Take that original sql statement and add an AND condition that checks for the user:

SELECT * FROM Table1 WHERE Field NOT IN (SELECT * FROM Table2) AND Username IN (SELECT Username FROM Table3)

 

I think that's what you mean. If I'm misunderstanding, I appologize.

Still not working, here is my latest code:

 

<li>Username: <?php /*Displays Logged in Users Name*/ $_SESSION["usr"] = usr; echo usr;?></li>
		SELECT * FROM Table1 WHERE Field NOT IN (SELECT * FROM Table2)
		<li>Test Drop Down: 
			<?php	$query="SELECT name,id FROM PRO WHERE name NOT IN (SELECT golfer FROM weekly_picks) AND usr NOT IN (SELECT usr FROM weekly_picks)";
								$result=mysql_query($query);
								echo "<select name=PRO value='golfer'>Golfers Name</option>";
								while($golfer=mysql_fetch_array($result)){
								echo "<option value='$golfer[name]'>$golfer[name]</option>";
								}
								echo "</select>";?></li>

What does it do/not do? Any errors?

 

Not sure what you're trying to do here, but this invalidly sets a variable (so its not getting set) and then you echo it incorrectly too

<li>Username: <?php /*Displays Logged in Users Name*/ $_SESSION["usr"] = usr; echo usr;?></li>

 

I think you mean this?

$usr = $_SESSION['usr']; echo $usr;

 

 

I fixed that code, but I still cannot get the following code to work:

 

 

<li>Username: <?php /*Displays Logged in Users Name*/ echo $userid;?></li>
		<li>Test Drop Down: 
			<?php	$query="SELECT name,id FROM PRO WHERE name NOT IN (SELECT golfer FROM weekly_picks) AND $userid NOT IN (SELECT usr FROM weekly_picks)";

 

The following code gives me a blank drop down list.

I think it's the $userid variable in the sql. That should be a field name, not the value. Try id, assuming usr holds an id in the table.

<li>Username: <?php /*Displays Logged in Users Name*/ echo $userid;?></li>
		<li>Test Drop Down: 
			<?php	$query="SELECT name,id FROM PRO WHERE name NOT IN (SELECT golfer FROM weekly_picks) AND id NOT IN (SELECT usr FROM weekly_picks)";

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.