Jump to content
php.lv forumi

kāds var palīdzēt? ar sql un php


bbaigaa

Recommended Posts

<div id="container">

 

<div id="layoutCenterBody">

 

 

<div id="layoutNavigation">

Jūs esat pietei<?php

// pareizais locījums

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="jumitis"; // Database name

$tbl_name="lietotaji"; // Table name

 

// Connect to server and select databse.

$conn=mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

mysql_query( "SET NAMES UTF8", $conn);

 

$user=$_SESSION['useris'];

$sql="SELECT * FROM $tbl_name WHERE username='$user'";

$result=mysql_query($sql);

 

$row = mysql_fetch_array($result);

if(substr($row['vards'], -1) == "s")

{

echo "cies kā ".$row['vards']." ".$row['uzvards']."! ";

} else

{

echo "kusies kā ".$row['vards']." ".$row['uzvards']."! ";

}

?>

<a href="logout.php" style="text-decoration: underline; ">Iziet</a>

</div>

 

 

<div id="layoutBodyContent">

<?php

// izvēlamies pareizo tabulu

$tbl_name = "tema";

$conn=mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

mysql_query( "SET NAMES UTF8", $conn);

 

// atlasa foruma tēmas no datu bāzes un sakārto tās pēc ID dilstošā secībā

// jeb pēdējais ievietotais tiek rādīts kā pirmais

$sql="SELECT * FROM $tbl_name ORDER BY temas_id DESC";

$result=mysql_query($sql);

$count=mysql_num_rows($result);

$result=mysql_query($sql) or die(mysql_error());

$counter = $count;

 

 

// lapu navigācija

for($i= 0;$i <= ($_SESSION["lapasnr"] * 10 -1); $i++)

{

if($_SESSION["lapasnr"] == 0)

{

break;

}

$row = mysql_fetch_array($result);

$count--;

}

if($count > 10)

{

$count = 10;

}

$tbl_name = "lietotaji";

// vajadzīgās lapas tēmu izklāsts

while($count > 0)

{

$row = mysql_fetch_array($result);

if($_SESSION["liet_priv"] == 1)

{

echo '<div class="jaun_date" style="float: right;" ><a href="delete_tema.php?id='.$row["temas_id"].'">Dzēst</a>'.$row["username"].' '.$row["datums"].'</div>';

} else

{

echo '<div style="float: right;" >'.$row["datums"].'</div>';

}

echo '<div class="jaun_head">'.$row["temas_nosaukums"].'  <a href="forums_kom.php?Id='.$row["temas_id"].'">Komentāri</a></div>';

$count--;

}

 

// pārbaude lai zinātu kuras navigācijas pogas jārāda

if($_SESSION["lapasnr"] >= 1)

{

echo '<div class="pag"><a href="login_success.php?inc='.($_SESSION["lapasnr"]-1).'"><<</a></div>';

}

if(($_SESSION["lapasnr"] < intval($counter / 10)) && ($counter > 10))

{

 

echo '<div class="pag"><a href="login_success.php?inc='.($_SESSION["lapasnr"]+1).'">>></a></div>';

}

?>

 

 

<div class="jaun_head">

<form method="post" action="add_temu.php">

<br><br>Temas nosaukums:<br>

<input type="text" name="temas_nosaukums" ></textarea><br>

Temas apraksts:<br>

<textarea name="temas_apraksts" ></textarea><br>

<input type="submit" name="submit" value="Pievienot tēmu" />

</form>

</div>';

_____________________________________________________________________________________________________________________________________

add_temu.php

 

<?php

session_start();

// lietotāja pārbaude

if(!isset($_SESSION["useris"]))

{

session_destroy();

header("location:login.php");

}

 

// datuma ieguve

$datums = getdate();

 

$host="localhost"; // Host name

$username="root"; // Mysql username

$password=""; // Mysql password

$db_name="jumitis"; // Database name

$tbl_name="tema"; // Table name

 

// savienojuma izveide ar datubāzi

$conn=mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

mysql_query("SET NAMES UTF8", $conn);

 

//pārbauda vai tēma ir ievadīta

 

$temas_nosaukums = $_POST["temas_nosaukums"];

$temas_apraksts = $_POST["temas_apraksts"];

 

$liet = $_SESSION["useris"];

$sql="INSERT INTO tema VALUES ( '$temas_nosaukums','$temas_apraksts','$datums','$liet')";

echo 'Lietotājs veiksmīgi pievienots!';

mysql_query($sql);

header("location:forums.php?succ=1");

?>

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...