0

I'm trying to pass an id to a hidden form element and having some syntactical issues.

Here is MySQL query:

$sql="SELECT id,lastname,firstname FROM drivers_0135199";
$result=mysql_query($sql,$con);
echo mysql_error();

Here is my While loop and the hidden form field I am trying to echo out:

while($row=mysql_fetch_array($result)){
echo "<input type='hidden' name='idholder' value=".$row["id"]."/>";
}

mysql_error() returns the following:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 

I know the issue is within the echo statement for the hidden function, I just don't know the correct way to manage the quotes in this situation.

Thanks in advance for the help, I couldn't find a great answer in the annals.

3
  • 3
    What is the error that you get from mysql_error()? Commented Dec 8, 2011 at 5:34
  • Do you really think that MySQL is psychic enough to detect PHP errors? Commented Dec 8, 2011 at 5:35
  • Added the mysql_error() for your viewing pleasure. Commented Dec 8, 2011 at 5:43

5 Answers 5

3

Your hidden field echo statement syntax is correct. You said MySQL was returning the error. Double check the following:

  1. Make sure you are connecting successfully.
  2. Make sure you've selected a database after connecting.
  3. Double check your field names are correct.
  4. Double check your table name is correct.
  5. If you copy/pasted your SQL statement from elsewhere try retyping it to make sure no bogus characters made their way in.
1
  • Making some progress now, thanks for that, never had this issue before. Commented Dec 8, 2011 at 6:07
1

Erase the entire line that contains $sql=... and retype it; somehow an invisible character has snuck its way into the text. You can use od -c to verify.

1

Try this it's working for me.

Below is the following code:

<?php
while($fetchregion=mysql_fetch_array($region))
{
?>
 <input type="hidden" name="region" maxlength="30" size="70" value="<?php echo $fetchregion['REGION'];?>"/>
<?php
}
?>
0
while($row=mysql_fetch_array($result)){
?>
<input type="hidden" name="idholder" value="<?php echo $row['id']; ?>" />
<?php
}
0

Write like this

echo "<input type='hidden' name='idholder' value='$row['id']' />";
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.