balkan7 Posted November 5, 2006 Share Posted November 5, 2006 hi again, i have problem whit values update in DB, where i wong whit my code ?edit.php[code]<?php//------------------------------------------//database connectionmysql_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 panelecho "<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] Quote Link to comment Share on other sites More sharing options...
Chikenty Posted November 5, 2006 Share Posted November 5, 2006 are some updating? r all the fields in entered in database? Quote Link to comment Share on other sites More sharing options...
Chikenty Posted November 5, 2006 Share Posted November 5, 2006 try replacing ur update with this [sup]$update = mysql_query("Update software set naslov = '$naslov',opis = '$opis', kat_id = '$kategorija', cd_id = '$cd, , novo = '$novo' where id = '$id'");[/sup]make sure to keep the other 1 Quote Link to comment Share on other sites More sharing options...
balkan7 Posted November 5, 2006 Author Share Posted November 5, 2006 i have tryed whit your code but not chage values in DB, just write me [color=red]Your product has been successfull update in DB![/color], but where you preview your change, not show your update just same product of 1st add!soryy for my bad english Quote Link to comment Share on other sites More sharing options...
balkan7 Posted November 5, 2006 Author Share Posted November 5, 2006 i have change [code]//if set izmeni ..elseif(isset($_POST['izmeni']))[/code]but again not update in DB. Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2006 Share Posted November 5, 2006 Are you getting any errors? Have you tried debugging? eg;[code=php:0]mysql_query("YOUR_UPDATE_QUERY") or die(mysql_erorr());[/code] Quote Link to comment Share on other sites More sharing options...
balkan7 Posted November 5, 2006 Author Share Posted November 5, 2006 [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 ! Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2006 Share Posted November 5, 2006 mysql_error() takes an optional resource link, not a string. What do you see if you echo $update? Quote Link to comment Share on other sites More sharing options...
balkan7 Posted November 5, 2006 Author Share Posted November 5, 2006 [code]echo "<p><b>Update has been succesfull!</b></p>";[/code] Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted November 5, 2006 Share Posted November 5, 2006 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. Quote Link to comment Share on other sites More sharing options...
redarrow Posted November 5, 2006 Share Posted November 5, 2006 Also make sure the id is set and is present echo $id if the id is present should work. Quote Link to comment Share on other sites More sharing options...
balkan7 Posted November 5, 2006 Author Share Posted November 5, 2006 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 connectionmysql_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 panelecho "<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] Quote Link to comment Share on other sites More sharing options...
trq Posted November 5, 2006 Share Posted November 5, 2006 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? Quote Link to comment Share on other sites More sharing options...
balkan7 Posted November 5, 2006 Author Share Posted November 5, 2006 [code]UPDATE software SET naslov = 'rrrrrrr', opis = 'aaaaaaaaaaaaaa', kat_id = '3', cd_id = '1', novo = '1' WHERE id = ''[/code] Quote Link to comment Share on other sites More sharing options...
balkan7 Posted November 5, 2006 Author Share Posted November 5, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.