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
https://forums.phpfreaks.com/topic/104109-updating-table/
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
https://forums.phpfreaks.com/topic/104109-updating-table/#findComment-533004
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.