Hey guys I'm relatively new to PHP and I've come across an issue with my Syntax I cant seem to fix (I've only started 2-3 weeks ago) and this is my second time trying to generate something 'dynamic generated' from the database.
I'm using radio buttons, so what I'm trying to do is my radio buttons will be generated from my database table and the form which its using will send the information of the value so like 'staffID' to another page to process that info
This is the error I'm getting:
syntax error, unexpected T_STRING, expecting ',' or ';'
I've looked it up it's saying I have some unterminated string of some sort at line 22 which is my echo in my while loop and I'm not too sure what to make of it.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>PHP Task 10</title>
</head>
<body>
<?php
$conn = mysql_connect("xxxxxx", xxxxxx", "xxxxxxxx");
mysql_select_db("xxxxxxxx", $conn)
or die ('Database not found ' . mysql_error() );
$sql = "SELECT staffName, staffID
FROM staff";
$rs = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
?>
<form id="staff" action="task7.php" method="get">
<?php
while($row = mysql_fetch_array($rs)){
echo "<input type="radio" name="staffID" value=<?php echo '".$row["staffID"]."'?>><?php echo ".$row["staffName"]."?>";
};
?>
<p><input type="submit" value="Submit">
<input type="reset" value="Reset"></p>
</form>
</body>
</html>
You have some mistakes in your code. While you are echoing a string with PHP, you don't need to add <?php ?>
tags and echo
each time like,
value=<?php echo '".$row["staffID"]."'?>
Change
while($row = mysql_fetch_array($rs)){
echo "<input type="radio" name="staffID" value=<?php echo '".$row["staffID"]."'?>><?php echo ".$row["staffName"]."?>";
};
to
while($row = mysql_fetch_array($rs)){
echo "<input type='radio' name='staffID' value='".$row["staffID"]."'>".$row["staffName"];
}
You cannot echo inside echo in PHP :
echo "<input type="radio" name="staffID" value=<?php echo '".$row["staffID"]."'?>><?php echo ".$row["staffName"]."?>";
This should be like :
echo "<input type='radio' name='staffID' value='".$row["staffID"]."'>".$row["staffName"];