Jump to content

Wont Update to DB


balkan7

Recommended Posts

hi again, i have problem whit values update in DB, where i wong whit my code ?

edit.php
[code]<?php
//------------------------------------------
//database connection
mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
//end database connection
//------------------------------------------
$authlvl = "3";
include("authcheck.php");
include("cstring.php");
//------------------------------------------
//echo out a navigation panel
echo "<body bgcolor='#C0C0C0'>";
echo "<center><a href='index.php'>Pregled na Kategoerii</a> | <a href='index.php?action=dodaj'>Dodaj Software</a></center>";
switch($_GET['action'])
{
case "popravi":

//if there is an ID given..
if($_GET['id'])
{
//set $id to the URL id, cast to an INT
//for security purposes
$id = (int)$_GET['id'];

//query the database
$query = mysql_query("SELECT * FROM software WHERE id = '$id'") or die (mysql_error());
  $row = mysql_fetch_array($query);
//if no rows returned...
if(mysql_num_rows($query) == 0)
{
echo "That ID is not in the database!";
exit();
}
  //isn't submitted, show one
if(!isset($_POST['izmeni']))
{
echo "<br>
<div align='center'>
<form action='izmeni.php?action=popravi' method='post'>
<table border='0' cellpadding='0' cellspacing='0' width='500' style='border: 1px solid black; padding: 3px;'>
    <tr>
        <td colspan='2'>Software:    <b>$row[naslov]</b></td>
    </tr>
    <tr>
              <td>Sifra:</td>
              <td><input type='text' name='sifra' value='$row[sifra]' disabled></td>
          <tr>
    <tr>
              <td>Naslov:</td>
              <td><input type='text' name='naslov' value='$row[naslov]'></td>
          <tr>
              <td>Opis:</td>
              <td><textarea name='opis' cols='40' rows='5'>$row[opis]</textarea></td>
          </tr>
          <tr>
          <td>Kategorija:</td>
          <td>
              <select name='kategorija'>
              <option>- Izberi -</option>
                  ";
          //the categorys table and getting all the
          $query = mysql_query("SELECT * FROM software_kategorija ORDER BY id ASC") or die(mysql_error());
          while($row = mysql_fetch_array($query))
          {
              echo "<option value='$row[id]'>$row[kategorija]";
          }
                    echo "
              </select>
          </td>
  </tr>
  <tr>
          <td>CD & DVD:</td>
          <td>
              <select name='cd'>
              <option>- Izberi -</option>
                  ";
          //so the user can select which category
          $query = mysql_query("SELECT * FROM software_cd ORDER BY id ASC") or die(mysql_error());
          while($row = mysql_fetch_array($query))
          {
              echo "<option value='$row[id]'>$row[cd]";
          }
                    echo "
              </select>
          </td>
      </tr>
  <tr>
      <td>Novo?</td>
      <td><input type='checkbox' name='novo' value='1' checked></td>
  </tr>
  <tr>
      <td colspan='2'><center><input type='submit' name='izmeni' value='Submit New Software'></center></td>
  </tr>
</form>
</table>
          </tr>
    <tr>
        <td colspan='2' style='border: 1px solid black;'><center><b>Software</b></center><br /></td>
    </tr>
    <tr>
    ";
  }
  }
   
//if set izmeni ..
if(isset($_POST['izmeni']))
{
$naslov = mysql_real_escape_string(strip_tags($_POST['naslov']));
    $opis = mysql_real_escape_string(strip_tags($_POST['opis']));
    $kategorija = mysql_real_escape_string(strip_tags($_POST['kategorija']));
    $cd = mysql_real_escape_string(strip_tags($_POST['cd']));
    $novo = mysql_real_escape_string($_POST['novo']);
    $datum = date("m/d/Y");
     
      //we begin error checking....
      $error_msg = array();
      if(empty($naslov))
      {
          $error_msg[] = "Please insert a naslov!<br />";
      }
      if(empty($opis))
      {
          $error_msg[] = "Please insert a opis!<br />";
      }
      if(empty($kategorija))
      {
          $error_msg[] = "Please select a kategorija!<br />";
      }
      if(empty($cd))
      {
          $error_msg[] = "Please select CD!<br />";
      }
      //print the errors, if any
      if(count($error_msg)>0)
      {
          echo "<strong>ERROR:</strong><br>\n";
          foreach($error_msg as $err)
              echo "$err";
      }
      //everythings ok, insert it to the DB
      else
      {
//update the product!
$popravi2 = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'";
mysql_query($popravi2) or die(mysql_error("Nemoze da napravi Update."));
    echo "<p><b>Update-ot e uspesno napraven!</b></p>";
}
    echo "
    </tr>
    </body>
    ";
  }
    }
    ?>[/code]
Link to comment
Share on other sites

[quote author=thorpe link=topic=113904.msg463262#msg463262 date=1162742589]
Are you getting any errors? Have you tried debugging? eg;

[code=php:0]
mysql_query("YOUR_UPDATE_QUERY") or die(mysql_erorr());
[/code]
[/quote]

no i dont get errors, show me the echo for successfull update, but i have tried first whit this code:[code]$update = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'";
mysql_query($update) or die(mysql_error("Nemoze da napravi Update."));[/code]
no result in DB !
Link to comment
Share on other sites

also put your connection in a variable so you can use it as a resource link in your queries, it helps sometimes. (just a backup I'm saying)

like
$conn = @mysql_connect("server", "user", "pass") or die(mysql_error());

then when you need to execute a query:
@mysql_query("sql here", $conn);

you just use it as the second argument.
Link to comment
Share on other sites

yes Id is present but i dont know why not update, i paste code for preview and code for edit again:

view.php
[code]<?php
  case "pregled":
  //if there is an ID given...
  if($_GET['id'])
  {
  //get the id, put it into a variable, cast to an INT
  //(for security purposes)
  $id = (int)$_GET['id'];
  $query = mysql_query("SELECT * FROM software WHERE kat_id = '$id' AND validen = '1'") or die(mysql_error());
 
  //if no results, show that there are no tutorials
  //for that category
  if(mysql_num_rows($query) == 0)
  {
  echo "Nema software vo ovaa Kategorija!";
  }
  //else, there is..show em
  else
  {
  echo "<h1>Softwares</h1>";
  //show all product of category
  echo "<form action='index.php?action=brisi' method='post' name='delete'>
  <table border='0' cellpadding='0' cellspacing='0' width='500'>";
  while($row = mysql_fetch_array($query))
  {
  echo "
      <tr>
          <td>Sifra:</td>
          <td><b>$row[sifra]</b></td>
      </tr>
      <tr>
          <td>Naslov:</td>
          <td><b>$row[naslov]</b></td>
      </tr>
      <tr>
          <td>Opis:</td>
          <td>$row[opis]</td>
      </tr>
      <tr>
          <td>Kategorija:</td>
          <td>$row[kat_id]</td>
      </tr>
      <tr>
          <td>CD & DVD:</td>
          <td>$row[cd_id]</td>
      </tr>
      <tr>
          <td>Novo:</td>
          <td>$row[novo]</td>
      </tr>
      <tr>
          <td>Datum:</td>
          <td>$row[datum]</td>
      </tr>
      <tr>
          <td>Izmeni:</td>
          <td colspan='2'><b><a href='izmeni.php?action=popravi&id=$row[id]'>Izmeni</a></b></td>
      </tr>
      <tr>
          <td><b>BRISI</b></td>
          <td><input onClick='document.delete.izbrisi.disabled=false' type='checkbox' name='row[]' value='$row[id]'>  <input type='submit' name='izbrisi' value='Delete' disabled></td>
      </tr>
      <tr>
          <td colspan='2'><hr /></td>
      </tr>
  ";
  }
  echo "</table>";
  }
}
else
{
echo "Momentalno nema Softwares!";
}
break; ?>[/code]

edit.php
[code]<?php
//------------------------------------------
//database connection
mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
//end database connection
//------------------------------------------
$authlvl = "3";
include("authcheck.php");
include("cstring.php");
//------------------------------------------
//echo out a navigation panel
echo "<body bgcolor='#C0C0C0'>";
echo "<center><a href='index.php'>Pregled na Kategoerii</a> | <a href='index.php?action=dodaj'>Dodaj Software</a></center>";
switch($_GET['action'])
{
case "popravi":

//if there is an ID given..
if($_GET['id'])
{
//set $id to the URL id, cast to an INT
//for security purposes
$id = (int)$_GET['id'];

//query the database
$query = mysql_query("SELECT * FROM software WHERE id = '$id'") or die (mysql_error());
  $row = mysql_fetch_array($query);
//if no rows returned...
if(mysql_num_rows($query) == 0)
{
echo "That ID is not in the database!";
exit();
}
  //isn't submitted, show one
if(!isset($_POST['izmeni']))
{
echo "<br>
<div align='center'>
<form action='izmeni.php?action=popravi' method='post'>
<table border='0' cellpadding='0' cellspacing='0' width='500' style='border: 1px solid black; padding: 3px;'>
    <tr>
        <td colspan='2'>Software:    <b>$row[naslov]</b></td>
    </tr>
    <tr>
              <td>Sifra:</td>
              <td><input type='text' name='sifra' value='$row[sifra]' disabled></td>
          <tr>
    <tr>
              <td>Naslov:</td>
              <td><input type='text' name='naslov' value='$row[naslov]'></td>
          <tr>
              <td>Opis:</td>
              <td><textarea name='opis' cols='40' rows='5'>$row[opis]</textarea></td>
          </tr>
          <tr>
          <td>Kategorija:</td>
          <td>
              <select name='kategorija'>
              <option>- Izberi -</option>
                  ";
          //the categorys table and getting all the
          $query = mysql_query("SELECT * FROM software_kategorija ORDER BY id ASC") or die(mysql_error());
          while($row = mysql_fetch_array($query))
          {
              echo "<option value='$row[id]'>$row[kategorija]";
          }
                    echo "
              </select>
          </td>
  </tr>
  <tr>
          <td>CD & DVD:</td>
          <td>
              <select name='cd'>
              <option>- Izberi -</option>
                  ";
          //so the user can select which category
          $query = mysql_query("SELECT * FROM software_cd ORDER BY id ASC") or die(mysql_error());
          while($row = mysql_fetch_array($query))
          {
              echo "<option value='$row[id]'>$row[cd]";
          }
                    echo "
              </select>
          </td>
      </tr>
  <tr>
      <td>Novo?</td>
      <td><input type='checkbox' name='novo' value='1' checked></td>
  </tr>
  <tr>
      <td colspan='2'><center><input type='submit' name='izmeni' value='Submit New Software'></center></td>
  </tr>
</form>
</table>
          </tr>
    <tr>
        <td colspan='2' style='border: 1px solid black;'><center><b>Software</b></center><br /></td>
    </tr>
    <tr>
    ";
  }
  }
   
//if set izmeni ..
elseif(isset($_POST['izmeni']))
{
$naslov = mysql_real_escape_string(strip_tags($_POST['naslov']));
    $opis = mysql_real_escape_string(strip_tags($_POST['opis']));
    $kategorija = mysql_real_escape_string(strip_tags($_POST['kategorija']));
    $cd = mysql_real_escape_string(strip_tags($_POST['cd']));
    $novo = mysql_real_escape_string($_POST['novo']);
     
      //we begin error checking....
      $error_msg = array();
      if(empty($naslov))
      {
          $error_msg[] = "Please insert a naslov!<br />";
      }
      if(empty($opis))
      {
          $error_msg[] = "Please insert a opis!<br />";
      }
      if(empty($kategorija))
      {
          $error_msg[] = "Please select a kategorija!<br />";
      }
      if(empty($cd))
      {
          $error_msg[] = "Please select CD!<br />";
      }
      //print the errors, if any
      if(count($error_msg)>0)
      {
          echo "<strong>ERROR:</strong><br>\n";
          foreach($error_msg as $err)
              echo "$err";
      }
      //everythings ok, insert it to the DB
      else
      {
//update the product!
$update = mysql_query("UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'") or die(mysql_error());
    echo "<p><b>Update-ot e uspesno napraven!</b></p>";
}
    echo "
    </tr>
    </body>
    ";
  }
    }
    ?>[/code]
Link to comment
Share on other sites

Echo your query!!!!

[code=php:0]
$update = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'";
echo $update;
exit();
mysql_query($update) or die(mysql_error());
[/code]

What do you see?
Link to comment
Share on other sites

i have fixed my problem, but thanks again for support!
just remove
[code]//if there is an ID given..
if($_GET['id'])
{
[/code] i forget this because this call from view product and forget to add in action [color=red]&id=$id[/color]:
[code]<form action='$PHP_SELF?action=popravi&id=$id' method='post'>[/code]
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.