MySQL DB insertion problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jsp_1983
Forum Newbie
Posts: 1
Joined: Sat Apr 03, 2004 11:42 am

MySQL DB insertion problem

Post by jsp_1983 »

Hello folks,

Can anybody help me with the following problem? I'm trying to create a simple page that will connect to my MySQL DB and update the contents using the script below. For some reason though, the content doesn't seem to update the DB tables- it just refreshes the page. Any ideas? Much appreciated if there are- it's getting a bit frustrating!

J


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="db_update_msw.php" method="post">
Mesh:
<input type="text" name="Mesh"><br>
Gauge:
<input type="text" name="Gauge"><br>
Diameter (mm):
<input type="text" name="Diameter"><br>
Aperture:
<input type="text" name="Aperture"><br>
Free Area (%):
<input type="text" name="Free_Area"><br>
<br>
<input type="Submit">
</form>
<?
$username="xxxxx";
$password="xxxxxx";
$database="xxxxxx";

mysql_connect('xxxxxxxxx',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO 'Mild Steel Wire' VALUES ('','$Mesh','$Gauge','$Diameter','$Aperture','$Free_Area')";
mysql_query($query);

mysql_close();
?>

</body>
</html>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Unless you have register_globals On (and it's Off by default since PHP 4.2.0) then you'll need to use :

$query = "INSERT INTO 'Mild Steel Wire' VALUES ('','{$_POST['Mesh']}','{$_POST['Gauge']}','{$_POST['Diameter']}','{$_POST['Aperture']}','{$_POST['Free_Area']}')";

See http://php.net/variables.predefined for more info.
Post Reply