Forum Moderators: coopster
The problem is displaying the values which are extracted from the db and that too with the single quotes placement in the echo part of the code. I can't figure out the proper way.
Where ever there is $row['something] that part throws a parse error and also the
<input type='hidden' name='id' value='$_GET['page']' />
<input type='hidden' name='catid' value='$_GET['catid']' />
part.
if($mode == '3') {
$edit = "SELECT * FROM articles WHERE id = $page AND catid = $catid"; $result = mysql_query($edit) or die (mysql_error());
$row = mysql_fetch_array($result);
echo "
<br>
<form action='ew.php' method='POST'><div>
<b>Name</b><br /><input type='text' name='name' value=$row['contributed_by'] /><br /><br />
<b>Title</b><br /><input type='text' name='title' value=$row['title'] /><br /><br />
<b>Content</b><br /><textarea name='content' cols='45' rows='10'>$row['content']</textarea><br /><br />
<b>Tags</b><br /><input type='text' name='tags' value=$row['tags'] /><br /><br />
<b>Mood</b><br />
<select name='mood' style='width:100px;'>
<option value='1'($row['mood'] == 1? ' selected='selected'' : ')>Happy</option>
<option value='2'($row['mood'] == 2? ' selected='selected'' : ')>Sad</option>
<option value='3'($row['mood'] == 3? ' selected='selected'' : ')>Anxious</option>
<option value='4'($row['mood'] == 4? ' selected='selected'' : ')>Angry</option>
<option value='5'($row['mood'] == 5? ' selected='selected'' : ')>Surprized</option>
</select><br /><br />
<input type='hidden' name='id' value='$_GET['page']' />
<input type='hidden' name='catid' value='$_GET['catid']' />
<input type='submit' value='Edit' />
</div>
</form>";
<option value='1'($row['mood'] == 1? ' selected='selected'' : ')>Happy</option>
<option value='2'($row['mood'] == 2? ' selected='selected'' : ')>Sad</option>
<option value='3'($row['mood'] == 3? ' selected='selected'' : ')>Anxious</option>
<option value='4'($row['mood'] == 4? ' selected='selected'' : ')>Angry</option>
<option value='5'($row['mood'] == 5? ' selected='selected'' : ')>Surprized</option>
You are using a ternary operator incorrectly. You can`t just use a single quote in the second part of the statement. And you need to enclose it in double quotes. You also need to remove the single quotes from the first part of the statement or escape them.
Try:
<option value='1'".($row['mood'] == 1? ' selected=\'selected\'' : '').">Happy</option>
<option value='2'".($row['mood'] == 2? ' selected=\'selected\'' : '').">Sad</option>
<option value='3'".($row['mood'] == 3? ' selected=\'selected\'' : '').">Anxious</option>
<option value='4'".($row['mood'] == 4? ' selected=\'selected\'' : '').">Angry</option>
<option value='5'".($row['mood'] == 5? ' selected=\'selected\'' : '').">Surprized</option>
dc
[php]if($mode == '3') {
$edit = "SELECT * FROM wow WHERE id = $page AND catid = $catid";
$result = mysql_query($edit) or die (mysql_error());
$row = mysql_fetch_array($result);
echo "
<br>
<form action='ew.php' method='POST'><div>
<b>Name</b><br /><input type='text' name='name' value='{$row['contributed_by']}'><br /><br />
<b>Title</b><br /><input type='text' name='title' value='{$row['title']}'><br /><br />
<b>Content</b><br /><textarea name='content' cols='45' rows='10'>{$row['content']}</textarea><br /><br />
<b>Tags</b><br /><input type='text' name='tags' value='{$row['tags']}'><br /><br />
<b>Mood</b><br />";
echo "<select name='mood' style='width:100px;'>";
echo "<option value='1'" . ($row['mood'] == 1? ' selected=\'selected\'' : '') . ">Happy</option>";
echo "<option value='2'" . ($row['mood'] == 2? ' selected=\'selected\'' : '') . ">Sad</option>";
echo "<option value='3'" . ($row['mood'] == 3? ' selected=\'selected\'' : '') . ">Anxious</option>";
echo "<option value='4'" . ($row['mood'] == 4? ' selected=\'selected\'' : '') . ">Angry</option>";
echo "<option value='5'" . ($row['mood'] == 5? ' selected=\'selected\'' : '') . ">Surprized</option>";
echo "</select><br /><br />";
echo" <input type='hidden' name='id' value='{$page}' />
<input type='hidden' name='catid' value='{$catid}'>
<input type='submit' value='Edit' />
</div>
</form>";
}[/php]