Jump to content

Some problems with GET


Guest

Recommended Posts

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: 

  1. $query = mysql_query ("SELECT * FROM news WHERE id='$id'");
  2. is working.
Edited by AxelhacK
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 12
UPDATE 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 by AxelhacK
Link to comment
Share on other sites

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.

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.