Page 1 of 1

Грешка в код

Posted: Fri Dec 11, 2009 9:37 pm
by Dizasterr
Здравейте! Написах си този код:

Code: Select all

	
	<?php

require_once&#40;"../connection.php"&#41;;
mysql_query&#40;"SET NAMES cp1251"&#41;;


$result = mysql_query&#40;"SELECT * FROM `bicycles`"&#41; or die&#40;mysql_error&#40;&#41;&#41;;

while&#40;$row=mysql_fetch_array&#40;$result&#41;&#41; &#123;
echo "<b> Колело&#58;</b> ";
echo $row&#91;'bicycle'&#93;;
echo "<b> Цена&#58;</b> $";
echo $row&#91;'price'&#93;;
echo "<br/>";


if &#40;isset&#40;$_GET&#91;'buy'&#93;&#41; && is_numeric&#40;$_GET&#91;'buy'&#93;&#41; && $_GET&#91;'buy'&#93; > 0&#41;
&#123;
$bicycle = $row&#91;'bicycle'&#93;;
$buy = $_GET&#91;'buy'&#93;;
mysql_query&#40;"UPDATE `potrebiteli` SET `bicycle`='".$row&#91;'bicycle'&#93;."' WHERE `potrebitel`='".$_SESSION&#91;'login'&#93;."'"&#41; or die&#40;mysql_error&#40;&#41;&#41;;

&#125;
$query = mysql_query&#40;"SELECT * FROM `potrebiteli` ORDER BY `id` DESC"&#41; or die&#40;mysql_error&#40;&#41;&#41;;
echo "<table border=\"0\">\n";

echo "&#91;<a href=\"?buy=".$row&#91;'bicycle'&#93;."\">Купи</a>&#93;\n";
echo "<br/>";

echo "</table>";
&#125;


?>
Но не работи. Не упдейтва базата данни. Кода ми трябва спешно. Благодаря предварително. За този, който помогне +1.

Posted: Fri Dec 11, 2009 9:42 pm
by justspy

Code: Select all

   <?php

require_once&#40;"../connection.php"&#41;;
mysql_query&#40;"SET NAMES cp1251"&#41;;


$result = mysql_query&#40;"SELECT * FROM `bicycles`"&#41; or die&#40;mysql_error&#40;&#41;&#41;;

while&#40;$row=mysql_fetch_array&#40;$result&#41;&#41; &#123;
echo "<b> Колело&#58;</b> ";
echo $row&#91;'bicycle'&#93;;
echo "<b> Цена&#58;</b> $";
echo $row&#91;'price'&#93;;
echo "<br/>";


if &#40;isset&#40;$_GET&#91;'buy'&#93;&#41; && is_numeric&#40;$_GET&#91;'buy'&#93;&#41; && $_GET&#91;'buy'&#93; > 0&#41;
&#123;
$bicycle = $row&#91;'bicycle'&#93;;
$buy = $_GET&#91;'buy'&#93;;
$session=$_SESSION&#91;'login'&#93;;

mysql_query&#40;"UPDATE `potrebiteli` SET `bicycle`='$bicycle' WHERE `potrebitel`='$session'"&#41; or die&#40;mysql_error&#40;&#41;&#41;;

&#125;
$query = mysql_query&#40;"SELECT * FROM `potrebiteli` ORDER BY `id` DESC"&#41; or die&#40;mysql_error&#40;&#41;&#41;;
echo "<table border=\"0\">\n";

echo "&#91;<a href=\"?buy=".$row&#91;'bicycle'&#93;."\">Купи</a>&#93;\n";
echo "<br/>";

echo "</table>";
&#125;


?>

Така ?

Posted: Fri Dec 11, 2009 9:44 pm
by Dizasterr
Не става. Не ми дава грешка, но и не записва. Може ли защото полето е празно ?

Posted: Fri Dec 11, 2009 9:44 pm
by jefriii
Dizasterr wrote:Не става. Не ми дава грешка, но и не записва. Може ли защото полето е празно ?
да

Posted: Fri Dec 11, 2009 9:46 pm
by Dizasterr
И да не е празно пак не става.

Posted: Fri Dec 11, 2009 9:46 pm
by justspy
братле всичко от условието въведено по горе трябва да е изпълнено, за да се осъществи заявката.. явно не всичко е изпълнено от там идва и грешката :)

Posted: Sat Dec 12, 2009 9:46 am
by Dizasterr
Мерси много. Вече се записват, но което и да натисна ми записва едно и също.