Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Ok, I've been to a ton of different forums and can't get a straight answer on my seemingly simple problem. I am a total n00b with PHP and MySQL so please excuse my ignorance. I want to be able to have a form (which I already have) dump the submitted info into a MySQL db. I was able to create the table in the DB; but I can't get any info into it.
Here is the code I'm using now:
form:
[syntax="html"]
<form method="post" action="answer.php" />
First Name Last Name<br>
<input type="text" name="fname" /><input type="text" name="lname" /><br/><br>
City State<br>
<input type="text" name="city" /><select name="state" />
<option>Alabama</option>
<option>Wyoming</option>
</select><br/><br>
E-mail Address<br>
<input type="text" name="email" /><br/><br>
Answer: <input type="radio" name="answer" value="A" /> A<input type="radio" name="answer" value="B" /> B<input type="radio" name="answer" value="C" /> C<input type="radio" name="answer" value="D" /> D<br/>
<input type="checkbox" name="remember" value="1" />Remember Me<br/><br/>
<input type="submit" name="submit" value="Submit" />
</form>
Code: Select all
<?php
$handle = mysql_connect('dbserver.com', 'dbname','password');
echo ($handle) ? "Connected to MySQL.\r\n" : "Could not connect to MySQL.\r\n";
mysql_select_db('test1002') or die('Cannot select database');
$error = false;
if(isset($_POST['submit'])); {
$form = array();
$form['fname'] = $_POST['fname'];
$form['lname'] = $_POST['lname'];
$form['email'] = $_POST['email'];
$form['city'] = $_POST['city'];
$form['state'] = $_POST['state'];
$answer = $_POST['answer'];
if(!ini_get('magic_quotes_gpc')); {
foreach($form as $key => $value); {
$form[$key] = mysql_escape_string($value);
}
}
$query = "INSERT INTO centries (fname,lname,email,city,state,answer) VALUES ('{$form['fname']}', '{$form['lname']}', '{$form['email']}', '{$form['city']}','{$form['state']}', '{$form['answer']}',)";
$result = $database->query($query);
?>Parse error: parse error, unexpected $ in xxx/xxx/xxx/xxx/answer.php on line 33
Any help is much appreciated.
Thanks in advance,
jawinn
twigletmac | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]