Jump to content

Inserting Radio Buttons Data


QuuDomi

Recommended Posts

I'm still just learning how to use PHP and MySQL. I created a table with 12 fields. Simply I need a form which I have created already to be able to take contact information. There are also several radio buttons that specify the job role the person is. I was able to get everything to work until I started to add radio buttons and modifying code. I obviously screwed something up.

 

 

MySQL - 5.0.91

 

  <?php
$fields ['SPM'] = false;
$fields ['PM'] = false;
$fields ['CEST'] = false;
$fields ['EST'] = false;
$fields ['PE'] = false;
$fields ['SI'] = false;
$fields ['OTH'] = false;
$fields[$_POST['field']] = true;

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$Company = $_POST['Company'];
$Email = $_POST['Email'];
$SPM = $_POST['SPM'];
$PM = $_POST['PM'];
$CEST = $_POST['CEST'];
$EST = $_POST['EST'];
$PE = $_POST['PE'];
$SI = $_POST['SI'];
$OTH = $_POST['OTH'];



mysql_connect ('server.mysql.com', 'username', '**********') or die ('Error: ' . mysql_error());
mysql_select_db ("databasename");

//Line 38:
$query="INSERT INTO ContactList ('ID', 'fname', 'lname', 'phone', 'Company', 'Email', 'SPM', 'PM', 'CEST', 'EST', 'PE', 'SI', 'OTH') VALUES ('NULL','".$fname."', '".$lname."', '".$phone."', '".$Company."', '".$Email."', '".$SPM."', '".$PM."', '".$CEST."', '".$EST."', '".$PE."', '".$SI."', '".$OTH."')";


mysql_query($query) or die ('Error registering');
echo " You have successfully registered!"

?>

 

Error:

Parse error: syntax error, unexpected T_VARIABLE: line 38 The above is the line of code it is referencing.

 

 

I've tried searching for answers but since I have so limited knowledge, I am not sure which info applies to me. For example some tutorials have written code with much less ""s and brackets. Some don't even have the .s where I have them, therefore I am finding it difficult to tell what I am doing wrong.

 

Please help thank you.

 

PS: I updated the code, I mistyped something. The error.

 

 

 

Link to comment
Share on other sites

First, that's a PHP error.

 

Second, you have quoting problems.

 

Third, you wouldn't have this problem if you used a proper function to create your SQL statements.

 

1) Sorry I wasn't sure to place it in PHP or MySQL

2) Right

3) Not sure what you are referring to. Perhaps a link to what you are talking about would be useful to me...?

4) Sorry yes. I removed some HTML I had in my Dreamweaver. Thats the entire PHP code.

Link to comment
Share on other sites

could you copy and paste your exact page code as it is in your .php file please (html as well)?

 

This may be more helpful, my form 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>form</title>
</head>

<body>

<form method="post" action="update.php">

First Name: <br />

<input type="text" name="fname" size="35" /><br />

Last Name: <br />

<input type="text" name="lname" size="35" /><br />

Phone Number: <br />

<input type="text" name="phone" size="12"  /><br />
Company:<br />
<input type="text" name="Company" size="30" /><br />
Email:<br />
<input type="text" name="Email" size="30" /> <br />

<input type="radio" name="field" value="SPM" />Sr. Project Manager<br />
<input type="radio" name="field" value="PM" />Project Manager<br />
<input type="radio" name="field" value="CEST" />Chief Estimator<br />
<input type="radio" name="field" value="EST" />Estimator<br />
<input type="radio" name="field" value="PE" />Project Engineer<br />
<input type="radio" name="field" value="SI" />Superintendent<br />
<input type="radio" name="field" value="OTH" />Other<br />

<input type="submit" value="Submit" />


</form>


</body>
</html>

 

<!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>Test Document</title>
</head>

<body>
<p>
  <?php
$fields ['SPM'] = false;
$fields ['PM'] = false;
$fields ['CEST'] = false;
$fields ['EST'] = false;
$fields ['PE'] = false;
$fields ['SI'] = false;
$fields ['OTH'] = false;
$fields[$_POST['field']] = true;

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$Company = $_POST['Company'];
$Email = $_POST['Email'];
$SPM = $_POST['SPM'];
$PM = $_POST['PM'];
$CEST = $_POST['CEST'];
$EST = $_POST['EST'];
$PE = $_POST['PE'];
$SI = $_POST['SI'];
$OTH = $_POST['OTH'];



mysql_connect ('server.mysql.com', 'user', '********') or die ('Error: ' . mysql_error());
mysql_select_db ("database");

$query="INSERT INTO ContactList ('ID', 'fname', 'lname', 'phone', 'Company', 'Email', 'SPM', 'PM', 'CEST', 'EST', 'PE', 'SI', 'OTH') VALUES ('NULL','".$fname."', '".$lname."', '".$phone."', '".$Company."', '".$Email."', '".$SPM."', '".$PM."', '".$CEST."', '".$EST."', '".$PE."', '".$SI."', '".$OTH."')";


mysql_query($query) or die ('Error registering');
echo " Successful!"

?>
  
</p>
<p><a href="query.php">Back to Query</a></p>
</body>
</html>

Link to comment
Share on other sites

mysql_query($query) or die ('Error registering');
echo " Successful!"

 

something is missing in the last line

 

semi colon? That is part of my original code that worked okay before I inserted the radio button code  :confused:

 

Well I added a semi colon and the original error when away XD and was replaced with this:

 

"Error registering" Which is the query error return in my update.php. So I am assuming since no one said anything about my radio button code, its okay other than my quote issues?

Link to comment
Share on other sites

ok, this is still kinda messy, but I think it should at least work this time:

<!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>Test Document</title>
</head>

<body>
<p>
  <?php
$fields = array('SPM'=> 0, 'PM' => 0, 'CEST'=> 0, 'EST'=> 0, 'PE'=> 0, 'SI'=> 0, 'OTH'=> 0);

$fields[$_POST['field']] = 1;

$fname = $_POST['fname'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$Company = $_POST['Company'];
$Email = $_POST['Email'];
$SPM = $fields['SPM'];
$PM = $fields['PM'];
$CEST = $fields['CEST'];
$EST = $fields['EST'];
$PE = $fields['PE'];
$SI = $fields['SI'];
$OTH = $fields['OTH'];


mysql_connect ('server.mysql.com', 'user', '********') or die ('Error: ' . mysql_error());
mysql_select_db ("database");

$query="INSERT INTO ContactList (fname, lname, phone, Company, Email, SPM, PM, CEST, EST, PE, SI, OTH) VALUES ('$fname', '$lname', '$phone', '$Company', '$Email', '$SPM', '$PM', '$CEST', '$EST', '$PE', '$SI', '$OTH')";


mysql_query($query) or die ('Error registering');
echo " Successful!";


print_r($_POST);
echo "<br><br>";
print_r($fields);
?>
  
</p>
<p><a href="query.php">Back to Query</a></p>
</body>
</html>

 

I'm not sure why you have designed it this way, but that's for another thread ;)  Let me know how you get on with this.

Link to comment
Share on other sites

Noisy output is my fault - I left the following lines of code in from when I was debuging it (because I didn't have time to set up a DB as well):

print_r($_POST);
echo "<br><br>";
print_r($fields);

 

remove them and it should be fine. 

 

First thing I would suggest is seriously spend time designing your project.  I know from experience it's all to easy to fling together some tables and start to code as soon as the concept is rounded off.  I also know from the same experiance that it's a proper headache if that impulse is not resisted.  Your table structure seems off to me, looking at the limited information available and having no idea of the context, it seems to me that you would have been better served having a single "postionHeld" column rather than a bool column for every possibility individualy.

 

As I said though, this is mainly for another thread, you can also PM me if you want to ask anything directly, although opeing a thread will generaly get more (and better!) input.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.