balkan7 Posted November 1, 2006 Share Posted November 1, 2006 i need help why not update in date base, what is wrong here:[code]<?php 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());//if no rows returned...if(mysql_num_rows($query) == 0){echo "That ID is not in the database!";}//else, if set izmeni (change)!else{if(isset($_POST['izmeni']))//update for this product!$popravi = 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 "Product has been successfull update!";//loop through the databasewhile($row = mysql_fetch_array($query)){echo "<br><form action='index.php?action=popravi' method='post' name='izmeni'><div align='center'><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>";//categorys and putting them into a select//so the user can select which category$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>";//categorys and putting them into a select//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 />$row[naslov]</td> </tr><tr>";}//----------------------------//if 1 = New while 0 = Nothing//----------------------------$new = "Novo";if($row['novo'] == 1){echo "$new";}echo "</tr>";}}break; ?>[/code] Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/ Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 Do you get an error? Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-117907 Share on other sites More sharing options...
balkan7 Posted November 1, 2006 Author Share Posted November 1, 2006 no, not show error, just not update in date base. Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-117910 Share on other sites More sharing options...
trq Posted November 1, 2006 Share Posted November 1, 2006 You really need to learn to indent your code. Its near impossible to read.Where are all tose variables in your query being set? Also... Try storing your query in a variable then echo'ing that variable for debuuging puposes. Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-117911 Share on other sites More sharing options...
balkan7 Posted November 1, 2006 Author Share Posted November 1, 2006 im soryy really i need time for translate code, but i think maybe here is error for not take action in date base.[code]if(isset($_POST['izmeni']))//update for this product!$popravi = 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 "Product has been successfull update!";[/code] Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-117919 Share on other sites More sharing options...
bljepp69 Posted November 1, 2006 Share Posted November 1, 2006 you either need to do this:[code]mysql_query("UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'") or die(mysql_error());[/code]or, something like:[code]$popravi = mysql_query("UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'");if ($popravi) echo "Product has been successfully updated!";else echo "Error: ".mysql_error();[/code]The problem is you are assigning the query to a variable, but not doing anything with that variable that would cause the update query to run. Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-117929 Share on other sites More sharing options...
balkan7 Posted November 1, 2006 Author Share Posted November 1, 2006 Parse error: syntax error, unexpected T_IF in /home/xxx/public_html/test/index.php on line 270[color=red]line 270 -> if ($popravi)[/color] Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-117937 Share on other sites More sharing options...
trq Posted November 1, 2006 Share Posted November 1, 2006 I'll say it again.[quote]Try storing your query in a variable then echo'ing that variable for debuuging puposes.[/quote]Now, an example.[code=php:0]$sql = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'";echo $sql;[/code]What does your query actually look like? Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-117944 Share on other sites More sharing options...
balkan7 Posted November 1, 2006 Author Share Posted November 1, 2006 thorpe yes i know but before when i try to edit some product query work perfect, but now everything its ok in input types show values and you can edit product, but when you click button for Update just show Blank page, not show mysql error or [color=blue]echo "Product has been successfully updated!";[/color], also i copy code in new file, now is change.php but nothing again.[code]<?php//------------------------------------------//database connection$db = mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());mysql_select_db("xxx") or die(mysql_error());//end database connection//------------------------------------------//------------------------------------------//echo out a navigation panelecho "<center><a href='index.php'>Pregled na Kategoerii</a> | <a href='index.php?action=dodaj'>Dodaj SoftwareAdd Tutorial</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()); //if no rows returned... if(mysql_num_rows($query) == 0) { echo "That ID is not in the database!"; } //else, show it! if(isset($_POST['izmeni'])) { //update the views for this tutorial! $popravi2 = 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 "Product has benn successfull update"; } else { //loop through the database while($row = mysql_fetch_array($query)) { echo "<br> <form action='$self?action=popravi' method='post' name='izmeni'> <div align='center'> <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> "; //now what we are doing here is looping through //the categorys table and getting all the //categorys and putting them into a select //so the user can select which category //the tutorial is on $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> "; //now what we are doing here is looping through //the categorys table and getting all the //categorys and putting them into a select //so the user can select which category //the tutorial is on $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> "; } } //---------------------------- //this part of the code //checks to see if the submitter //wants an email left for support //---------------------------- $new = "Novo"; if($row['novo'] == 1) { echo "$new"; } echo " </tr> "; } } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118116 Share on other sites More sharing options...
balkan7 Posted November 1, 2006 Author Share Posted November 1, 2006 now i change the code, when i click to Button for Submit, [color=red]echo Error cannot write in DB![/color], can someone help me ?[code]<?php//------------------------------------------//database connectionmysql_connect("localhost", "xxx", "xxx") or die(mysql_error());mysql_select_db("xxx") or die(mysql_error());//end database connection//------------------------------------------//------------------------------------------//echo out a navigation panelecho "<center><a href='index.php'>Pregled na Kategoerii</a> | <a href='index.php?action=dodaj'>Dodaj SoftwareAdd Tutorial</a></center>";switch($_GET['action']){ case "popravi"://if there is an ID given..if(isset($_POST['izmeni'])) { //update the views for this tutorial! $popravi2 = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'"; $rezultat = mysql_query($popravi2); if ($result) echo "<p>Product has been successfull UPDATE!</p>"; else echo "<p>Error cannot write in DB!</p>";} else { 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()); //if no rows returned... if(mysql_num_rows($query) == 0) { echo "That ID is not in the database!"; } //else, show it! else { //loop through the database while($row = mysql_fetch_array($query)) { echo "<br> <form action='$PHP_SELF?action=popravi' method='post'> <div align='center'> <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> "; //now what we are doing here is looping through //the categorys table and getting all the //categorys and putting them into a select //so the user can select which category //the tutorial is on $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> "; //now what we are doing here is looping through //the categorys table and getting all the //categorys and putting them into a select //so the user can select which category //the tutorial is on $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 1 = New while 0 = Nothing //---------------------------- $new = "Novo"; if($row['novo'] == 1) { echo "$new"; } echo " </tr> "; } } } ?>[/code] Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118166 Share on other sites More sharing options...
trq Posted November 1, 2006 Share Posted November 1, 2006 Echo your query!!! Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118174 Share on other sites More sharing options...
balkan7 Posted November 1, 2006 Author Share Posted November 1, 2006 i think error is here,[code]if(isset($_POST['izmeni'])) { //update for this product! $popravi2 = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'"; $rezultat = mysql_query($popravi2); if ($result) echo "<p>Product has been successfull UPDATE!</p>"; else echo "<p>Error cannot write in DB!</p>";} [/code] Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118182 Share on other sites More sharing options...
gmwebs Posted November 1, 2006 Share Posted November 1, 2006 Seriously... Change your code to echo out your query... When you have done it, post the output here.[code]<?phpif(isset($_POST['izmeni'])) { //update for this product! $popravi2 = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'"; echo $popravi2; //Let's see what the query consists of exit(); //Exit the script so that you can see the query $rezultat = mysql_query($popravi2); if ($result) echo "<p>Product has been successfull UPDATE!</p>"; else echo "<p>Error cannot write in DB!</p>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118186 Share on other sites More sharing options...
jsladek Posted November 2, 2006 Share Posted November 2, 2006 Also Look at this section is $rezultat the same as $result? I speak english only... $rezultat = mysql_query($popravi2); if ($result) echo "<p>Product has been successfull UPDATE!</p>"; Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118195 Share on other sites More sharing options...
balkan7 Posted November 2, 2006 Author Share Posted November 2, 2006 i change my mastake in [code]<?phpif(isset($_POST['izmeni'])) { //update for this product! $popravi2 = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'"; echo $popravi2; //Let's see what the query consists of exit(); //Exit the script so that you can see the query $result = mysql_query($popravi2); if ($result) echo "<p>Product has been successfull UPDATE!</p>"; else echo "<p>Error cannot write in DB!</p>";}?>[/code]now write [color=blue]Product has been successfull UPDATE![/color], but not change values ! Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118348 Share on other sites More sharing options...
trq Posted November 2, 2006 Share Posted November 2, 2006 Can we see what the echo of the query produces? Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118368 Share on other sites More sharing options...
balkan7 Posted November 2, 2006 Author Share Posted November 2, 2006 look this:[code]$popravi2 = "UPDATE software SET naslov = '$naslov', opis = '$opis', kat_id = '$kategorija', cd_id = '$cd', novo = '$novo' WHERE id = '$id'";[/code]so i have in value: [code]<td><input type='text' name='naslov' value='$row[naslov]'></td>[/code]maybe for this not query. Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118389 Share on other sites More sharing options...
jsladek Posted November 3, 2006 Share Posted November 3, 2006 what did the Line...[font=Verdana]echo $popravi2; //Let's see what the query consists of[/font]Print out on the screen? Link to comment https://forums.phpfreaks.com/topic/25822-update-not-working/#findComment-118829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.