Jump to content

re-executing mysql query after submission - two forms one page


Recommended Posts

Hi, I know this has to be possible but I have been unable to get this to work properly.

 

I have a page with two forms.  The first form is a list of sources associated with a subject, with checkboxes, so that it is possible to remove these associations, like so:

 

$qs = "SELECT s.source_id, s.source_name
	from source s, source_subject ss, subject sb
	where s.source_id = ss.source_id
	and sb.subject_id = ss.subject_id
	and sb.subject_id = $subject_id
	order by source_name";
$rs  = mysqli_query($dbc, $qs)
  or die ('Error querying database');


while($row = mysqli_fetch_array($rs)) {


		echo '<input type="checkbox" value="' . $row['source_id'] . '" name="markdelete[]">' . $row['source_name'] . '<br />' ;

}

 

The second form is a list of sources that are not associated with this subject, with checkboxes enabling the addition of more sources to this subject, like so:

 

$r = "SELECT source_id, source_name 
	FROM source 
	WHERE source_id NOT IN 
	(select s.source_id
	from source s, source_subject ss
	where s.source_id = ss.source_id
	and ss.subject_id = '$subject_id')";

$r1  = mysqli_query($dbc, $r)
	or die ('Update Error: '.mysqli_error($dbc));						


while ($row = mysqli_fetch_array($r1)) {
echo '<input type="checkbox" id="source_id" name="source_id[]" ' ;

echo 'value="'. $row['source_id'] .'"';


    echo '> ' . $row['source_name'] . '<br />'; 


}  

 

The first form works fine... when the "remove" submit button is clicked, it successfully removes any selected sources and then shows the remaining sources still associated, and then automatically populates this source in the below list (form 2) as one that is not selected.

 

On the second form, when adding a new source to the subject, it successfully enters the data into the database, and removes this source from the list of unselected sources, but it does not seem to re-populate in the first form.

 

The data is correct on the tables, but the page needs to reload the first query... how do I get it to do this?  I'd like to be able to make this page editable, and re-editable (in case someone makes a mistake) without having to go back and reload the entire page.

 

Note, both forms call the page itself; not sure if this is part of it.  Using this:

<form  method="POST" action="<?php echo $_SERVER['PHP_SELF'].'?subject_id='.$subject_id ;    ?>">  

 

Does anyone have any ideas?

 

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.