Undefined index

2

Undefined index

offline
  • lnenad  Male
  • Stručni saradnik
    Web
  • Nenad
  • Arhitetak
  • Pridružio: 16 Jan 2007
  • Poruke: 2860
  • Gde živiš: Bijeljina

Nema ovdje sta da se sredjuje

Napravi dvije stranice od toga

index.php

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Comment box</title> </head> <body> <center> <form action="submit.php" method="POST"> <table> <tr><td>Name: <br><input type="text" name="name"/></td></tr> <tr><td colspan="2">Comment: </td></tr> <tr><td colspan="5"><textarea name="comment" rows="10" cols="50"></textarea></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr> </table> </form> <?php $dbLink = mysql_connect("localhost", "root", "");    mysql_query("SET character_set_results=utf8", $dbLink);    mb_language('uni');    mb_internal_encoding('UTF-8'); $getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC"); while($rows=mysql_fetch_assoc($getquery)) { $id=$rows['id']; $name=$rows['name']; $comment=$rows['comment']; echo $name . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="1"/>' ;} ?> </body> </html>

submit.php

<?php mysql_connect("localhost","root",""); mysql_select_db("commentbox"); $name=$_POST['name']; $comment=$_POST['comment']; $submit=$_POST['submit']; $dbLink = mysql_connect("localhost", "root", "");    mysql_query("SET character_set_client=utf8", $dbLink);    mysql_query("SET character_set_connection=utf8", $dbLink); if($submit) { if($name&&$comment) { $insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') "); } else { echo "please fill out all fields"; } } ?>

Ili ako hoces sve u jednu

index.php

<?php if (isset($_GET['go'])) { mysql_connect("localhost","root",""); mysql_select_db("commentbox"); $name=$_POST['name']; $comment=$_POST['comment']; $submit=$_POST['submit']; $dbLink = mysql_connect("localhost", "root", "");    mysql_query("SET character_set_client=utf8", $dbLink);    mysql_query("SET character_set_connection=utf8", $dbLink); if($submit) { if($name&&$comment) { $insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') "); } else { echo "please fill out all fields"; } } } // if go ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Comment box</title> </head> <body> <center> <form action="index.php?go=set" method="POST"> <table> <tr><td>Name: <br><input type="text" name="name"/></td></tr> <tr><td colspan="2">Comment: </td></tr> <tr><td colspan="5"><textarea name="comment" rows="10" cols="50"></textarea></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr> </table> </form> <?php $dbLink = mysql_connect("localhost", "root", "");    mysql_query("SET character_set_results=utf8", $dbLink);    mb_language('uni');    mb_internal_encoding('UTF-8'); $getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC"); while($rows=mysql_fetch_assoc($getquery)) { $id=$rows['id']; $name=$rows['name']; $comment=$rows['comment']; echo $name . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="1"/>' ;} ?> </body> </html>



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • Pridružio: 08 Sep 2011
  • Poruke: 70

Nenade hvala ti na pomoći ali i kad tako stavim kod u jednu stranu opet prikazuje grešku na 51 liniji (oko while petlje).
Ovaj ceo kod treba napisati iz početka a to mi nepada napamet jer sasvim uredno radi. Rešio sam problem sa error_reporting(0); i to je moguće rešenje.



offline
  • lnenad  Male
  • Stručni saradnik
    Web
  • Nenad
  • Arhitetak
  • Pridružio: 16 Jan 2007
  • Poruke: 2860
  • Gde živiš: Bijeljina

error_reporting nije rjesenje, to je sakrivanje prikaza gresaka krajnjem korisniku, greska postoji jos uvijek.

Ajde reci sta ti prijavljuje, ne odustaj tako lako Smile

offline
  • Pridružio: 08 Sep 2011
  • Poruke: 70

Ovo je taj isti kod prerađen i nema grešaka ali mu neradi funkcija if (molim upišite ime); eto sad to neće, ne znam kako da uradim!? Znači kad pritisneš dugme Submit a ne napišeš ime Name: neće da izbaci "molim upišite ime" na istoj stranici.
<?php

$dbLink = mysql_connect("localhost", "root", "");

mysql_select_db("commentbox");

if(!empty($_POST['name']) && !empty($_POST['comment']))
{
$name= $_POST['name'];
$comment= $_POST['comment'];
$submit= $_POST['submit'];


mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);

if($submit)
{
if($name && $comment)
{
$insert=mysql_query("INSERT INTO commenttable (name,comment) VALUES ('$name','$comment') ");
}
else
{
echo "molim upišite ime!";
}
}
}
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comment box</title>
</head>

<body>
<center>
<form action="commentindex.php" method="post">
<table>
<tr><td>Name: <br><input type="text" name="name"/></td></tr>
<tr><td colspan="2">Comment: </td></tr>
<tr><td colspan="5"><textarea name="comment" rows="10" cols="50"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr>
</table>
</form>

<?php

$getquery=mysql_query("SELECT * FROM commenttable ORDER BY id DESC");
while($rows=mysql_fetch_assoc($getquery))
{
$id=$rows['id'];
$name=$rows['name'];
$comment=$rows['comment'];
echo $name . '<br/>' . '<br/>' . $comment . '<br/>' . '<br/>' . '<hr size="1"/>'
;}
?>

</body>
</html>

offline
  • lnenad  Male
  • Stručni saradnik
    Web
  • Nenad
  • Arhitetak
  • Pridružio: 16 Jan 2007
  • Poruke: 2860
  • Gde živiš: Bijeljina

Ubuduce stavljaj   tagove

Ispravi ovo

if($submit) { if($name && $comment)

u ovo

if(isset($submit)) { if(isset($name) && isset($comment))

offline
  • Pridružio: 08 Sep 2011
  • Poruke: 70

Nenade hvala na pomoći i ostalima.

Ko je trenutno na forumu
 

Ukupno su 1115 korisnika na forumu :: 25 registrovanih, 4 sakrivenih i 1086 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: 357magnum, BlekMen, bokisha253, Dogma21, draganl, Frunze, Georgius, HogarStrashni, Kibice, Kubovac, LUDI, Mercury, Milan A. Nikolic, milenko crazy north, Milometer, milutin134, MiroslavD, mnn2, Nikola00, Sir Budimir, Skywhaler, Snorks, styg, wizzardone, zastavnik