Jump to content

Updating table


jesj

Recommended Posts

Ok, Basically this is what im aiming for. The user is brought to a page where they see a form, the form consist of a field called username and *HIDDEN* field called active with the values "yes". On the table the columns are (username, active) username being w/e they registered for and active with the values "no". So on the form they fill out there username and hit submit, once they hit submit the hidden field active with the values "yes" updates the table active from "no" to "yes" with out them knowing. I want this to work for w/e user enters there username. So i dont want to update the whole column/or row. Sorry if you can't understand me ill try to explain it better if I have to.

Link to comment
Share on other sites

Well I don't think you even need the hidden field, you could just have "yes" hardcoded into the script, but if you want to use it you'll need a form looking like this on your HTML page:

 

<form action="yourphppage.php" method="post">
<input type="hidden" name="active" value="yes" />
<input type="text" name="username" value="" />
<input type="submit" name="submit" value="Activate!" />
</form>

 

And yourphppage.php:

<?php
$active = $_POST['active'] == 'yes' ? 'yes' : 'no';
$username = $_POST['username'];
$query = "UPDATE `tablename` SET `active`='" . $active . "' WHERE `username`='" . $username . "'";
$result = mysql_query($query) or die(mysql_error());
?>

 

Please be aware that the code I just wrote is highly vulnerable to SQL injection.  You'll need to run whatever you feel is necessary (usually a mysql_real_escape_string and some HTML removal technique is good enough) to remove that vulnerability.

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.