Reputation: 1453
I am a real beginner at this so sorry if I am makin awfull mistakes!
Want I want to do I know is very simple but I cant find the relevant help in my documentation.
I want to bring four variables out of a 'product' page, I then want to post these as the values of an html form but I am not sure how.
The variables come from managebooks.php and need to be used in ammendbook.php.
In managebooks.php my link to ammendbook.php is as follows:
echo "<tr>";
echo "<td>";
echo "<a href='amendbook.php?bookname=".$bookname."&bookauthor=".$bookauthor."&bookpub=".$bookpub."&bookisbn=".$bookisbn."'>Amend Entry</a>";
echo "</td>";
This i expected to bring that four variables with me to the next page (ammendbook.php) my form code is as follows:
<form id="adminlogin" name="login" action="amendbookupdate.php" method="post">
Book Title <br />
<input type="text" name="booktitle" value="<?php echo $bookname; ?>"></input><br />
Book Author(s)<br />
<input type="text" name="bookauthor" value="<?php echo $bookauthor; ?>"></input><br />
Book Publisher<br />
<input type="text" name="bookpub" value="<?php echo $bookpub; ?>" ></input><br />
ISBN-10 number (non-standard format)<br />
<input type="text" name="bookisbn" value="<?php echo $bookisbn; ?>"></input><br /><br />
<input type="submit" name="submit" value=" - Update Database - "></input>
</form>
I am not sure what else to include, I tried making an array to see if that would work (hense the echo variables like this:
<?php
$bookname['bookname'] = $_GET['bookname'];
$bookauthor['bookauthor'] = $_GET['bookauthor'];
$bookpub['bookpub'] = $_GET['bookpub'];
$bookisbn['bookisbn'] = $_GET['bookisbn'];
?>
But this is wrong.
I also in the form attempted to just put:
<input type="text" name="booktitle" value="<?php echo $_SESSION['bookname'] ?>"></input><br />
but this is also wrong!
Any ideas guys..
Thank you in advance for reading and any help!
[=
Upvotes: 2
Views: 570
Reputation: 18595
method="post"
To
method="GET"
Then feel free to use
$_GET['bookpub']
Without declaring.
test1.php:
<form action="test2.php" method="get">
Book Title <br />
<input type="text" name="booktitle" /><br />
<input type="submit" name="submit" value=" - Update Database - " />
</form>
test2.php
<body>
<? echo $_GET["booktitle"]; ?>
</body>
Upvotes: 4
Reputation: 1084
Just try:
$bookname = $_GET['bookname'];
$bookauthor = $_GET['bookauthor'];
$bookpub = $_GET['bookpub'];
$bookisbn = $_GET['bookisbn'];
At the top of ammendbook.php and then refer to those variables by those names. Is that not what you're looking for? I may be confused.
Edit: You should always sanitize variables that come from the GET or POST arrays before assigning them to variables.
Upvotes: 1