Jump to content

PHP/SQL update statement


kanie12

Recommended Posts

Hi i'm having some problem with my update statment. Here is a form with disabled and prefilled fields. Every field has an edit button. Form.php(bottom of page) doesn't update the table. Is the statement wrong? Im sure that "Seinfeld" is in the database and kunde is the correct table. Could it be the disabled/prefilled fields causing the problem since they have an initial value? I edited fornavn(firstname) and etternavn for updating. After the update it should print to screen that the update is done, this never happens so clearly the statement isn't working. I tried using insert with empty table and that worked no prob.  :-\

 

Info.php

 

<?php

require_once("funksjoner.php");

topp();

topp_meny();

$Choo = new mysql();

      $Choo->connect();

      $result = $Choo->query("SELECT * FROM `kunde` WHERE kunde_id=1");

      $row = mysql_fetch_row( $result );

     

  $kunde_id=($row[0]);

      $fornavn=($row[1]);

  $etternavn=($row[2]);

  $gatenavn=($row[3]);

  $postnummer=($row[4]);

  $telefonnr=($row[5]);

  $mobil=($row[6]);

  $epost=($row[7]);

  $passord=($row[8]);

 

 

?>

<style type="text/css">

<!--

.style1 {color: #CCCCCC}

-->

</style>

 

 

<div id='kundeinfo'>

<form name='info' form action="form.php" method="post">

 

 

<table width="396" border="0" align="center">

  <tr>

    <td width="195"><div align="left">Fornavn:</div></td>

    <td width="191"><div align="center">

    <input type="text" value="<?php echo $fornavn; ?>" name= "fornavn"  disabled="true" />

    <script language="javascript">

function enableFornavn()

{

document.info.fornavn.disabled=false;

}

 

</script>

 

<a href="javascript:enableFornavn()">Endre<a/>

    </div></td>

  </tr>

  <tr>

    <td><div align="left">Etternavn:</div></td>

    <td><div align="center">

      <input type="text" value="<?php echo $etternavn; ?>" name = "etternavn"  disabled="true" />

      <script language="javascript">

function enableEtternavn()

{

document.info.etternavn.disabled=false;

}

 

</script>

<a href="javascript:enableEtternavn()">Endre<a/>

    </div></td>

  </tr>

  <tr>

    <td><div align="left">Gatenavn:</div></td>

    <td><div align="center">

      <input type="text" value="<?php echo $gatenavn; ?>"name = "gatenavn"  disabled="true" />

      <script language="javascript">

function enableGatenavn()

{

document.info.gatenavn.disabled=false;

}

 

</script>

<a href="javascript:enableGatenavn()">Endre<a/>

    </div></td>

  </tr>

  <td><div align="left">Postnr:</div></td>

    <td><div align="center">

      <input type="text" value="<?php echo $postnummer; ?>"name = "postnummer"  disabled="true" />

      <script language="javascript">

function enablePostnr()

{

document.info.postnummer.disabled=false;

}

 

</script>

<a href="javascript:enablePostnr()">Endre<a/>

    </div></td>

  </tr>

  <td><div align="left">Telefon:</div></td>

    <td><div align="center">

      <input type="text" value="<?php echo $telefonnr; ?>"name = "telefonnr"  disabled="true" />

      <script language="javascript">

function enableTelefonnr()

{

document.info.telefonnr.disabled=false;

}

 

</script>

<a href="javascript:enableTelefonnr()">Endre<a/>

    </div></td>

  </tr>

  <td><div align="left">Mobil:</div></td>

    <td><div align="center">

      <input type="text" value="<?php echo $mobil; ?>" name = "mobil"  disabled="true" />

      <script language="javascript">

function enableMobil()

{

document.info.mobil.disabled=false;

}

 

</script>

<a href="javascript:enableMobil()">Endre<a/>

    </div></td>

  </tr>

    <td><div align="left">Epost:</div></td>

    <td><div align="center">

      <input type="text" value="<?php echo $epost; ?>" name = "epost"  disabled="true" />

      <script language="javascript">

function enableEpost()

{

document.info.epost.disabled=false;

}

 

</script>

<a href="javascript:enableEpost()">Endre<a/>

    </div></td>

  </tr>

    <td><div align="left">Passord:</div></td>

    <td><div align="center">

      <input type="text" value="<?php echo $passord; ?>"name = "passord"  disabled="true" />

      <script language="javascript">

function enablePassord()

{

document.info.passord.disabled=false;

}

 

</script>

<a href="javascript:enablePassord()">Endre<a/>

    </div></td>

  </tr>

    <tr>

    <td><div align="left">Kundeid:

       

    </div></td>

    <td>     

     

      <div align="center">

        <input type="text" value="<?php echo $kunde_id; ?>"name = "kunde_id"  disabled="true" />

        <span class="style1">Endre</span></div></td>

  </tr>

</table>

 

 

 

 

<div align="center">

      <input type="submit" value="Oppdater">

     

</div>

</form></div>

 

 

     

     

 

Form.php

 

<?php

$kunde_id=$_POST['kunde_id'];

$fornavn=$_POST['fornavn'];

$etternavn=$_POST['etternavn'];

$gatenavn=$_POST['gatenavn'];

$postnummer=$_POST['postnummer'];

$telefonnr=$_POST['telefonr'];

$mobil=$_POST['mobil'];

$epost=$_POST['epost'];

$passord=$_POST['passord']; 

 

mysql_connect("localhost", "*****", "******") or die(mysql_error());

mysql_select_db("ernis_no") or die(mysql_error());

mysql_query("UPDATE kunde SET fornavn = $fornavn, etternavn = $etternavn WHERE etternavn = "Seinfeld"");

Print "Kundeinfo ble oppdatert!";

?>

 

 

Link to comment
Share on other sites

Try changing this line:

 

mysql_query("UPDATE kunde SET fornavn = $fornavn, etternavn = $etternavn WHERE etternavn = "Seinfeld"");

 

 

To:

 

mysql_query("UPDATE kunde SET fornavn = $fornavn, etternavn = $etternavn WHERE etternavn = 'Seinfeld'");

Link to comment
Share on other sites

Change:

 

mysql_query("UPDATE kunde SET fornavn = $fornavn, etternavn = $etternavn WHERE etternavn = 'Seinfeld'");

 

to:

 

$query = "UPDATE kunde SET fornavn = '$fornavn', etternavn = '$etternavn' WHERE etternavn = 'Seinfeld'";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

 

Report any error message output

Link to comment
Share on other sites

use addslashes at minium please ok.

 

<?php 
$kunde_id=addslashes($_POST['kunde_id']); 
$fornavn=addslashes($_POST['fornavn']); 
$etternavn=addslashes($_POST['etternavn']);
$gatenavn=addslashes($_POST['gatenavn']); 
$postnummer=addslashes($_POST['postnummer']); 
$telefonnr=addslashes($_POST['telefonr']); 
$mobil=addslashes($_POST['mobil']); 
$epost=addslashes($_POST['epost']); 
$passord=addslashes($_POST['passord']);  

$db=mysql_connect("localhost", "*****", "******"); 
mysql_select_db("ernis_no",$db) or die(mysql_error()); 
$query="UPDATE `kunde` SET `fornavn` = '$fornavn', `etternavn` = '$etternavn' WHERE `etternavn` = 'Seinfeld' ";
$result=mysql_query($query)or die("mysql_error()");
if(mysql_affected_rows($result)){
Print "Kundeinfo ble oppdatert!"; 
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.