Jump to content

zirgs

Members
  • Posts

    25
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

zirgs's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi. I have very simple question about mysql ... can someone tell me function that checks if query was successfull? or just use somth like that? [code] if (!$query) { echo "Not good ;("; } ) [/code]
  2. hello, can anyone can give me some clue how to restrict posting codes(html's,js's,php's) and so on, i mean in guestbooks and like that. thanks.
  3. ok it didn't work for me what i wanted .... ok anyone knows how to check if form was submited or not (i mean if submit button was pressed) ... any help?
  4. ok i'll try it out later.thanks.
  5. hi there i'm using this code [code] <?php if ( $_POST['author']=="name" || $_POST['comment']=="comment" ) { if (isset($_POST)) { echo "Some fields were left blank!"; } } elseif ( $_POST['author']=="" || $_POST['comment']=="" ) { if (!isset($_POST)) { echo "Some fields were left blank!"; } } else { include 'db_connect.php'; $date = date('d/m/Y G:i'); $query="INSERT INTO comments (newid,author,comment,date) VALUES ('$_POST[id]','$_POST[author]','$_POST[comment]','$date')"; if(mysql_db_query($current_db,$query)) { echo "Comment added!"; mysql_close($database); } } ?> [/code] it works fine until i press submit when there isn't anything writen into fields.I need to then show "Some fields were left blank!" anyone help ? what i'm doing wrong?thanks.
  6. thanks, [b]wildteen88[/b]. I've just modified it a bit because there was one error ... but now my problem is solved. cheers! [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
  7. ok i'll make it "more english" [code] <?php include 'db_con.php'; $numb = $_GET['numb']; settype($numb,"integer"); if(!empty($_GET['numb'])) { $sql = mysql_query("select * from news where id = '$numb'"); $num = mysql_num_rows($sql); $sql_coments= mysql_query("select * from coments where newsid = '$numb' order by id desc"); if($num == 1) { $row = mysql_fetch_array($sql); $row_coments = mysql_fetch_array($sql_coments); $title = $row["title"]; $date = $row["date"]; $new = $row["new"]; $shortnew = $row["shortnew"]; $author = $row_k["author"]; // coment author $coment = $row_k["coment"]; // coment $comentdate = $row_k["comentdate"]; // date of the coment echo "<span id=virs>"; echo $title; echo "</span><br />"; echo "<span id=dat>"; echo $date; echo "</span><br />"; echo $new; echo "<br /><br /><br /><br /><br />"; while($row_coments = mysql_fetch_array($sql_coments)) { echo "<span id=au>"; echo $author; echo "</span><br />"; echo "<span id=dat>"; echo $comentdate; echo "</span><br />"; echo $coment; echo "<br /><br />"; } } } if(empty($_GET['numb']) OR $num <> 1) { $sql = mysql_query("select * from zinjas order by id desc"); while($row = mysql_fetch_array($sql)) { echo "<span id=virs><a href=zinjas.php?numb="; echo $row["id"]; echo ">"; echo $row["title"]; echo "</a></span><br />"; echo "<span id=dat>"; echo $row["date"]; echo "</span><br />"; echo $row["shortnew"]; echo "<br /><br />"; echo "<div class=komentari>"; echo "<a href=zinjas.php>Coments</a>"; echo "</div>";    } } ?> [/code] now you should understand which part is coment part ... any solutions?
  8. change [code] echo $row[0]; [/code] to this one [code] echo $row['0']; [/code] but i think that you cant echo non existing row?
  9. Ok i changed my code to this one: [code] <?php include 'db_con.php'; $numb = $_GET['numb']; settype($numb,"integer"); if(!empty($_GET['numb'])) { $sql = mysql_query("select * from news where id = '$numb'"); $num = mysql_num_rows($sql); $sql_k = mysql_query("select * from komentari where zinjuid = '$numb' order by id desc"); if($num == 1) { $row = mysql_fetch_array($sql); $row_k = mysql_fetch_array($sql_k); $t = $row["t"]; $d = $row["d"]; $n = $row["n"]; $iz = $row["iz"]; $au = $row_k["au"]; $co = $row_k["co"]; $cod = $row_k["cod"]; echo "<span id=virs>"; echo $t; echo "</span><br />"; echo "<span id=dat>"; echo $d; echo "</span><br />"; echo $n; echo "<br /><br /><br /><br /><br />"; while($row_k = mysql_fetch_array($sql_k)) { echo "<span id=au>"; echo $au; echo "</span><br />"; echo "<span id=dat>"; echo $cod; echo "</span><br />"; echo $co; echo "<br /><br />"; } } } if(empty($_GET['numb']) OR $num <> 1) { $sql = mysql_query("select * from zinjas order by id desc"); while($row = mysql_fetch_array($sql)) { echo "<span id=virs><a href=zinjas.php?numb="; echo $row["id"]; echo ">"; echo $row["t"]; echo "</a></span><br />"; echo "<span id=dat>"; echo $row["d"]; echo "</span><br />"; echo $row["iz"]; echo "<br /><br />"; echo "<div class=komentari>"; echo "<a href=zinjas.php>Komentari</a>"; echo "</div>";    } } ?> [/code] it still echoes out only one comment ... maybe i'm using while in this case wrong? sorry i'm not yet familiar with php where is involved mysql ...
  10. Hello i'm now using this scripts for news display but i need to show each news coments, but with this code i'm having trouble that it shows only 1 coment (but in database is more than one) ... can you help me out? code: [code] <?php include 'db_con.php'; $numb = $_GET['numb']; settype($numb,"integer"); if(!empty($_GET['numb'])) { $sql = mysql_query("select * from news where id = '$numb'"); $num = mysql_num_rows($sql); $sql_k = mysql_query("select * from komentari where zinjuid = '$numb' order by id desc"); if($num == 1) { $row = mysql_fetch_array($sql); $row_k = mysql_fetch_array($sql_k); $t = $row["t"]; $d = $row["d"]; $n = $row["n"]; $iz = $row["iz"]; $au = $row_k["au"]; $co = $row_k["co"]; $cod = $row_k["cod"]; echo "<span id=virs>"; echo $t; echo "</span><br />"; echo "<span id=dat>"; echo $d; echo "</span><br />"; echo $n; echo "<br /><br /><br /><br /><br />"; echo "<span id=au>"; echo $au; echo "</span><br />"; echo "<span id=dat>"; echo $cod; echo "</span><br />"; echo $co; echo "<br /><br />"; } } if(empty($_GET['numb']) OR $num <> 1) { $sql = mysql_query("select * from zinjas order by id desc"); while($row = mysql_fetch_array($sql)) { echo "<span id=virs><a href=zinjas.php?numb="; echo $row["id"]; echo ">"; echo $row["t"]; echo "</a></span><br />"; echo "<span id=dat>"; echo $row["d"]; echo "</span><br />"; echo $row["iz"]; echo "<br /><br />"; echo "<div class=komentari>"; echo "<a href=zinjas.php>Komentari</a>"; echo "</div>";    } } ?>[/code]
  11. thanks for the advices i've just realised that it was strupid to first do connection to database and then check for empty fields ... i've made first check and then connection and query ... and no errors [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] cheers!
  12. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] <?php $db_username = "*****"; $db_pasword = "*****"; $db_host = "******"; $db = "news"; @mysql_connect($db_host, $db_username, $db_pasword) or die("Can't connect to database!"); @mysql_select_db($db) or die("Can't select database!"); if ( $_POST['title'] == "" || $_POST['date'] == "" ) ( echo "Some fields were left blank!"; ) elseif ( $_POST['new'] == "" ) ( echo "You didn't entered the new!"; ) else ( $query="INSERT INTO news (title,date,new,short_news) VALUES ('$_POST['title']','$_POST['date']','$_POST['new']','$_POST['short_new']')"; if(!mysql_db_query($db,$query)) die(mysql_error()); echo "News added succesfully!"; ) ?>[/quote]
  13. i thought that it's not obligatory... but it's something in this line i think because it's 12 line [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]echo "Some fields were left blank!";[/quote] sorry for so much questions but i really want to figure it out :)
×
×
  • 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.