What's the exact error message? The parens look wrong to me, but I can't tell you for sure.
What's the exact error message? The parens look wrong to me, but I can't tell you for sure.
MY FORM:
add2.php:PHP Code:<!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>database first try</title>
</head>
<body>
<form method="post" action="add2.php">
<table>
<tr>
<td>link url:</td>
<td><input name="link_url" type="text" /></td>
</tr>
<tr>
<td>link name:</td>
<td><input name="link_name" type="text" /></td>
</tr>
<tr>
<td>choose:</td>
<td>
<select name="selectgrade">
<option value="option_a">A</option>
<option value="option_b">B</option>
<option value="option_c">C</option>
<option value="option_d">D</option>
</select>
</td>
</tr>
</table>
<input type="submit" value="sumbit" />
</form>
</body>
</html>
What I've tried to do is to get the selected value and insert it into a database.PHP Code:<!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>database first try</title>
</head>
<body>
<?php
$connection = mysql_connect("localhost",
"XXX",
"XXX");
if (!$connection)
die('Could not connect: ' . mysql_error());
mysql_select_db("XXX", $connection);
$sql="INSERT INTO links (link_url, link_name, selectgrade)
VALUES
('$_POST[link_url]','$_POST[link_name]','$_POST['selectgrade']')";
if (!mysql_query($sql,$connection))
die('Error: ' . mysql_error());
echo "1 record added";
mysql_close($connection);
?>
</body>
</html>
Thank you for posting the entire source, but what's the error message?
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
The code you originally said was causing the problem wasBut if that line became thisCode:$sql="INSERT INTO grades (selectgrade) VALUES ('$_POST['selectgrade']')";then change it to thisCode:$sql="INSERT INTO links (link_url, link_name, selectgrade) VALUES ('$_POST[link_url]','$_POST[link_name]','$_POST['selectgrade']')";See the second code-section at http://www.php.net/manual/en/languag...string.parsing.Code:$sql="INSERT INTO links (link_url, link_name, selectgrade) VALUES ('{$_POST['link_url']}','{$_POST['link_name']}','{$_POST['selectgrade']}')";
Hi thank you,
now there are no errors, but still it doesn't insert it in the right way. All the values from the select menu turned into 0 in the database.
Try this anywhere in that script and report the output:Code:var_dump(isset($_POST['selectgrade'])); var_dump($_POST['selectgrade']);
lord22 (08-07-2008)
I think it might have something to do with your single quotes. Here is the way it would be saved.
Try this:Code:$sql="INSERT INTO grades (selectgrade) VALUES ('$_POST['selectgrade']')";
Also as to the problem with changing to 0, make sure that the field in the DB is set to text/varchar and not int.Code:$grade = $_POST['selectgrade']; $sql="INSERT INTO grades (selectgrade) VALUES ('{$grade}')";
lord22 (08-07-2008)
Thank you very much!!
Now it is working![]()
Bookmarks