QuuDomi Posted January 9, 2012 Share Posted January 9, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/ Share on other sites More sharing options...
fenway Posted January 9, 2012 Share Posted January 9, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305902 Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 fourthly, I get that line you marked as being line 29, with the whole script closing on line 36... is that the entyre script exactly as it apears in your php file? Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305903 Share on other sites More sharing options...
QuuDomi Posted January 9, 2012 Author Share Posted January 9, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305908 Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 could you copy and paste your exact page code as it is in your .php file please (html as well)? Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305910 Share on other sites More sharing options...
QuuDomi Posted January 9, 2012 Author Share Posted January 9, 2012 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> Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305913 Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 try changing your query line to this for now: $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')"; Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305917 Share on other sites More sharing options...
QuuDomi Posted January 9, 2012 Author Share Posted January 9, 2012 Thanks for your replies, I updated update.php and ran it, I received the same error on the same line. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305920 Share on other sites More sharing options...
mikosiko Posted January 9, 2012 Share Posted January 9, 2012 mysql_query($query) or die ('Error registering'); echo " Successful!" something is missing in the last line Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305921 Share on other sites More sharing options...
QuuDomi Posted January 9, 2012 Author Share Posted January 9, 2012 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 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? Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305923 Share on other sites More sharing options...
fenway Posted January 9, 2012 Share Posted January 9, 2012 Also, it won't work at all, since you're single-quoting your column name. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305933 Share on other sites More sharing options...
QuuDomi Posted January 9, 2012 Author Share Posted January 9, 2012 Also, it won't work at all, since you're single-quoting your column name. You mean in the POST function not the query right? Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305936 Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 No, he meens the fact that you have your field list in the INSERT query built using single quotes. I didn't even notice and thought they were backticks. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305946 Share on other sites More sharing options...
QuuDomi Posted January 9, 2012 Author Share Posted January 9, 2012 No, he meens the fact that you have your field list in the INSERT query built using single quotes. I didn't even notice and thought they were backticks. I was trying to use this post as a reference. http://www.phpfreaks.com/forums/index.php?topic=221372.0 Okay, will change the single quotes. Thansk Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305949 Share on other sites More sharing options...
QuuDomi Posted January 9, 2012 Author Share Posted January 9, 2012 Should I just repost this in the PHP forum since I am apparently in the wrong thread to begin with? Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305950 Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 nah, fanway woulda moved it if he thought it would be better. Truth is most of the people here look up both forums anyways. Let me look closer at the code and see what I can come up with. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305955 Share on other sites More sharing options...
Muddy_Funster Posted January 9, 2012 Share Posted January 9, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305958 Share on other sites More sharing options...
QuuDomi Posted January 10, 2012 Author Share Posted January 10, 2012 Seems to work but I get a bit noisy output: Successful!Array ( [fname] => PeronsName [lname] => HisLastName [phone] => 321-321-3214 [Company] => Company, Inc. => iono@iono.com [field] => CEST ) Array ( [sPM] => 0 [PM] => 0 [CEST] => 1 [EST] => 0 [PE] => 0 [sI] => 0 [OTH] => 0 ) 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. Because I'm a n00b lol... If there is something I could read I don't mind reading, just theres so much info it's hard to know where to start. I have just been following some tutorials I found. But they have all been from different sources. Let me know what you think I should do differently if you feel up to it. So I can look further into it on my own. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1305965 Share on other sites More sharing options...
Muddy_Funster Posted January 10, 2012 Share Posted January 10, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1306022 Share on other sites More sharing options...
fenway Posted January 10, 2012 Share Posted January 10, 2012 Now that we're debugging php output, perhaps this isn't the best board any longer? Quote Link to comment https://forums.phpfreaks.com/topic/254674-inserting-radio-buttons-data/#findComment-1306226 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.