I want to use a php form textfield to change a value in my databas. I got this far by im keep getting this error, please help me figure out whats wrong.
PHP Code:
<?php
$server = "localhost";
$username = "admin";
$password = "admin";
$database = "local_db";
$con = mysql_connect($server, $username, $password);
$ok = mysql_select_db($database, $con);
$Cname = mysql_real_escape_string($_POST['newname']);
$sql = "UPDATE people SET name='{$Cname}' WHERE id=1";
mysql_query($sql) or die(mysql_error());
?>
<form method="post" action="">
<input name="newname" type="text" id="textfield"/>
<input type="submit" name="change" value="Change now" />
</form>
<?php
if(isset($_POST['change'])){
if(!preg_match("/^[A-Za-z]$/",$_POST['name'],$match)){
echo "Invalid characters, please try again";
}
if(preg_match("/^[A-Za-z]$/",$_POST['name'],$match)){
header('Location: http://localhost/sent.php');
}
}
?>
Notice: Undefined index: newname in this line,
PHP Code:
$Cname = mysql_real_escape_string($_POST['newname']);