0

Hey All!

I am trying to update some records using forms - But something gets mixed up when I send my info to the database:

My form with the info I wish to update, look like this:

//Getting the info from a dropdown list, where the user has picked which item to update
<?php
if (isset($_POST['formSubmit'])) {//get id from dropdown and clean it
$id = mysqli_real_escape_string($myConnection, $_POST['navn']); 
//Pull out the info from the database
$sqlCommand = "SELECT * FROM customers where id=$id LIMIT 1"; 
}
$query = mysqli_query($myConnection, $sqlCommand) or die                        (mysqli_error()); 		
while ($row = mysqli_fetch_array($query)) { 
$navn = $row['navn'];
$adresse = $row['adresse'];
$telefon = $row["telefon"];
$email = $row["email"];
$udmark = $row["udmark"];
$skind = $row["skind"];
$pris = $row["pris"];
$kontaktet = $row["kontaktet"];
}
mysqli_free_result($result); 
?>
//Here is my form where i prepopulate the fields with the relevant info
<form id="form" name="form" method="post" action="create_record_parse.php" 
    onsubmit="return validate_form ( );">
        
  <p><b>Navn&nbsp;<span class="required">*</span></b></p><input name="navn" type="text" id="navn"
   size="53" maxlength="80" value="<?php echo $navn; ?>"/> 
<br /><br />

<p><b>Adresse&nbsp;<span class="required">*</span></b></p><input name="adresse" type="text" id="adresse"   size="53" maxlength="80" value="<?php echo $adresse; ?>"/> 
 <br /><br />

<p><b>Telefon&nbsp;<span class="required">*</span></b></p><input name="telefon" type="text" id="telefon"   size="53" maxlength="80" value="<?php echo $telefon; ?>"/>
<br /><br />

<p><b>Email&nbsp;<span class="required">*</span></b></p><input name="email" type="text" id="email"   size="53" maxlength="80" value="<?php echo $email; ?>"/>
<br /><br />

<p><b>Udmark&nbsp;<span class="required">*</span></b></p><input name="udmark" type="text" id="udmark"   size="53" maxlength="80" value="<?php echo $udmark; ?>"/>
<br /><br />

<p><b>Antal Skind&nbsp;<span class="required">*</span></b></p><input name="skind" type="text" id="skind"   size="53" maxlength="80" value="<?php echo $skind; ?>"/>
<br /><br />

<p><b>Pris&nbsp;<span class="required">*</span></b></p><input name="pris" type="text" id="pris"   size="53" maxlength="80" value="<?php echo $pris; ?>"/>
<br /><br />

<p><b>Kontaktet&nbsp;<span class="required">*</span></b></p><input name="kontaktet" type="text" id="kontaktet"   size="53" maxlength="80"value="<?php echo $kontaktet; ?>"/>
<br /><br />
//[B]IS THERE SOMETHING WRONG IN THIS PART?[/B] IM USING THE HIDDEN FIELD IN MY PROCESS PAGE, //SHOWN FURTHER DOWN - MIGHT BE GETTING IT WRONG..
<input name="pid" type="hidden" value="<?php echo $id; ?>" />
<input type="submit" name="button" id="button" value="&nbsp;Opdater Kunde!&nbsp;" />
        
</form>

When I process the form, my code looks like this - And this actually CREATES a new record, instead of updating a record..???

Form processing code

$pid = ($_POST['pid']);
$navn = ($_POST['navn']);
$adresse = ($_POST['adresse']);
$telefon = ($_POST['telefon']);
$email = ($_POST['email']);
$udmark = ($_POST['udmark']);
$skind = ($_POST['skind']);
$pris = ($_POST['pris']);
$kontaktet = ($_POST['kontaktet']);

//And then i want to update the info in the DB, but it CREATES a new record...

require_once ('connect_to_mysql.php');

// Add the updated info into the database table--------------------------------------
$query = mysqli_query($myConnection, "UPDATE customers SET navn='$navn', adresse='$adresse', telefon='$telefon', email='$email', udmark='$udmark', skind='$skind', pris='$pris', kontaktet='$kontaktet' WHERE id='$pid'") or die (mysqli_error($myConnection));

Anyone that can see what I am doing wrong in my form handling here? :-)

Klemme

1
Contributor
1
Reply
3
Views
6 Years
Discussion Span
Last Post by klemme
0

Oops nevermind all, im a rookie kind a guy!! Form action="create_record......"

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.