newbie question

This is a discussion on newbie question within the PHP Language forums, part of the PHP Programming Forums category; Sorry if missed something obvious. I'm trying to write a notebook program that allows me to select a "...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-16-2005
maxborn555
 
Posts: n/a
Default newbie question

Sorry if missed something obvious. I'm trying to write
a notebook program that allows me to select a "subject"
from a pulldown menu and read the corresponding "data" back
into a form where I can edit and save it.

The MySQL database table looks like, ('id', 'subject, 'data').

Everything works find except for the last part (if post op = update).
The program doesn't remember the $_POST[id] although it does remember
all the other $_POST variables.

Thanks for any hints or suggestions.

Max


-------------------------------------------------------------
<?php

//echo $_POST[op];
$conn=mysql_connect("localhost","root","mypass");
mysql_select_db("it",$conn);
$sql="select * from data";
$result=mysql_query($sql,$conn);

if ($_POST[op] != "view") {

//show the form

echo "<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<select name=\"id\"><option value=\"\">--select
page--</option>";
while ($na = mysql_fetch_array($result)) {
echo "<option value=".$na['0'].">".$na['1']."</option>"; }
echo "</select>";
echo "<input type=\"submit\" name=\"op\"
value=\"view\"></form>";
}

if ($_POST[op] == "view") {

//get data and put into form.

$query="select * from data where id=".$_POST[id]."";
$res=mysql_query($query,$conn);
$array=mysql_fetch_array($res);

echo "<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
Subject:<br>
<input type=\"text\" name=\"subject\" size=\"81\"
value=\"".$array[1]."\"><br>
Description:<br>
<textarea name=\"body\" rows=\"40\"
cols=\"80\">".$array[2]."</textarea><br>
<input type=\"submit\" name=\"op\" value=\"update\">
</form>";
}

if ($_POST[op] == "update") {

//insert updated info into table

$update = "replace into data
values('$_POST[id]','$_POST[subject]','$_POST[body]')";
mysql_query($update) or die(mysql_error());

//echo for testing
echo $_POST['subject']."<br>";
echo $_POST['body']."<br>";
echo $_POST[op]."<br>";
echo $_POST[id]; //why is this always 'null'?

echo "Database updated.";
}

?>

Reply With Quote
  #2 (permalink)  
Old 02-16-2005
Steve
 
Posts: n/a
Default Re: newbie question

maxborn555 wrote:
> Sorry if missed something obvious. I'm trying to write
> a notebook program that allows me to select a "subject"
> from a pulldown menu and read the corresponding "data" back
> into a form where I can edit and save it.
>
> The MySQL database table looks like, ('id', 'subject, 'data').
>
> Everything works find except for the last part (if post op = update).
> The program doesn't remember the $_POST[id] although it does remember
> all the other $_POST variables.
>
> Thanks for any hints or suggestions.
>
> Max
>
>
> -------------------------------------------------------------
> <?php
>
> //echo $_POST[op];
> $conn=mysql_connect("localhost","root","mypass");
> mysql_select_db("it",$conn);
> $sql="select * from data";
> $result=mysql_query($sql,$conn);
>
> if ($_POST[op] != "view") {
>
> //show the form
>
> echo "<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
> <select name=\"id\"><option value=\"\">--select
> page--</option>";
> while ($na = mysql_fetch_array($result)) {
> echo "<option value=".$na['0'].">".$na['1']."</option>"; }

Either use
echo "<option value=".$na[0].">".$na[1]."</option>"; }
or
echo "<option value=".$na['id'].">".$na['subject']."</option>"; }

Steve
> echo "</select>";
> echo "<input type=\"submit\" name=\"op\"
> value=\"view\"></form>";
> }
>[snip]

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:23 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0