01-24-2008, 08:06 AM
|
#1 (permalink)
|
|
The Contributor
Join Date: Dec 2007
Location: Durban, South Africa
Posts: 51
Thanks: 1
|
Variables not writing to db
Hey guys... I've finally been able to get some time to play around with php a bit. I've hit a bit of a blank wall though, and was hoping someone could point out my obvious blunder. Taking into consideration the code below (I'm building it in stages, so it's not secure yet with regards to mysqli_real_escape_string), I am not able to write the variable value into the database. I've tried a few variations of the code, but still nothing. If I change the variable value to a normal string value, it inserts it without a prob. The code gives no errors either, so I'm a little confused
PHP Code:
<?php
if ($_POST["submit"]) {
$hostname = "localhost";
$username = "david";
$password = "test";
$dbname = "test";
$insertSQL = sprintf("INSERT INTO david_test (david_name) VALUES (%s)", $_POST['Fname']);
$dbh = mysqli_connect($hostname,$username,$password,$dbname) or die("Problem connecting: ".mysqli_error());
$result = mysqli_query($dbh, $insertSQL);
mysqli_close($dbh);}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="<?php echo $PHP_SELF;?>">
First Name:<input type="text" size="12" maxlength="12"
name="Fname"><br />
Last Name:<input type="text" size="12" maxlength="36"
name="Lname"><br />
<input type="submit" value="submit" name="submit">
</form>
</body>
</html>
|
|
|
|