Jump to content

Parse error, drop-down menu


HogDog

Recommended Posts

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.

 

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

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.