Basic submission of a Form to MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Basic submission of a Form to MySQL

Post 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]
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Why do you think you're setting a $_GET variable? Coz you ain't.
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post by besbajah »

what should I do then instead of setting a $GET variable?
besbajah
Forum Newbie
Posts: 23
Joined: Fri May 20, 2005 1:00 pm
Location: Brazil

Post 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 ?
User avatar
ed209
Forum Contributor
Posts: 153
Joined: Thu May 12, 2005 5:06 am
Location: UK

Post 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')"); 

}  

?>
Post Reply