Hej, jeg har et lille problem med at få min values fra databasen ned i mine text felter så jeg kan redigere dem.
<?php
$id = $_GET['id'];
$sql = sprintf("SELECT * FROM news WHERE id = $id");
$result = mysql_query($sql) or die(mysql_error );
while($row = mysql_fetch_assoc($result)) ?>
<td width="30%" valign="top">Headline: </td>
<td width="70%"><input name="headline" type="text" class="inputfield" id="headline" value="<?php echo $row['headline']; ?>"></td>
</tr>
<tr>
<td><input name="hidden_id" type="hidden" id="hidden_id" value="<?php echo $id ?>"></td>
<td><?php echo $row['bodytext']; ?></td>
</tr>
<tr>
<td valign="top">Text:</td>
<td><textarea name="bodytext" rows="10" class="inputfield" id="bodytext"><?php echo $row['bodytext']; ?></textarea></td>
</tr>
<tr>
<td valign="top"> </td>
<td> </td>
</tr>
<tr>
<td align="center" valign="top"> </td>
<td valign="top"><input name="Submit" type="submit" style="text-align: center" class="inputfield" value="Edit news item"></td>
</tr>
<tr>
<td align="center" valign="top"> </td>
<td valign="top"> </td>
</tr>
<tr>
<td align="center" valign="top"> </td>
<td valign="top">
<?
if (isset($_POST['Submit'])) {
$headline = htmlspecialchars($_POST[headline]);
$bodytext = htmlspecialchars($_POST[bodytext]);
if((!$headline) || (!$bodytext))
{
echo("Please define headline and text for this news post!");
}else{
mysql_connect("localhost", "eastd", "west14");
mysql_select_db("eastd_db");
mysql_query("UPDATE news (id, headline, bodytext) VALUES ('$id', '$headline', '$bodytext')") or die(mysql_error());
echo("The news post has been edited!");
}}
?>
Ville blive glad hvis nogen kan hjælpe mig
Der skal ikke være nogen sprintf funktion til sql-querien, så vidt jeg ved, så ville rette:
<?php
$id = $_GET['id'];
$sql = "SELECT * FROM news WHERE id = $id";
$result = mysql_query($sql) or die(mysql_error );
while($row = mysql_fetch_assoc($result)) ?>
<td width="30%" valign="top">Headline: </td>
<td width="70%"><input name="headline" type="text" class="inputfield" id="headline" value="<?php echo $row['headline']; ?>"></td>
</tr>
<tr>
<td><input name="hidden_id" type="hidden" id="hidden_id" value="<?php echo $id ?>"></td>
<td><?php echo $row['bodytext']; ?></td>
</tr>
<tr>
<td valign="top">Text:</td>
<td><textarea name="bodytext" rows="10" class="inputfield" id="bodytext"><?php echo $row['bodytext']; ?></textarea></td>
</tr>
<tr>
<td valign="top"> </td>
<td> </td>
</tr>
<tr>
<td align="center" valign="top"> </td>
<td valign="top"><input name="Submit" type="submit" style="text-align: center" class="inputfield" value="Edit news item"></td>
</tr>
<tr>
<td align="center" valign="top"> </td>
<td valign="top"> </td>
</tr>
<tr>
<td align="center" valign="top"> </td>
<td valign="top">
<?
if (isset($_POST['Submit'])) {
$headline = htmlspecialchars($_POST[headline]);
$bodytext = htmlspecialchars($_POST[bodytext]);
if((!$headline) || (!$bodytext))
{
echo("Please define headline and text for this news post!");
}else{
mysql_connect("*****", "*****", "******");
mysql_select_db("*****");
mysql_query("UPDATE news (id, headline, bodytext) VALUES ('$id', '$headline', '$bodytext')") or die(mysql_error());
echo("The news post has been edited!");
}}
?>
btw. det er farligt at skrive hvad der ser ud til at være de rigtige password og brugernavn i tråden
Indlæg senest redigeret d. 24.06.2006 18:15 af Bruger #3884