Hi all,
OK, I am trying to get the variable $currentid to be accessible throughout the script... How is this done?
The function changeid does not seem to help.
I am getting an error every time when I try and use id="$currentid" in a function that did not define it to start with...
So the idea is to have a choice of the database listings at first, then be able to assign a permanent value to $id so that all fomrs etc will use the id selected at first.
Sorry if this is confusing... I am confusing myself just trying to ask the question.
Thanks
Lucas
<?php
include "timing1.php";
$db = mysql_connect("localhost", "user", "blahblah");
mysql_select_db("mydbname",$db);
function changeid()
{
global $currentid;
$currentid = $id;
echo "this is the current: <br>", $currentid, "<br>";
return $currentid;
}
if ($submit) {
$add1 = '<P class=normal>';
$add2 = '</P><br>';
if ($radio1) {
$add1 = '<P class=title2>';
}
if ($radio2) {
$add1 = '<div class="center"><table class=main cellpadding="5" cellspacing="0"><tr><td>';
$add2 = '</td></tr></table></div><br>';
}
$entercontent = nl2br("$entercontent");
$entercontentb = $add1.$entercontent.$add2;
$result = mysql_query("SELECT * FROM add1 WHERE id='$currentid'",$db);
$myrow = mysql_fetch_array($result);
$newvar = $myrow['content'].$entercontentb;
$sql = "UPDATE add1 SET content = '$newvar', date = NOW() WHERE id = '$currentid'";
$result = mysql_query($sql);
if (!$result) {
echo "<P class=header>Sorry there was an Error, Please try again</P>";
} else {
// echo "<P class=header>thankyou information updated</P>";
}
}
if ($link) {
changeid();
$result = mysql_query("SELECT * FROM add1 WHERE id=$currentid");
echo $result;
echo "that was the result";
while ($myrow = mysql_fetch_array($result)) {
printf("%s", $myrow['content']);
}
if (!$myrow['content']) {
echo 'There is no output to display, please start creating the page below';
}
?>
<form action="<?php echo $PHP_SELF ?>" enctype="multipart/form-data" method="POST">
<table class=small border="1">
<tr><td>Text to add</td><td><textarea type="text" name="entercontent" rows="2" cols="80"></textarea></td></tr>
<tr><td><input type="Submit" name="submit" value="Enter information"></td>
<td><input type="radio" name="radio1">Colour text Red,
<input type="radio" name="radio2">Command text box
</td></tr>
<td><a href=<?php echo $PHP_SELF?>?id=<?php echo $currentid ?>&edita=yes>Edit</a> </td></tr>
</table>
</form>
<?php
}
if (!$currentid) {
$sql = "SELECT * FROM add1";
$result = mysql_query($sql);
while ($myrow = mysql_fetch_array($result)) {
printf("<a href=%s?id=%s&link=yes>%s</a><br>", $PHP_SELF, $myrow['id'], $myrow['title']);
} }
$result = mysql_query("SELECT * FROM add1",$db);
$myrow = mysql_fetch_array($result);
printf('<P class=footnoteb>This page was last updated on the %s</P>', $myrow['date']);
include "timing2.php";
?>