dsp77 Posted October 13, 2009 Share Posted October 13, 2009 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 . Quote Link to comment Share on other sites More sharing options...
GKWelding Posted October 13, 2009 Share Posted October 13, 2009 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. Quote Link to comment Share on other sites More sharing options...
dsp77 Posted October 13, 2009 Author Share Posted October 13, 2009 same thing now i notice that the page is loading untill error with your code and mine and still no change Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted October 13, 2009 Share Posted October 13, 2009 what is the error message? Quote Link to comment Share on other sites More sharing options...
dsp77 Posted October 13, 2009 Author Share Posted October 13, 2009 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. Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted October 13, 2009 Share Posted October 13, 2009 try changing: header("location:edit.php"); to: header ("Location: http://www.site.com"); Quote Link to comment Share on other sites More sharing options...
dsp77 Posted October 13, 2009 Author Share Posted October 13, 2009 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 Quote Link to comment Share on other sites More sharing options...
dsp77 Posted October 13, 2009 Author Share Posted October 13, 2009 i know that headers error may be because of spaces before and after the code i checked and didn't find any the error is more because of session start in config file Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted October 13, 2009 Share Posted October 13, 2009 In the final code you posted, are the variables you're using ($start, etc.) defined? Should they be $_POST variables instead? Quote Link to comment Share on other sites More sharing options...
dsp77 Posted October 13, 2009 Author Share Posted October 13, 2009 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:( Quote Link to comment Share on other sites More sharing options...
johnsmith153 Posted October 13, 2009 Share Posted October 13, 2009 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 Quote Link to comment Share on other sites More sharing options...
ialsoagree Posted October 13, 2009 Share Posted October 13, 2009 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? Quote Link to comment Share on other sites More sharing options...
dsp77 Posted October 14, 2009 Author Share Posted October 14, 2009 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"); ?> Quote Link to comment Share on other sites More sharing options...
dsp77 Posted October 14, 2009 Author Share Posted October 14, 2009 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>"; ?> 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.