ziedinjsh Posted September 22, 2011 Report Share Posted September 22, 2011 (edited) Sveiki! Lieta tāda, nospiežot submit pogu izmet erroru un pasaka, ka kāds no lauciņiem ir tukš, nospiežot otro reizi vieņš ppievieno datus arī tad ja kāds no lauciņiem ir pa tiešām tukšs. if($cat=="simple"){ $data = mysql_fetch_array(mysql_query("SELECT * FROM members WHERE email='".$_SESSION['email']."' LIMIT 1")); echo " <div id='result'></div> <form method='post' action='process/addsimple_process.php' id='addsimple'> <input type='hidden' name='author' value='".$data['username']."'><input type='hidden' name='mid' value='".$data['id']."'> <p class='title'>Virsraksts</p> <p><input type='text' name='title' class='input' style='width:590px;'></p> <p class='title'>Ievads</p> <p><textarea name='intro' class='introi'></textarea></p> <p class='title'>Raksts</p> <p><textarea name='article' class='articlei'></textarea></p> <p><input type='submit' name='simple' value='Pievienot' class='button'></p> </form> "; } $type = "simple"; $author = mysql_real_escape_string($_POST['author']); $mid = mysql_real_escape_string($_POST['mid']); $title = mysql_real_escape_string($_POST['title']); $intro = mysql_real_escape_string($_POST['intro']); $article = mysql_real_escape_string($_POST['article']); $date = date("d.m.Y"); $statuss = "ok"; if($author=="" || $mid==""){ $error = "<h3 style='color:#ff0000;font-size:20px;'>Kļūda! Ielogojies vai reģistrējies.</h3>"; $statuss = "error"; } if($title=="" || $intro=="" || $article==""){ $error = "<h3 style='color:#ff0000;font-size:20px;'>Kāds no lauciņiem ir palicis tukšs!</h3>"; $statuss = "error"; } if($statuss<>"ok"){ echo $error; }else{ mysql_query("INSERT INTO articles (type, author, mid, title, intro, article, date) VALUES ('$type', '$author', '$mid', '$title', '$intro', '$article', '$date')"); echo "<h3 style='color:green;font-style:20px;'>Paldies, raksts ir pievienots!</h3>"; echo "<meta http-equiv='refresh' content='2;url=index.php'>"; } $(document).ready(function() { $('#addsimple').submit(function() { $.ajax({ type: "POST", url: $('#addsimple').attr('action'), data: $('#addsimple').serialize(), success: function(data) { $('#result').html(data); } }); return false; }); }); Edited September 22, 2011 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
briedis Posted September 22, 2011 Report Share Posted September 22, 2011 Paskatoties vien uz šo paliek šķebīgi :( echo "<h3 style='color:green;font-style:20px;'>Paldies, raksts ir pievienots!</h3>"; echo "<meta http-equiv='refresh' content='2;url=index.php'>"; Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 22, 2011 Author Report Share Posted September 22, 2011 bet vai tad tā dēļ kods nestrādā? Quote Link to comment Share on other sites More sharing options...
No0ne Posted September 22, 2011 Report Share Posted September 22, 2011 (edited) un ja tu ieraksti pirms mysql_querya die($author); ko tev labu parada? Edited September 22, 2011 by No0ne Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted September 23, 2011 Author Report Share Posted September 23, 2011 (edited) vienreiz nospiežot parāda klūdu - kāds no lauciņiem ir palicis tukšs un nospiežot atkārtoti tad parāda lietotājvāru ar kuru esmu ielogojies un kurš būs tas author ja tu to biji domājis šādi: $type = "simple"; $author = mysql_real_escape_string($_POST['author']); $mid = mysql_real_escape_string($_POST['mid']); $title = mysql_real_escape_string($_POST['title']); $intro = mysql_real_escape_string($_POST['intro']); $article = mysql_real_escape_string($_POST['article']); $date = date("d.m.Y"); $statuss = "ok"; if($author=="" || $mid==""){ $error = "<h3 style='color:#ff0000;font-size:20px;'>Kļūda! Ielogojies vai reģistrējies.</h3>"; $statuss = "error"; } if($title=="" || $intro=="" || $article==""){ $error = "<h3 style='color:#ff0000;font-size:20px;'>Kāds no lauciņiem ir palicis tukšs!</h3>"; $statuss = "error"; } if($statuss<>"ok"){ echo $error; }else{ die($author); mysql_query("INSERT INTO articles (type, author, mid, title, intro, article, date) VALUES ('$type', '$author', '$mid', '$title', '$intro', '$article', '$date')"); echo "<h3 style='color:green;font-style:20px;'>Paldies, raksts ir pievienots!</h3>"; echo "<meta http-equiv='refresh' content='2;url=index.php'>"; } Edited September 23, 2011 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
briedis Posted September 23, 2011 Report Share Posted September 23, 2011 Tev ačgārna loģika - varbūt labāk dari tā, ka vispirms ir $statuss = "error"; un tad pārbaudi if(derigslietotajvards && cits lauks ok && ...){ status ok; } Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 16, 2011 Author Report Share Posted November 16, 2011 $first = mysql_real_escape_string($_POST['first']); $last = mysql_real_escape_string($_POST['last']); $nick = mysql_real_escape_string($_POST['nick']); $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $password2 = mysql_real_escape_string($_POST['password2']); $genere = mysql_real_escape_string($_POST['genre']); $date = date("d.m.Y"); $statuss= "error"; if($first && $last && $nick && $email && $password && $password2 && $genere){ $statuss = "ok"; }else{ $error = $lang['013']; $statuss = "error"; } bet kad tiek aizpildīti visi lauciņi vienalga izmet erroru! Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted November 16, 2011 Report Share Posted November 16, 2011 var_dump($_POST) Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted November 16, 2011 Author Report Share Posted November 16, 2011 es jau pārbaudīju ar to.. visi lauciņi bija pilni! Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 16, 2011 Report Share Posted November 16, 2011 Pamēģini pārbaudīt nevis kā if ($a && $b && $c), bet if (!empty($a) && !empty($b) && !empty($c)). http://lv.php.net/manual/en/language.operators.logical.php http://lv.php.net/empty Quote Link to comment Share on other sites More sharing options...
Kavacky Posted November 16, 2011 Report Share Posted November 16, 2011 Pirmkārt jau, tas jādara PIRMS lasīt no $_POST. Quote Link to comment Share on other sites More sharing options...
daGrevis Posted November 16, 2011 Report Share Posted November 16, 2011 Es jau nesaku, ka pēc. Zienišjsšš... nu ja patiešām jūti, ka neiet tev tā lieta - es nezinu; mēģini ko citu. Vai tad profesijas trūkst? Gribi mājaslapu? Maksā tiem, kas mājaslapas veido. Džīzas! 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.