Guest Posted July 25, 2013 Share Posted July 25, 2013 (edited) Hello, <?php require('../db_connect.php'); mysql_select_db('news'); $headline = $_POST['headline']; $author = $_POST['author']; $text = $_POST['text']; $id = $_GET['id']; - My Problem if(isset($_POST['Aktualisieren'])) { $head2 = $_POST['headline']; $text2 = $_POST['text']; $author2 = $_POST['author']; $date2 = date('Y-m-d'); if ($head2 !="" || $text2 !="" || $author2 !="") { $updatequery = "UPDATE news SET headline='$head2', author='$author2', text='$text2', date='$date2' WHERE id='$id'"; mysql_query($updatequery) or die('error'); printf($updatequery); //echo 'Ersetzt'; //header("Location: http://localhost/project1/News/news2.php"); } else { echo 'Bitte fülen Sie alle Felder aus'; } } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Submit</title> <script src="../ckeditor/ckeditor.js"></script> </head> <body> <?php $query = mysql_query ("SELECT * FROM news WHERE id='$id'"); while($row = mysql_fetch_array($query)) { echo "<form action=update2.php method=POST>"; echo "<tr>"; echo "<td><input type='hidden' name='headline' value='" . $row['headline'] . "'> </td>"; echo "<td><input type='hidden' name='author' value='" . $row['author'] . "'> </td>"; echo "<td><input type='hidden' name='text' value='" . $row['text'] . "'> </td>"; echo "<td><input type='submit' name='update' value='get'" . " </td>"; echo "</form>"; } echo "<form action=update2.php method=POST>"; echo "<tr>"; echo "<td> Überschrift: </td> <input name='headline' type='text' value='$headline' /> <br />"; echo "<td> von: </td> <input name='author' type='text' value='$author' /> </td><br />"; echo "<p> <textarea name='textar'>$text</textarea></p><br />"; ?> <script> CKEDITOR.replace( 'textar', { toolbar : 'basic', uiColor : '# 9AB8F3', enterMode : CKEDITOR.ENTER_BR, shiftEnterMode : CKEDITOR.ENTER_P }); </script></td> <?php echo "<input name='Aktualisieren' type='submit' value='Aktualisieren'/>"; echo "</tr>"; echo "</form>"; ?> </body> <link href='../css/main.css' rel="stylesheet" type="text/css" /> </html> from the page news2.php I get the ID, but when I use this form { echo "<form action=update2.php method=POST>"; echo "<tr>"; echo "<td><input type='hidden' name='headline' value='" . $row['headline'] . "'> </td>"; echo "<td><input type='hidden' name='author' value='" . $row['author'] . "'> </td>"; echo "<td><input type='hidden' name='text' value='" . $row['text'] . "'> </td>"; echo "<td><input type='submit' name='update' value='get'" . " </td>"; echo "</form>"; } the ID diseappears and I need it for the $updatequery $updatequery = "UPDATE news SET headline='$head2', author='$author2', text='$text2', date='$date2' WHERE id='$id'"; How could I fix it? Sorry for my english. EDIT: $query = mysql_query ("SELECT * FROM news WHERE id='$id'"); is working. Edited July 25, 2013 by AxelhacK Quote Link to comment https://forums.phpfreaks.com/topic/280496-some-problems-with-get/ Share on other sites More sharing options...
boompa Posted July 25, 2013 Share Posted July 25, 2013 The answer is no different from the one in your other thread. If you want to pass a variable through GET, it must be in the URL. The difference is the URL is in the form's action. Quote Link to comment https://forums.phpfreaks.com/topic/280496-some-problems-with-get/#findComment-1442085 Share on other sites More sharing options...
Guest Posted July 25, 2013 Share Posted July 25, 2013 Bad news sir. Quote Link to comment https://forums.phpfreaks.com/topic/280496-some-problems-with-get/#findComment-1442087 Share on other sites More sharing options...
Guest Posted July 25, 2013 Share Posted July 25, 2013 I tried to fix it this way. $query = mysql_query ("SELECT * FROM news WHERE id='$id'"); while($row = mysql_fetch_array($query)) echo "<form action=update2.php method=POST>"; echo "<tr>"; echo "<td> Überschrift: </td> <input name='headline' type='text' value=".$row['headline']." /> <br />"; echo "<td> von: </td> <input name='author' type='text' value='".$row['author']."' /> </td><br />"; echo "<p> <textarea name='textar'>$row[text]</textarea></p><br />"; ?> .$row['headline']. .$row['author']. $row[text] do not output the text. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/280496-some-problems-with-get/#findComment-1442088 Share on other sites More sharing options...
Guest Posted July 25, 2013 Share Posted July 25, 2013 (edited) i fixed the form this way: <?php $query = mysql_query ("SELECT * FROM news WHERE id='$_GET[id]'"); while($row = mysql_fetch_array($query)){ echo "<form action=update2.php method=post>"; echo "<td> Titel:<input type='text' name='headline' value='" . $row['headline'] . "'> <br /> </td>"; echo "<td> Autor:<input type='text' name='author' value='" . $row['author'] . "'> </td>"; echo "<p><textarea name='textar'>".$row['text']."</textarea></p><br />"; ?> <script> CKEDITOR.replace( 'textar', { toolbar : 'basic', uiColor : '# 9AB8F3', enterMode : CKEDITOR.ENTER_BR, shiftEnterMode : CKEDITOR.ENTER_P }); </script></td> <?php echo "<input name='Aktualisieren' type='submit' value='Aktualisieren'/>"; echo "</tr>"; echo "</form>"; } ?> but still cant fix this $updatequery = "UPDATE news SET headline='$head2', author='$author2', text='$text2', date='$date2' WHERE id='$_GET[id]'"; mysql_query($updatequery) or die('error'); printf($updatequery); Notice: Undefined index: id in C:\xampp\htdocs\Project1\News\update2.php on line 12UPDATE news SET headline='asdf', author='admin', text='sdfhsdg', date='2013-07-25' WHERE id='' Notice: Undefined index: id in C:\xampp\htdocs\Project1\News\update2.php on line 39 Edited July 25, 2013 by AxelhacK Quote Link to comment https://forums.phpfreaks.com/topic/280496-some-problems-with-get/#findComment-1442097 Share on other sites More sharing options...
cyberRobot Posted July 26, 2013 Share Posted July 26, 2013 When update2.php was called, did you pass the id variable? For example: ...update2.php?id=3 Quote Link to comment https://forums.phpfreaks.com/topic/280496-some-problems-with-get/#findComment-1442267 Share on other sites More sharing options...
cyberRobot Posted July 26, 2013 Share Posted July 26, 2013 I just re-read the post. The GET variable needs to be added to the form tag as boompa suggested. <?php echo "<form action='update2.php?id={$row['id']}' method='post'>"; ?> Of course, $row['id'] would need to be changed to whatever variable you're using within the form script. Quote Link to comment https://forums.phpfreaks.com/topic/280496-some-problems-with-get/#findComment-1442268 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.