[PHP/MySQL] Update mysql row

Newbie Spellweaver
Joined
Aug 20, 2008
Messages
38
Reaction score
1
Heyy

Ive Just Found A Code , Which Updates php Tables Threw A html Form , i Wont this Code to Edit A Users
username And Password

But I Dont No Where I Should Input The Table Details . Here Is the PHP Code .

PHP:
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("mydatabase", $con);

mysql_query(" UPDATE stuff SET Amount = ('$_POST[amount]')
WHERE Item = ('$_POST[item]') ");
mysql_close($con);
?>

My Database = test
My Section = member


And The Tables For the Username And Password Are

username And Password .

Sorry im a Noob :thumbdown: Lol

Thanks - Pringle
 
PHP:
<?php
$con = mysql_connect("localhost","root","//your_mysql_pass_here");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("test'", $con);

mysql_query(" UPDATE stuff SET Amount = ('$_POST[amount]')
WHERE Item = ('$_POST[item]') ");
mysql_close($con);
?>
 
Try this.

PHP:
<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("test", $con);

mysql_query(" UPDATE member SET Amount = ('$_POST[amount]')
WHERE Item = ('$_POST[item]') ");
mysql_close($con);
?>
 
PHP:
<?php
$db = mysql_connect('localhost','username','Password') or die("Could not connect.");
if(!$db) 
    die('no db');
if(!mysql_select_db('test',$db))
     die("No database selected.");

mysql_query('UPDATE `member` SET `Amount` = "'.$_POST['amount'].'"
WHERE `Item` = "'.$_POST['item'].'" ';
mysql_close($db);
?>
or,
mysql_connect('host','user','pass')
 
above, not..what..he...asked?
Code:
<?php
$db = mysql_connect('localhost','username','Password') or die("Could not connect.");
if(!$db) 
    die('no db');
if(!mysql_select_db('test',$db))
     die("No database selected.");

mysql_query('UPDATE `member` SET `username` = "'.$_POST['username'].'"
AND `password` = "'.$_POST['pass'].'" WHERE id = '$id'';
mysql_close($db);
?>

get a way to declare $id.
 
If this is available to the public, make sure you prevent SQL injections by using mysql_real_escape_string()

example:
PHP:
mysql_real_escape_string($_POST[amount]');
 
Last edited:
Back