Hi,
I'm learning PHP. I was trying to update SQL Database through PHP form.
PHP Code:
<?php
/* Opens Connection to mysql server */
$dbc = mysql_connect('localhost', 'root', 'admin');
if (!$dbc){
die ("Not Connected : " . mysql_error());
}
/* Selecting a database */
$db_selected = mysql_select_db ("local", $dbc);
if (!$db_selected) {
die ("Cant Connect :" . mysql_error());
}
/* Updating Data in table */
$new_username = $_POST["name"];
$query="UPDATE profile SET username='$new_username' WHERE id='1'";
$result=mysql_query($query);
echo '<form method="post" action="'.$SERVER['PHP_SELF'];'">';
echo '<input type="text" name="name" value="" />';
echo '<input type="submit" value="Update" /></form>';
?>
Also what is the use of $Server. I guess it is for same page submission...
Teach me PHP 
__________________
"Think 100 times before you take a decision, But once that decision is taken, stand by it as one man." - Quaid-e-Azam
|