Jump to content

[SOLVED] mysql update success but no update in db


dsp77

Recommended Posts

Hello,

 

My problem is the mysql update command is doin the job but in the database i dont see any changes here are the two scripts

 

<?php
require_once('config.php');

$rezultat = mysql_query("SELECT * FROM intrari") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Start</th> <th>Sfarsit</th> <th>Nume</th> <th>Prioritate</th> <th>Descriere</th> <th>Editeaza</th> <th>Sterge</th> </tr>";
while($rand = mysql_fetch_array( $rezultat )) {
echo "<tr><td>";
echo $rand['id'];
echo "</td><td>";
echo $rand['start'];
echo "</td><td>"; 
echo $rand['sfarsit'];
echo "</td><td>"; 
echo $rand['nume'];
echo "</td><td>"; 
echo $rand['prioritate'];
echo "</td><td>"; 
echo $rand['descriere'];
echo "</td><td>"; 
echo "<a href=\"editeaza.php?id=$rand[id]\">Editeaza</a>";
echo "</td><td>"; 
echo "<a href=\"sterge.php?id=$rand[id]\">Sterge</a>";
echo "</td></tr>"; 
} 

echo "</table>";
?>

 

editeaza.php is edit

sterge.php is delete

 

and the update

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>
<body>
<table border=1>
  <tr>
    <td align=center>Form Edit Data</td>
  </tr>
  <tr>
    <td><table>
        <?php
require_once('config.php');
$id = $_GET['id'];

$order = "SELECT * FROM intrari where id='$id'";
$rezultat = mysql_query($order);
$rand = mysql_fetch_array($rezultat);
?>
        <form method="post" action="edit.php">
          <input type="hidden" name="id" value="<?php echo "$rand[id]"?>">
          <tr>
            <td>Start:</td>
            <td><input type="text" name="start" size="10" value="<?php echo "$rand[start]"?>"></td>
          </tr>
          <tr>
            <td>Sfarsit:</td>
            <td><input type="text" name="sfarsit" size="10" value="<?php echo "$rand[sfarsit]"?>"></td>
          </tr>
          <tr>
            <td>Nume:</td>
            <td><select name="nume" id="nume">
                <option selected="selected">Alege</option>
                <option>Adrian</option>
                <option>Dani</option>
                <option>Dinu</option>
                <option>Marian</option>
                <option>Marius</option>
              </select></td>
          </tr>
          <tr>
            <td>Prioritate:</td>
            <td><select name="prioritate" id="prioritate">
                <option selected="selected">Mica</option>
                <option>Medie</option>
                <option>Mare</option>
              </select></td>
          </tr>
          <tr>
            <td>Descriere:</td>
            <td><textarea cols="30" rows="5" name="descriere"><?php echo "$rand[descriere]"?></textarea></td>
          </tr>
          <tr>
            <td align="right"><input type="submit" name="submit value" value="Edit"></td>
          </tr>
        </form>
      </table></td>
  </tr>
</table>
</body>
</html>

<?php
require_once('config.php');
$order = "UPDATE intrari SET start='$start', sfarsit='$sfarsit', nume='$nume', prioritate='$prioritate', descriere='$descriere WHERE id='$id'";
mysql_query($order);
header("location:edit.php");
?>

the help would be very appreciated .

 

Link to comment
Share on other sites

change to:

 

<?php
require_once('config.php');
$order = "UPDATE intrari SET start='$start', sfarsit='$sfarsit', nume='$nume', prioritate='$prioritate', descriere='$descriere' WHERE id='$id'";
mysql_query($order);
header("location:edit.php");
?>

 

then report back.

Link to comment
Share on other sites

the error is generated by firefox not the server, maybe i missed something in php code

and cookies are accepted, in ie page is loading and nothing happens.

 

The page isn't redirecting properly

 

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

 

    *  This problem can sometimes be caused by disabling or refusing to accept

          cookies.

Link to comment
Share on other sites

this helped i don't get that error anymore but still no update in the database...tested now on other server php 5.30 and i get this 2

Notice: Undefined variable: start in C:\xampp\htdocs\it\edit.php on line 3

 

Notice: Undefined variable: sfarsit in C:\xampp\htdocs\it\edit.php on line 3

 

Notice: Undefined variable: nume in C:\xampp\htdocs\it\edit.php on line 3

 

Notice: Undefined variable: prioritate in C:\xampp\htdocs\it\edit.php on line 3

 

Notice: Undefined variable: descriere in C:\xampp\htdocs\it\edit.php on line 3

 

Notice: Undefined variable: id in C:\xampp\htdocs\it\edit.php on line 3

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\it\edit.php:3) in C:\xampp\htdocs\it\edit.php on line 5

Link to comment
Share on other sites

in the first code i extract the data from db and display as text

in the second code i create the form with data based on id from first code (i dont know how to use POST in the input fields there are already used with the code of extract)

and last code is all what u see is all code full.

i remember that i tried something like that and dint work or maybe you have other idea im out of options:(

Link to comment
Share on other sites

The Solution:

 

Search through your entire code for $rand, and ensure correctly written:

 

A lot of places you have done it correctly:

$rand['id'];

 

However there are a few places where you haven't:

$rand[id];

 

Notice the difference?

 

This is the variable undefined problem and relates to start, sfarsit, id and a few others

Link to comment
Share on other sites

The Solution:

 

Search through your entire code for $rand, and ensure correctly written:

 

A lot of places you have done it correctly:

$rand['id'];

 

However there are a few places where you haven't:

$rand[id];

 

Notice the difference?

 

This is the variable undefined problem and relates to start, sfarsit, id and a few others

 

Not necessarily, when you are refering to an associated array inside double quotes you can leave off single quotes to address the indexes:

 

<?php
echo "$some_array[some_index] - The correct way to address some_index in the array inside double quotes.";
?>

 

dsp77

You write this code:

 

<?php
require_once('config.php');
$order = "UPDATE intrari SET start='$start', sfarsit='$sfarsit', nume='$nume', prioritate='$prioritate', descriere='$descriere WHERE id='$id'";
mysql_query($order);
header("location:edit.php");
?>

 

Where is $start, $sfarsit, $nume, $prioritate, $descriere, and $id defined?

Link to comment
Share on other sites

yay at last i did it yes the problem was with the var undefined but i changed the sql syntax to this and it works

<?php
require_once('config.php');
$order = "UPDATE intrari SET start='" . $_POST['start'] . "', sfarsit='" . $_POST['sfarsit'] . "', nume='" . $_POST['nume'] . "', prioritate='" . $_POST['prioritate'] . "', descriere='" . $_POST['descriere'] . "' WHERE id='" . $_POST['id'] . "'"; ;
mysql_query($order);
header ("Location: http://127.0.0.1/jobs/vizualizare.php"); 
?>

Link to comment
Share on other sites

all i have left to figure out is the delete part to work im getting this error Notice: Undefined index: id in C:\xampp\xampp\htdocs\jobs\sterge.php on line 3

sterge.php

<?php
include "config.php";
$id=$_POST['id'];
$sql=mysql_query("DELETE FROM intrari WHERE id='$id'");
if (!$sql) {
die(mysql_error());
} else {
echo "datele au fost sterse";
}
mysql_close($conexiune);
?> 

 

the previous page is

<?php
require_once('config.php');

$rezultat = mysql_query("SELECT * FROM intrari") 
or die(mysql_error());  

echo "<table border='1'>";
echo "<tr> <th>ID</th> <th>Start</th> <th>Sfarsit</th> <th>Nume</th> <th>Prioritate</th> <th>Descriere</th> <th>Editeaza</th> <th>Sterge</th> </tr>";
while($rand = mysql_fetch_array( $rezultat )) {
   echo "<tr><td>";
   echo $rand['id'];
   echo "</td><td>";
   echo $rand['start'];
   echo "</td><td>"; 
   echo $rand['sfarsit'];
   echo "</td><td>"; 
   echo $rand['nume'];
   echo "</td><td>"; 
   echo $rand['prioritate'];
   echo "</td><td>"; 
   echo $rand['descriere'];
   echo "</td><td>"; 
   echo "<a href=\"editeaza.php?id=$rand[id]\">Editeaza</a>";
   echo "</td><td>"; 
   echo "<a href=\"sterge.php?id=$rand[id]\">Sterge</a>";
   echo "</td></tr>"; 
} 

echo "</table>";
?>

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.