Forum Moderators: coopster

Message Too Old, No Replies

MYSQL help!

         

tcdearling

8:27 pm on Nov 12, 2005 (gmt 0)

10+ Year Member



I want it so that I can change a field in my database, from a webpage, made in php. All that I want is for a text box and a button that allows me to insert a name into the textbox and it changes the data in that field.

I need desperate help!

eelixduppy

8:40 pm on Nov 12, 2005 (gmt 0)



the MySQL query you have to use is:
UPDATE tablename SET columnname = 'something' WHERE columnname LIKE 'something';

now to incorporate this into a php site goes something like this:

$query = "UPDATE tablename SET columnname = 'something' WHERE columnname LIKE 'something'";
$db = "database name";
$link= mysql_connect("localhost", "yourID@localhost", "password") or die("Could not connect! Error: " . mysql_error());
mysql_select_db($db, $link) or die("Could not open database invetory! Error: " . mysql_error());
$result = mysql_query($query, $link) or die("Query error! Error: " . mysql_error());
mysql_close($link);

There you go...reply if you have any trouble!

tcdearling

9:46 pm on Nov 12, 2005 (gmt 0)

10+ Year Member



I wanted it so you add a textbox into the script (intergrate it) and when i put in eg. name, it changes another field in the database.

Get me?

scott182

10:22 pm on Nov 12, 2005 (gmt 0)

10+ Year Member



Is this something like what you want? This is PHP code you'd need for the web page, web_page.php, simply a text input box (you may need to add appropriate HTML):

<?
<form method='post' action='update_name.php'>
Name: <input type='text' size=10 name='name_field' />
</form>
?>

################################################

This would be the file update_name.php, which updates the database. Note that upon execution, this will present you with update_name.php in the browser; it should show up as just a blank page. You can certainly redirect to another page, or present links on this page -- just add some HTML or some echo " HTML code here... "; statements.

<?
# get variables from form -- you would refer to the variable 'name_field' as $vars['name_field']
while(list($key, $value) = each($_POST)){
$vars[$key] = $value;
}

$query = "UPDATE tablename SET columnname = '$vars[name_field]' WHERE columnname LIKE 'something'";
$db = "database name";
$link= mysql_connect("localhost", "yourID@localhost", "password") or die("Could not connect! Error: " . mysql_error());
mysql_select_db($db, $link) or die("Could not open database invetory! Error: " . mysql_error());
$result = mysql_query($query, $link) or die("Query error! Error: " . mysql_error());
mysql_close($link);
?>

tcdearling

10:16 pm on Nov 13, 2005 (gmt 0)

10+ Year Member



Thanks for your help, it has solved all my problems