Page 1 of 1

Basic submission of a Form to MySQL

Posted: Fri Mar 31, 2006 9:28 am
by besbajah
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi everyone,

I've got some code that submits the variables from a Form to MySQL. It works OK but there is an extra variable that needs to be sent that doesn't submit its data, a variable that was parsed from a refering file.

The variable is stored here: -
"
$FixedIDvalue = $_GET['FixedIDvalue'];
"

And here's the code: -

Code: Select all

<?php

IF (!isset($_POST['submit'])) {

?>

<form action="Reviewupdate01.php" method="post">

Your Name: <input type="text" name="Name" size="20">

Your Review: <input type="text" name="Review" size="50">

<input type="submit" name="submit" value="Submit!">

</form>

<?php

}

else
{

  $FixedIDvalue = $_GET['FixedIDvalue'];

  $Name = $_POST['Name'];
  $Review = $_POST['Review'];

mysql_db_query("vinylsur_music", "INSERT INTO `TrackReviews` (Name, Review, FixedID) VALUES ('$Name', '$Review', '$FixedIDvalue')");

} 

?>
If I were to change the value of $FixedIDvalue to a number, eg: $FixedIDvalue = 1234; the value is successfully sent to my table, but not the value of the $_GET value.

Any ideas?

Richard.


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Fri Mar 31, 2006 9:46 am
by onion2k
Why do you think you're setting a $_GET variable? Coz you ain't.

Posted: Fri Mar 31, 2006 9:50 am
by besbajah
what should I do then instead of setting a $GET variable?

Posted: Fri Mar 31, 2006 9:55 am
by besbajah
In other words, what should I do do convert the number that was parsed from the previous file into a variable?

At the moment I have:

$FixedIDvalue = $_GET['FixedIDvalue'];

Could I use something like

$FixedIDvalue = FixedIDvalue;

..taking out all the $_GET stuff ?

Posted: Fri Mar 31, 2006 1:55 pm
by ed209
Assuming this page receives the 'FixedIDvalue' in the url e.g.

Reviewupdate01.php?FixedIDvalue=1234

Code: Select all

<?php 

if(!isset($_POST['submit'])) { 

?> 

<form action="Reviewupdate01.php" method="post"> 

Your Name: <input type="text" name="Name" size="20"> 

Your Review: <input type="text" name="Review" size="50"> 



<!-- If your variable is received as a GET then you can add it into a hidden form field. -->
<input type="hidden" name="FixedIDvalue" value="<?php echo $_GET['FixedIDvalue']; ?>" />



<input type="submit" name="submit" value="Submit!"> 

</form> 

<?php 

} 

else 
{ 

  // Change this to Post 
  $FixedIDvalue = $_POST['FixedIDvalue']; 

  $Name = $_POST['Name']; 
  $Review = $_POST['Review']; 

mysql_db_query("vinylsur_music", "INSERT INTO `TrackReviews` (Name, Review, FixedID) VALUES ('$Name', '$Review', '$FixedIDvalue')"); 

}  

?>