HogDog Posted October 19, 2008 Share Posted October 19, 2008 Hello all, My php is giving me this error: Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/doc_update.php on line 39 What I'm trying to do is populate a drop-down menu with a list of products from a database, then the admin could select the product, then a type of file(documentation, firmware, software), then enter the directory of the file. this info would then be inserted in to a certain table in the same database. This is my php file: <?php session_start(); if(!isset($_SESSION['adminctrl'])){ header('Location: admin.php'); die('<a href="admin.php">Login first!</a>'); } elseif(!isset($_SESSION['production'])){ header('Location: production.php'); die('<a href="production.php">Login first!</a>'); } $query = mysql_connect("*********************", "****", "*******") or die(mysql_error()); mysql_select_db('*********', $query) or die(mysql_error()); $len = strlen($_POST['type']); $len = strlen($_POST['product']); $len = strlen($_POST['directory']); @mysql_query('INSERT INTO `product_docs_support` (type, product, directory) VALUES (\''.mysql_real_escape_string($_POST['type']).'\', \''.mysql_real_escape_string($_POST['product']).'\',\''.mysql_real_escape_string($_POST['directory']).'\')'); echo"Update was successful."; php?> <!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> <title>Customer Update</title> </head> <html> <body> <form method="post" action="customer_info.php"> <?php $query = mysql_connect("****************", "*****", "********") or die(mysql_error()); mysql_select_db('********', $query) or die(mysql_error()); $conn ="SELECT product_id FROM `product`" ; $result = mysql_query($conn,$query); while($row=mysql_fetch_row($result)) { $user[] = $row[0]; } echo "<selectname="product">\n"; foreach( $url as $y ) { echo "<option value="$y">\n" $y."<option/>\n"; } echo "</select>\n"; mysql_free_result($result); php?> <br /> <selectname="type"> <option value="doc">Documentation<option/> <option value="firmware">Firmware<option/> <option value="software">Software<option/> </select> directory: <input type="text" name="directory" /> <input type="submit" name="submit" value="Update" /> </form> </body> </html> I'm a newbie but I'm guessing its somewhere in here: $conn ="SELECT product_id FROM `product`" ; $result = mysql_query($conn,$query); while($row=mysql_fetch_row($result)) { $user[] = $row[0]; } echo "<selectname="product">\n"; foreach( $url as $y ) { echo "<option value="$y">\n" $y."<option/>\n"; } echo "</select>\n"; mysql_free_result($result); I'm guessing what I did to try and populate a drop-down menu won't work that way. thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/ Share on other sites More sharing options...
JasonLewis Posted October 19, 2008 Share Posted October 19, 2008 You have multiple errors, all of the same type. Look at your script, you do this a lot: echo "<option value="something">Something</option>"; Although it's not always with options, its with other stuff as well. You cannot open a string with double quotes the have double quotes inside the string because PHP thinks you are closing it off. You can solve it by escape the quotes: echo "<option value=\"something\">Something</option>"; Or you can use single quotes on the inside, or outside: echo "<option value='something'>Something</option>"; Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-668923 Share on other sites More sharing options...
philipolson Posted October 19, 2008 Share Posted October 19, 2008 Also, it's ?> and not php?> ... Also, 100% of the time a parse error is for invalid PHP syntax. Also, most of the time when PHP says an error is on a certain line the problem exists on the line before it (because it becomes a problem after)... anyway, so here PHP said line 39 and I reckon line 38 had the problem... the first one at least. Also, when posting a question, it's helpful to say which line is in the error... so in this case state which line is 39. Sorry I wrote "Also," so much here, I think it's getting late. Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-668984 Share on other sites More sharing options...
HogDog Posted October 19, 2008 Author Share Posted October 19, 2008 thanks a lot guys. Now I'm getting this error on line 38: Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in /home/doc_update.php on line 38 I've looked over my code but can't seem to find the problem. thanks for all your help. <?php session_start(); if(!isset($_SESSION['adminctrl'])){ header('Location: admin.php'); die('<a href="admin.php">Login first!</a>'); } $query = mysql_connect("**************", "******", "*************") or die(mysql_error()); mysql_select_db('*******', $query) or die(mysql_error()); $len = strlen($_POST['type']); $len = strlen($_POST['product']); $len = strlen($_POST['directory']); @mysql_query('INSERT INTO `product_docs_support` (type, product, directory) VALUES (\''.mysql_real_escape_string($_POST['type']).'\', \''.mysql_real_escape_string($_POST['product']).'\',\''.mysql_real_escape_string($_POST['directory']).'\')'); echo"Update was successful."; ?> <!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> <title>Customer Update</title> </head> <html> <body> <form method="post" action="customer_info.php"> <?php $query = mysql_connect("*****************", "***********", "**********") or die(mysql_error()); mysql_select_db('***********', $query) or die(mysql_error()); $conn ="SELECT product_id FROM `product`" ; $result = mysql_query($conn,$query); while($row=mysql_fetch_row($result)) { $user[] = $row[0]; } echo "<selectname='product'>\n"; foreach($url as $y){ echo "<option value='$y'>\n" $y."<option/>\n"; } echo "</select>\n"; mysql_free_result($result); ?> <br /> <selectname="type"> <option value="doc">Documentation<option/> <option value="firmware">Firmware<option/> <option value="software">Software<option/> </select> directory: <input type="text" name="directory" /> <input type="submit" name="submit" value="Update" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-669019 Share on other sites More sharing options...
JasonLewis Posted October 19, 2008 Share Posted October 19, 2008 Look at line 38, your not breaking out of the string properly. echo "<option value='$y'>\n" $y."<option/>\n"; Should be this: echo "<option value='$y'>\n".$y."</option>\n"; (I also fixed your HTML, you had <option/> not </option>) Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-669035 Share on other sites More sharing options...
HogDog Posted October 19, 2008 Author Share Posted October 19, 2008 thanks a ton, I can't believe missed that and the html. Thanks However I am presented now with these errors: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/doc_update.php on line 31 Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/doc_update.php on line 42 <?php session_start(); if(!isset($_SESSION['adminctrl'])){ header('Location: admin.php'); die('<a href="admin.php">Login first!</a>'); } $query = mysql_connect("***********", "********", "***********") or die(mysql_error()); mysql_select_db('********', $query) or die(mysql_error()); $len = strlen($_POST['type']); $len = strlen($_POST['product']); $len = strlen($_POST['directory']); @mysql_query('INSERT INTO `product_docs_support` (type, product, directory) VALUES (\''.mysql_real_escape_string($_POST['type']).'\', \''.mysql_real_escape_string($_POST['product']).'\',\''.mysql_real_escape_string($_POST['directory']).'\')'); echo"Update was successful."; ?> <!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> <title>Customer Update</title> </head> <html> <body> <form method="post" action="customer_info.php"> <?php $query = mysql_connect("************", "********", "*********") or die(mysql_error()); mysql_select_db('*********', $query) or die(mysql_error()); $conn ="SELECT product_id FROM `product`" ; $result = mysql_query($conn,$query); while($row=mysql_fetch_row($result)) { $user[] = $row[0]; } echo "<select name='product'>\n"; foreach($url as $y){ echo "<option value='$y'>\n" .$y."</option>\n"; } echo "</select>\n"; mysql_free_result($result); ?> <br /> <select name="type"> <option value="doc">Documentation</option> <option value="firmware">Firmware</option> <option value="software">Software</option> </select> <br/> directory: <input type="text" name="directory" /> <input type="submit" name="submit" value="Update" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-669064 Share on other sites More sharing options...
HogDog Posted October 19, 2008 Author Share Posted October 19, 2008 sorry for the double post. I changed my code around a little bit and emilinated two errors. Now I'm getting this message: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/J/a/p/JapII/html/reftek/doc_update.php on line 17 heres my code, thanks a ton. <?php session_start(); if(!isset($_SESSION['adminctrl'])){ header('Location: admin.php'); die('<a href="admin.php">Login first!</a>'); } $query = mysql_connect("***************", "************", "************") or die(mysql_error()); mysql_select_db('**********', $query) or die(mysql_error()); $len = strlen($_POST['type']); $len = strlen($_POST['product']); $len = strlen($_POST['directory']); @mysql_query('INSERT INTO `product_docs_support` (type, product, directory) VALUES (\''.mysql_real_escape_string($_POST['type']).'\', \''.mysql_real_escape_string($_POST['product']).'\',\''.mysql_real_escape_string($_POST['directory']).'\')'); echo"Update was successful."; $conn ="SELECT product_id FROM `product`" ; $result = mysql_query($conn,$query); while($row=mysql_fetch_assoc($result)) { $url[] = $row['product_id']; } ?> <!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> <title>Customer Update</title> </head> <html> <body> <form method="post" action="customer_info.php"> <br/> Product:<br/> <?php echo "<select name='product'>\n"; foreach($url as $y){ echo "<option value='$y'>\n" .$y."</option>\n"; } echo "</select>\n"; ?> <br /> <br/> File Type:<br/> <select name="type"> <option value="doc">Documentation</option> <option value="firmware">Firmware</option> <option value="software">Software</option> </select> <br/><br/> Directory:<br/> <input type="text" name="directory" /> <br/> <input type="submit" name="submit" value="Update" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-669605 Share on other sites More sharing options...
AndyB Posted October 20, 2008 Share Posted October 20, 2008 Trap errors while developing. Change: $result = mysql_query($conn,$query); to: $result = mysql_query($conn,$query) or die("Error: ". mysql_error(). " with query ". $conn; Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-669631 Share on other sites More sharing options...
HogDog Posted October 20, 2008 Author Share Posted October 20, 2008 okay just did that, now I get this: Parse error: parse error, unexpected ';' in /home/doc_update.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-669783 Share on other sites More sharing options...
philipolson Posted October 20, 2008 Share Posted October 20, 2008 Still you're making helping you difficult by not saying what line is what... like, what is line 15 and 16? Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-670098 Share on other sites More sharing options...
HogDog Posted October 20, 2008 Author Share Posted October 20, 2008 I don't know I'm guessing, line 16 :-\ Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-670352 Share on other sites More sharing options...
HogDog Posted October 20, 2008 Author Share Posted October 20, 2008 oops, I read your post incorrectly, philipolson, line 16 is: $result = mysql_query($conn,$query) or die("Error: ". mysql_error(). " with query ". $conn; -thanks Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-670394 Share on other sites More sharing options...
AndyB Posted October 20, 2008 Share Posted October 20, 2008 my fault. It should be $result = mysql_query($conn,$query) or die("Error: ". mysql_error(). " with query ". $conn); Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-670401 Share on other sites More sharing options...
HogDog Posted October 21, 2008 Author Share Posted October 21, 2008 okay thanks here whats displaying now. Error: Table 'raytech.product' doesn't exist with query SELECT product_id FROM `product` Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-670526 Share on other sites More sharing options...
pugboy Posted October 21, 2008 Share Posted October 21, 2008 The error means exactly what it says-- the table product does not exist in your Reytech database. That is why the product_id cannot be selected. Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-670546 Share on other sites More sharing options...
HogDog Posted October 21, 2008 Author Share Posted October 21, 2008 dang, typo in my database. Thanks a ton guys! Quote Link to comment https://forums.phpfreaks.com/topic/129036-parse-error-drop-down-menu/#findComment-670609 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.