I'm having this error on the area below. When I comment it out it stops giving me the error and I have tried commenting it out piece by piece to see if there is something wrong but I get nothing. I'm sure I am missing something really easy.

while (row= mysql_fetch_row($result)) {
                  print '<form';
                  print '<select name = "students">;
                  foreach ($row as $field) {
                       print '<option value="$field>$field</option>;
                  }
                  print '</select>';
                  print '</form>;
                  }

That usually means a syntax error of some sort.

Isn't the format for the print 'function':

print ( a string );

(Note the brackets).

And you've not got a paired ' in the last one.

And there's one in the middle with only one " in it which will need to be escaped using \" if you want it in a string as such.

And one of your <forms> bits has a > missing.

It doesn't look like it will work as it is.

I apologize I kinda typed the code poorly in putting it up and did a few errors there. However one of the errors was actually in it so thanks for the quick response. I'm not getting that error anymore but now I am getting 4 drop down boxes instead of one but I'll work at that for a while. Fix one problem you get 5 new ones I guess. Thanks again for the help.

Someone will correct me on this if I'm wrong, but if the output for this is to go to the screen (I didn't think about what it was supposed to do until later) you'd be better using echo instead of print.

I know I always do.

It is discussed here:

http://www.faqts.com/knowledge_base/view.phtml/aid/1/fid/40

I see no compelling reason to use one above the other UNLESS I need the return code from print... which is always one.

if (print ("Never False"))
  {
  echo "Look at me!";
  }
else
  {
  echo "Thanks for noticing me.";
  }
Member Avatar for Rhyan

I'm having this error on the area below. When I comment it out it stops giving me the error and I have tried commenting it out piece by piece to see if there is something wrong but I get nothing. I'm sure I am missing something really easy.

while (row= mysql_fetch_row($result)) {
                  print '<form';
                  print '<select name = "students">;
                  foreach ($row as $field) {
                       print '<option value="$field>$field</option>;
                  }
                  print '</select>';
                  print '</form>;
                  }

Hey there.

In my opinion in your case you should use mysql_fetch_array() instead of mysql_fetch_row(). It is supposed that mysql_fetch_row returns an array of the values for a single row only, while, I see you are trying to fetch several values from several different rows.
The other thing is print or echo - they are identical, however echo is more frequently used. In both cases check always if you have corectly closed your quotes and if you have placed evrywhere the closing brakets and the semicolons [;]. If you have pasted the above code directly from your page, I see a couple of errors you should correct first.

I would do it like this

echo '<form name="name" action="targetpage.php" >';
 
while ($row= mysql_fetch_array($result)) 
{
                  echo '<select name = "students">;
                    foreach ($row as $field) 
  {
   echo '<option value="'.$field.">'.$field.'</option>';
  }
}
echo '</select>
        </form>';
Member Avatar for Rhyan

I'm having this error on the area below. When I comment it out it stops giving me the error and I have tried commenting it out piece by piece to see if there is something wrong but I get nothing. I'm sure I am missing something really easy.

while (row= mysql_fetch_row($result)) {
                  print '<form';
                  print '<select name = "students">;
                  foreach ($row as $field) {
                       print '<option value="$field>$field</option>;
                  }
                  print '</select>';
                  print '</form>;
                  }

Hey there.

In my opinion in your case you should use mysql_fetch_array() instead of mysql_fetch_row(). It is supposed that mysql_fetch_row returns an array of the values for a single row only, while, I see you are trying to fetch several values from several different rows.
The other thing is print or echo - they are identical, however echo is more frequently used. In both cases check always if you have corectly closed your quotes and if you have placed evrywhere the closing brakets and the semicolons [;]. If you have pasted the above code directly from your page, I see a couple of errors you should correct first.

I would do it like this

echo '<form name="name" action="targetpage.php" >';
 
while ($row= mysql_fetch_array($result)) 
{
                  echo '<select name = "students">;
                    foreach ($row as $field) 
  {
   echo '<option value="'.$field.">'.$field.'</option>';
  }
}
echo '</select>
        </form>';

Please do help me in solving this code...Because I am not able to insert information into my database.

<?
	session_start();
	
	require("db.php");

	mysql_connect(MACHINE, USER, '');
	mysql_select_db(DBNAME);
	
	
	$userid = $_SESSION['userid'];
	$ts = time();
		
	foreach ($_POST as $key => $value) {
	//echo "key: ".$key.", value: ".$value."<br>";

		$sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$ts')";
		mysql_query($sql); 
	}
	
	header('Refresh: 3; url=cart.php');
	echo "Your order is being processed, you will be directed to your shopping cart soon";
?>
Member Avatar for Rhyan

Please do help me in solving this code...Because I am not able to insert information into my database.

<?
    session_start();
    
    require("db.php");

    mysql_connect(MACHINE, USER, '');
    mysql_select_db(DBNAME);
    
    
    $userid = $_SESSION['userid'];
    $ts = time();
        
    foreach ($_POST as $key => $value) {
    //echo "key: ".$key.", value: ".$value."<br>";

        $sql = "INSERT INTO orders (imageid, userid, time) VALUES ('$key', '$userid', '$ts')";
        mysql_query($sql); 
    }
    
    header('Refresh: 3; url=cart.php');
    echo "Your order is being processed, you will be directed to your shopping cart soon";
?>

Hi there,

you have to advise what is the message that the system throws when you are unable to insert data. There may be many reasons.
From your code I suspect the following:

1. mysql_connect function requires you to insert host, username and pass using quotes ''. So you should do it like mysql_connect('machine', 'user', 'pass');

2. mysql_select_db('dbname') - same error as on previous point.

3. It is recommended that you use the dbname.tablename convention when using the insert statement in order to insert data into your db. It is supposed to avoid mistakes when referencing to a table. Note, that although you have selected the DB using mysql_select_db, still it is better to specify the db.tablename when inserting data.

Try theese and advise results, as well as error messages.

Please start a new thread to ask a different question. If you find one similar to what your problem is, you can link to it.

October 2006 was a long time ago, I had forgotten all about errorcodes and such from "print."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.