код за приятели

C++ JAVA
Post Reply
k0kytak
Потребител
Потребител
Posts: 964
Joined: Sun Aug 17, 2008 11:17 pm
Contact:

код за приятели

Post by k0kytak » Fri Apr 10, 2009 2:07 pm

Дайте ми некав код за добавяне на приятели (не за баннери) да има една database friends и там да се записват мойте добавени приятели и да ги показва.. 8)

User avatar
ArchDevil
Турист
Турист
Posts: 378
Joined: Sat Aug 23, 2008 7:00 am
Answers: 41
Location: Сандански

Post by ArchDevil » Fri Apr 10, 2009 2:29 pm

Code: Select all

<?php
switch&#40;$_GET&#91;'mode'&#93;&#41;&#123;
case 'addfr'&#58;
if&#40;!$_POST&#91;'addfr'&#93;&#41;&#123;
?>
<form action="" method="post">
Добави приятел <input type="text" name="friend"><br />
<input type="submit" name="addfr" value="Добави"></form>
<?php
&#125;
else&#123;
$friend=htmlspecialchars&#40;$_POST&#91;'friend'&#93;&#41;;
if&#40;!empty&#40;$friend&#41;&#41;&#123;
mysql_connect&#40;"localhost","root","3scap3r"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
mysql_select_db&#40;"test"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
mysql_query&#40;"INSERT INTO users &#40;`id`,`friend`,`user`&#41; VALUES &#40;'NULL','$friend','Replace'&#41;"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
echo"Добавихте $friend в списъка с приятели <meta http-equiv='refresh' content='2; url=friend.php'>";
&#125;
else&#123;echo"Не сте избрали приятел";&#125;
&#125;
break;
default &#58;
mysql_connect&#40;"localhost","root","3scap3r"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
mysql_select_db&#40;"test"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
$sql=mysql_query&#40;"SELECT * FROM users WHERE user='Replace'"&#41;;
echo"<table border='1'><tr><td>Номер</td><td>Приятели</td></tr>";
$i='1';
while&#40;$row = mysql_fetch_array&#40;$sql&#41;&#41;&#123;
echo"<tr><td>$i</td><td>$row&#91;friend&#93;</td></tr>";
$i++;
&#125;
$obshto=mysql_num_rows&#40;mysql_query&#40;"SELECT id FROM users WHERE user='Replace'"&#41;&#41;;
echo"</table>Вие имате общо $obshto приятели";
break;
&#125;
?>
SQL

Code: Select all

CREATE TABLE IF NOT EXISTS `users` &#40;
  `id` int&#40;11&#41; NOT NULL auto_increment,
  `friend` varchar&#40;255&#41; NOT NULL,
  `user` varchar&#40;255&#41; NOT NULL,
  PRIMARY KEY  &#40;`id`&#41;
&#41; ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

k0kytak
Потребител
Потребител
Posts: 964
Joined: Sun Aug 17, 2008 11:17 pm
Contact:

Post by k0kytak » Fri Apr 10, 2009 6:48 pm

Добре май кода работи но може ли код за добавяне на приятели да го сложа кода в самия профил на потребителите и да може да ги добавям ?

k0kytak
Потребител
Потребител
Posts: 964
Joined: Sun Aug 17, 2008 11:17 pm
Contact:

Post by k0kytak » Fri Apr 10, 2009 7:17 pm

Офф тоя код не става бе... добавям от сяла приятел

Code: Select all

 id 1  friend  2  user k0kytak
и не вади нищо в мойте приятели баси кочината..
там кадето се записват приятелите датабазата се казва frends а там кадето са потребителите е users надявам се да помогнете...

Code: Select all

<?php
switch&#40;$_GET&#91;'mode'&#93;&#41;&#123;
case 'addfr'&#58;
if&#40;!$_POST&#91;'addfr'&#93;&#41;&#123;
?>
<form action="" method="post">
Добави приятел <input type="text" name="friend"><br />
<input type="submit" name="addfr" value="Добави"></form>
<?php
&#125;
else&#123;
$friend=htmlspecialchars&#40;$_POST&#91;'friend'&#93;&#41;;
if&#40;!empty&#40;$friend&#41;&#41;&#123;
mysql_connect&#40;"localhost","root","Parolata"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
mysql_select_db&#40;"database"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
mysql_query&#40;"INSERT INTO frends &#40;`id`,`friend`,`user`&#41; VALUES &#40;'NULL','$friend','Replace'&#41;"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
echo"Добавихте $friend в списъка с приятели <meta http-equiv='refresh' content='2; url=friend.php'>";
&#125;
else&#123;echo"Не сте избрали приятел";&#125;
&#125;
break;
default &#58;
mysql_connect&#40;"localhost","root","Parolata"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
mysql_select_db&#40;"database"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
$sql=mysql_query&#40;"SELECT * FROM frends WHERE user='Replace'"&#41;;
echo"<center><table border='5'><tr><td>Номер</td><td>Приятели</td></tr></center>";
$i='1';
while&#40;$row = mysql_fetch_array&#40;$sql&#41;&#41;&#123;
echo"<tr><td>$i</td><td>$row&#91;friend&#93;</td></tr>";
$i++;
&#125;
$obshto=mysql_num_rows&#40;mysql_query&#40;"SELECT id FROM frends WHERE user='Replace'"&#41;&#41;;
echo"</table><br>Вие имате общо $obshto приятели</br>";
break;
&#125;
?> 

camerb
Турист
Турист
Posts: 307
Joined: Sat Nov 10, 2007 2:55 pm

Post by camerb » Fri Apr 10, 2009 7:21 pm

Code: Select all

mysql_connect&#40;"localhost","root","Parolata"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
mysql_select_db&#40;"database"&#41;or die&#40;mysql_error&#40;&#41;&#41;; 

k0kytak
Потребител
Потребител
Posts: 964
Joined: Sun Aug 17, 2008 11:17 pm
Contact:

Post by k0kytak » Fri Apr 10, 2009 7:25 pm

camerb wrote:

Code: Select all

mysql_connect&#40;"localhost","root","Parolata"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
mysql_select_db&#40;"database"&#41;or die&#40;mysql_error&#40;&#41;&#41;; 
Е кво ми го показваш тва тука сам махнал паролата и датабазата да не зяпате :!:

User avatar
ArchDevil
Турист
Турист
Posts: 378
Joined: Sat Aug 23, 2008 7:00 am
Answers: 41
Location: Сандански

Post by ArchDevil » Sat Apr 11, 2009 4:27 am

Ами почваме от начало. Ти каза, че се казва frend, а в кода е friend. Не знам правописна грешка или грешка в кода е.
Ако не пробвай това. http://web-tourist.net/forum/viewtopic.php?t=63473

HelpeR
Нов
Нов
Posts: 37
Joined: Sat Apr 11, 2009 5:37 am
Location: Пазарджик

Post by HelpeR » Sat Apr 11, 2009 5:54 am

Ето ти и едно мое скриптче.

Таме кадето искаш да изкаращ приятелите свожи това:

Code: Select all

<?php
include &#40;'conf.php'&#41;;
$select = mysql_query&#40;"SELECT * FROM links "&#41;or die&#40;mysql_error&#40;&#41;&#41;;
$num = mysql_num_rows&#40;$select&#41;;
for &#40;$i=0;$i<$num;$i++&#41; &#123;
$name = mysql_result&#40;$select, $i, "name"&#41;;
$link = mysql_result&#40;$select, $i, "link"&#41;;
echo '<meta http-equiv="Content-Type" content="text/html"; charset="windows-1251" />';
echo '<li><a href="' . $link . '" target="_blank">' . $name . '</a></li>';
&#125;

mysql_close&#40;&#41;;
?>
Ето ти и кода за добавяне на приятел.

admin_friends_add.php

Code: Select all

<?php
if &#40;isset&#40;$_POST&#91;"submit"&#93;&#41;&#41; &#123;
include &#40;'conf.php'&#41;;
if &#40;!empty&#40;$_POST&#91;"name"&#93;&#41;&#41; $name = htmlspecialchars&#40;$_POST&#91;"name"&#93;&#41;;
else $errMsg = "<b>Не сте въвели име!</b><br />";
if &#40;!empty&#40;$_POST&#91;"link"&#93;&#41;&#41; $link = htmlspecialchars&#40;$_POST&#91;"link"&#93;&#41;;
else $errMsg = "<b>Не сте въвели линк!</b><br />";
if &#40;empty&#40;$errMsg&#41;&#41; &#123;
$insert = mysql_query&#40;"INSERT INTO links&#40;name, link&#41; VALUES&#40;'$name', '$link'&#41;"&#41;or die&#40;mysql_error&#40;&#41;&#41;;
echo '<b>Успешно добавихте линк!</b>';
echo "<meta http-equiv=\"refresh\" content=\"1; url=../admin/admin_friends_links.php\">";
&#125; else echo $errMsg;
mysql_close&#40;&#41;;
&#125;
?>
Eто ти и кода за истриване.

admin_friends_del.php

Code: Select all

	 <?php
include &#40;'conf.php'&#41;;
$back = $_SERVER&#91;'HTTP_REFERER'&#93;;
mysql_query&#40;'SET NAMES cp1251'&#41;;
$id = $_GET&#91;'id'&#93;;
if&#40;isset&#40;$id&#41;&#41;&#123;
$query1 = "delete from links where id=$id";

$result = mysql_query&#40;$query1&#41;;
&#125;
$ok = mysql_query&#40;$query1&#41;;
if&#40;$ok&#41;&#123;
echo "<meta http-equiv=\"refresh\" content=\"1; url=../admin/admin_friends_links.php\">Линка е изтрит успешно!";
&#125;else&#123;
echo "<b>Възникна грешка!</b>";
&#125;;
?>
Eто ти и кода за редактиране на приятел.
admin_friends_edit.php

Code: Select all

<?php
include&#40;'conf.php'&#41;;
$id = $_GET&#91;'id'&#93;;
if &#40;!$_POST&#91;'links'&#93;&#41;
&#123;
$our = mysql_query&#40;"SELECT name, link FROM links where id='$id' "&#41;;
while&#40;$r=mysql_fetch_array&#40;$our&#41;&#41;&#123;
?>
<form method="POST">
<b>Име&#58;</b> <input type="text" name="name" maxlength="30" class="textbox" value="<?PHP echo"$r&#91;name&#93;"; ?>"/><br />
<b>Линк&#58;</b> <input type="text" value="<?PHP echo"$r&#91;link&#93;"; ?>" name="link" class="textbox"><br />
<input name="links" type="submit" value="Промени!" class="button">
</form>
<?

Ето ти и кода за в началната страница на админ панела кадето показва приятелите до тях изтри редактирай

admin_friends_links.php

Code: Select all

<?php
include &#40;'conf.php'&#41;;

$select = mysql_query&#40;"SELECT * FROM links "&#41;or die&#40;mysql_error&#40;&#41;&#41;;
$num = mysql_num_rows&#40;$select&#41;;
for &#40;$i=0;$i<$num;$i++&#41; &#123;
$name = mysql_result&#40;$select, $i, "name"&#41;;
$link = mysql_result&#40;$select, $i, "link"&#41;;
$id = mysql_result&#40;$select, $i, "id"&#41;;
echo '<a href="' . $link . '" target="_blank"><b><u>' . $name . '</u></b></a> - <a href="admin_friends_edit.php?id=' . $id . '">Промени</a> | <a href="admin_friends_del.php?id=' . $id . '">Изтрий</a><br />';
&#125;

mysql_close&#40;&#41;;
?>

Ето и conf.php

Code: Select all

<?
$hostname = "Хост";
$user = " Потребител";
$pass = "Парола ";
$database = "Име на базата дани";
$conn = @mysql_connect&#40;"$hostname","$user","$pass"&#41;;
$chars="SET CHARACTER SET UTF-8"; mysql_query&#40;$chars&#41;;
@mysql_select_db&#40;$database&#41;;
$pass_admin = "123";
?>
Ето ти и sql

Code: Select all

CREATE TABLE IF NOT EXISTS `links` &#40;
  `id` int&#40;8&#41; NOT NULL auto_increment,
  `name` varchar&#40;255&#41; NOT NULL,
  `link` varchar&#40;255&#41; NOT NULL,
  PRIMARY KEY  &#40;`id`&#41;
&#41; ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=18 ;
Това е надявам се да съм ти помогнъл.[/code]

Post Reply