Guteman
-
Posts
39 -
Joined
-
Last visited
Never
Posts posted by Guteman
-
-
Thanks alot with helping me here, it works now! :D Now on to deleting news posts, lol.
-
Alright now its getting somewhere, something small is still missing!
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]UPDATE news SET title='SST Website',post='Hello and Welcome to the SST-Website. This is the news script working.',user='Guteman' WHERE id='\".$id.\"'[/quote]
is what i got now
here is the full code (all 1 page)
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?
include("config.php");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select id, title from news order by id");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$id=$r["id"];//take out the id
$title=$r["title"];//take out the title
//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM news WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message:<TEXTAREA NAME="post" ROWS=10 COLS=30><? echo $myrow["post"] ?></TEXTAREA><br>
Who:<INPUT TYPE="TEXT" NAME="user" VALUE="<?php echo $myrow["user"] ?>" SIZE=30><br>
<input type="hidden" name="cmd" value="edit">
<input type='hidden' name='id' value='".$id."' />
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["submit"])
{
$title = $_POST["title"];
$post = $_POST["post"];
$user = $_POST["user"];
$id = $_POST["id"];
$sql = "UPDATE news SET title='$title',post='$post',user='$user' WHERE id='$id'";
print $sql;
die();
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>[/quote] -
No sir it is not, its getting the same thing as above.
-
ugh this is frusterating me. A question I have is in php myadmin its said as ID not id... is all this case sensitive? Do you see something wrong I did. Thanks very much for your help so far.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?
include("config.php");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select id, title from news order by id");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$id=$r["id"];//take out the id
$title=$r["title"];//take out the title
//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM news WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message:<TEXTAREA NAME="post" ROWS=10 COLS=30><? echo $myrow["post"] ?></TEXTAREA><br>
Who:<INPUT TYPE="TEXT" NAME="user" VALUE="<?php echo $myrow["user"] ?>" SIZE=30><br>
<input type="hidden" name="cmd" value="edit">
<input type='hidden' value='".$id."' />
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["submit"])
{
$title = $_POST["title"];
$post = $_POST["post"];
$user = $_POST["user"];
$id = $_POST["id"];
$sql = "UPDATE news SET title='$title',post='$post',user='$user' WHERE ID='$id'";
print $sql;
die();
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>
[/quote] -
I do believe you are right.. Heres what I got:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]UPDATE news SET title='SST Website',post='Hello and Welcome to the SST-',user='Guteman' WHERE id=''[/quote]
How do I go about defining the id variable? -
lol sorry It doesnt make sense to me :( Is there any other way you can put it?
-
[!--quoteo(post=353050:date=Mar 8 2006, 04:57 PM:name=lessthanthree)--][div class=\'quotetop\']QUOTE(lessthanthree @ Mar 8 2006, 04:57 PM) [snapback]353050[/snapback][/div][div class=\'quotemain\'][!--quotec--]
if ($_POST["$submit"])
should be if ($_POST["submit"])
for good measure, i'd do: if (isset($_POST["submit"]))
Just to add, you having some security flaws in there that open your site up to sql injection. You should clean the values to make them as injection proof as possible.
look at using functions like addslashes() to protect your site from malicious attacks.
[/quote]
This did not fix it :(
-
Okay so now I got all the fields to show up correctly, now when I click submit to change a news post, nothing changes in the news! Ima need someones help again.
Here is the code again.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?
include("config.php");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select id, title from news order by id");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$id=$r["id"];//take out the id
$title=$r["title"];//take out the title
//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM news WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message:<TEXTAREA NAME="post" ROWS=10 COLS=30><? echo $myrow["post"] ?></TEXTAREA><br>
Who:<INPUT TYPE="TEXT" NAME="user" VALUE="<?php echo $myrow["user"] ?>" SIZE=30><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$title = $_POST["title"];
$post = $_POST["post"];
$user = $_POST["user"];
$sql = "UPDATE news SET title='$title',post='$post',user='$user' WHERE id='$id'";
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>[/quote] -
Problem is fixed. Thank you!
-
someone please help.
-
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]echo "<a href=\"edit.php?cmd=edit&id=$id\">$title - Edit</a>";[/quote]
Still doesnt seem to work. Same problem -
Alright guys, here is my issue. I cannot get [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<a href='edit.php?cmd=edit&id=$id'>[/quote] to work properly. Specificly the $id part. Its not seeing the id in the news through the sql. I know the rest of this works because I can enter an id number after the link and it works. So its gotta be that variable. Can you please help me out?
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?
include("config.php");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select * from news order by id");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$title=$r["title"];//take out the title
$id=$r["id"];//take out the id
//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM news WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message:<TEXTAREA NAME="message" ROWS=10 COLS=30><? echo $myrow["message"] ?></TEXTAREA><br>
Who:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["who"] ?>" SIZE=30><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$title = $_POST["title"];
$message = $_POST["message"];
$who = $_POST["who"];
$sql = "UPDATE news SET title='$title',message='$message',who='$who' WHERE id=$id";
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>[/quote] -
Alright guys, here is my issue. I cannot get [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<a href='edit.php?cmd=edit&id=$id'>[/quote] to work properly. Specificly the $id part. Its not seeing the id in the news through the sql. I know the rest of this works because I can enter an id number after the link and it works. So its gotta be that variable. Can you please help me out?
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<?
include("config.php");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the news
$result = mysql_query("select * from news order by id");
//run the while loop that grabs all the news scripts
while($r=mysql_fetch_array($result))
{
//grab the title and the ID of the news
$title=$r["title"];//take out the title
$id=$r["id"];//take out the id
//make the title a link
echo "<a href='edit.php?cmd=edit&id=$id'>$title - Edit</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM news WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
Title:<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message:<TEXTAREA NAME="message" ROWS=10 COLS=30><? echo $myrow["message"] ?></TEXTAREA><br>
Who:<INPUT TYPE="TEXT" NAME="who" VALUE="<?php echo $myrow["who"] ?>" SIZE=30><br>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</form>
<? } ?>
<?
if ($_POST["$submit"])
{
$title = $_POST["title"];
$message = $_POST["message"];
$who = $_POST["who"];
$sql = "UPDATE news SET title='$title',message='$message',who='$who' WHERE id=$id";
//replace news with your table name above
$result = mysql_query($sql);
echo "Thank you! Information updated.";
}
}
?>[/quote]
PHP Layout
in PHP Coding Help
Posted