jesj Posted May 4, 2008 Share Posted May 4, 2008 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 More sharing options...
Bauer418 Posted May 4, 2008 Share Posted May 4, 2008 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 More sharing options...
jesj Posted May 4, 2008 Author Share Posted May 4, 2008 no i get the "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)" sorry im a newbie on this ??? Link to comment https://forums.phpfreaks.com/topic/104109-updating-table/#findComment-533017 Share on other sites More sharing options...
ohdang888 Posted May 4, 2008 Share Posted May 4, 2008 did you connect to your database first? if so, its probably a host problem.... unless your connect code is screwed up Link to comment https://forums.phpfreaks.com/topic/104109-updating-table/#findComment-533089 Share on other sites More sharing options...
psychowolvesbane Posted May 5, 2008 Share Posted May 5, 2008 If you have a connection script when you come to use the mysql_query() function you need to do this mysql_query($query,$conn); Link to comment https://forums.phpfreaks.com/topic/104109-updating-table/#findComment-533130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.