Jump to content

Submit Button - Execute a Query


Mko

Recommended Posts

I have this piece of code:

	if (isset($_POST['type1'])) {
			mysql_query("UPDATE tabke SET status = 1 WHERE id = $rid", $c2) or die(mysql_error());
		}
	if (isset($_POST['type2'])) {
			mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error());
		}
	if (isset($_POST['type3'])) {
			mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error());
		}
?>
<br />
<form method="post" action="">
	<input type="hidden" name="pageid" value="plyrmgmt">
	<input type="hidden" name="action" value="changeBan">
	<input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
	<input type="hidden" name="repid" value="<?php echo $rid; ?>">
	<input type="submit" name="type1" value="Choice1" onClick="this.form.submit()">
</form>
<form method="post" action="">
	<input type="hidden" name="pageid" value="plyrmgmt">
	<input type="hidden" name="action" value="changeMute">
	<input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
	<input type="hidden" name="repid" value="<?php echo $rid; ?>">
	<input type="submit" name="type2" value="Choice2" onClick="this.form.submit()">
</form>
<form method="post" action="">
	<input type="hidden" name="pageid" value="plyrmgmt">
	<input type="hidden" name="action" value="changeLock">
	<input type="hidden" name="uid" value="<?php echo $hr_uid; ?>">
	<input type="hidden" name="repid" value="<?php echo $rid; ?>">
	<input type="submit" name="type3" value="Choice3" onClick="this.form.submit()">
</form>

 

Now, for some reason when I click on Choice1, the query doesn't execute.

Also, when I click on Choice2 or Choice3, the URL in my browser doesn't change for some odd reason...it stays the same as it was prior to clicking the Submit Button.

 

Can anyone point out some errors I have?

 

Thanks,

Mark.

Link to comment
Share on other sites

When you have an empty action in a form, ie:

<form method="post" action="">

 

it is a self serving form so the url would not change unless you made the method "GET" instead of post. "GET" puts the variables into your URL. However if you are using these forms for MySQL queries, putting the queries in the URL leaves the application open for SQL injections which can be malicious.

Use echo, print, or print_r is using arrays to make sure the data being entered is what you want to be used in the database query.

for example i might do this for your code:

if (isset($_POST['type1'])) {
                                echo "This was type1:" . $_POST['type1'];
			echo "UPDATE table SET status = 1 WHERE id = $rid"; //this will print just the database query to make sure $rid is what you want it to be
                               //mysql_query("UPDATE tabke SET status = 1 WHERE id = $rid", $c2) or die(mysql_error());
		}
	if (isset($_POST['type2'])) {
                                echo "This was type1:" . $_POST['type2'];
			echo "UPDATE table SET status = 1 WHERE id = $rid"; //this will print just the database query to make sure $rid is what you want it to be
                               //mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error());
		}
	if (isset($_POST['type3'])) {
                                echo "This was type1:" . $_POST['type3'];
			echo "UPDATE table SET status = 1 WHERE id = $rid"; //this will print just the database query to make sure $rid is what you want it to be
                               //mysql_query("UPDATE table SET status = 1 WHERE id = $rid", $c2) or die(mysql_error());
		}
?>

 

your code that we have is slightly uncomplete to know exactly what you are doing, we dont know where $rid is coming from. Also you said the URL doesnt change but how your forms are set up, your URL shouldnt change UNLESS your function call within the onclick "this.form.submit()" is suppose to alter the URL when hitting submit on any of the three forms.

 

algidDes523

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.