Forum Moderators: coopster
---- START OF CODE ------------
<html>
<head><title>Enter your user information</title><head>
<body>
<?
// Set a variable with the database name
$database_name = "mydb";
// Attempt to connect to database and store result
$dbh = mysql_connect("localhost","root");
// Check the result of the connection attempt
if (!mysql_select_db($database_name)) {
echo "Can't Select $database_name";
}
// Conditional test to see if submit button was pressed
if (isset ($enter_data)) {
// Build our query string
$sql = “insert into employees (first,last,address) values (‘$first’, ‘$last’, ‘$address’)”;
// Execute a query and store the result
$res = mysql_query($sql,$dbh);
// Check to make sure the query actually ran
if (!$res) {
echo mysql_errno().": ". mysql_error ()."";
return 0;
}
printf(”<p>Record successfully added</p>”);
}
?>
<h2>A listing of all current users</h2>
<table>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
</tr>
<?
// Execute a query and store the result
$res = mysql_query("SELECT * from employees",$dbh);
// Check to make sure the query actually ran
if (!$res) {
echo mysql_errno().": ". mysql_error ()."";
return 0;
}
// Use the query results
while ($thearray = mysql_fetch_array($res)) {
printf("<tr><td>$thearray[id]</td><td>$thearray[first]
</td><td>$thearray[last]</td><td>$thearray[address]
</td></tr>");
}
?>
</table>
<form name=”user_info” method=”post” action=”<? $_SERVER['PHP_SELF']?>”>
First Name: <input type=”text” name=”first”>
Last Name: <input type=”text” name=”last”>
Email address: <input type=”text” name=”address”>
<input type=”submit” name=”enter_data” value=”Enter Data”>
</form>
</body>
</html>
------------- END OF CODE --------------
When I load the php page I get the following error:
Parse error: parse error, unexpected T_STRING in C:\Program Files\Apache Group\Apache\htdocs\mysql6.php on line 16
Line 16 is the insert statement. I checked it in the database and table employees with columns first, last, and address exist. Line 16 in the code is:
$sql = “insert into employees (first,last,address) values (‘$first’, ‘$last’, ‘$address’)”;
Please help me out with this.
Thanks
Mario
[edited by: jatar_k at 1:59 am (utc) on Oct. 26, 2002]
[edit reason] no sigs please [/edit]
I don't know about MySQL, but a quick test shows that Postgres likes '`' as little as I expected, which is to say not at all.