0

I would like to do this, but I can't. I tried almost everything. Can I ask how can I update the username in the sql database?

I want if I write something to the username's place then I click to the button (and if it success the string will be just one 'world') so far I could do it. My problem is when success, I want to the cnc.php update the data to the sql server) I hope you can understand what I mean/want.

<form name="form1" method="post" action="inc/processings/cnc.php">
     <p id="be">Change username</p>
     <input name="username" placeholder="Your new name" type="text" id="cn">
     <input type="button" id="change" onclick="return renformhash (this.form, this.form.username);" value="Change">
</form>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Haroshow
  • 5
  • 3

1 Answers1

0

If you would provide some PHP and JQuery code that would be very helpful.

However, judging from what I think I understand of your question to update the username in your sql database you would simply set a variable to the new username and then write an sql statement to place that variable inside.

//Updates users username
$query = "UPDATE membertable SET username='$username' WHERE name='$name'";
$result=mysql_query($query,$DBConnect);

Hopefully that clarifies some of the confusion.

user5166162
  • 156
  • 2
  • 11
  • 1
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 04 '15 at 21:30
  • [Your script is at risk for SQL Injection Attacks.](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) – Jay Blanchard Sep 04 '15 at 21:30