Jump to content

PHP problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
cedomirovic

cedomirovic

    Newbie

  • Members
  • Pip
  • 4 posts
Hi, on my admin page i have this


<?php

//konekcija sa bazom i forma sa padajucom listom

include ("../baza/konekcija.php");

//include ("../include/forma.php");


?>



<form name="konfigurator" method="post" action="../index.php">

   <b>CPU</b>

    <select name="cpu">

    <?php

      $result = mysql_query("SELECT cpu FROM konfiguracije") or die(mysql_error());

      while($row = mysql_fetch_array($result)) {

      echo $row['cpu'] ;

      echo '<option>';

      echo $row['cpu'] ;

      echo '</option> ';

      }      


   ?>

   </select>

   <BR>

    <b>Maticna ploca</b>

    <select name="maticna">

    <?php

      $result = mysql_query("SELECT maticna FROM konfiguracije") or die(mysql_error());

      while($row = mysql_fetch_array($result)) {

      echo $row['maticna'] ;

      echo '<option>';

      echo $row['maticna'] ;

      echo '</option> ';

      }?>

<input name="ubaci" type="submit" id="ubaci" value="Objavi">


</form>




now how to display selected item on my index page i try this but not works, please help i am beginer and sorry on my English


<link href="css/style.css" rel="stylesheet" type="text/css">


<div id="sajt">


   <div id="levo">

      <h2>Hardware</h2>

      <p>

      <?php

error_reporting(E_ALL ^ E_NOTICE);


   $cpu = $_POST["cpu"];

   $maticna = $_POST["maticna"];

   

      

echo $cpu;

         echo "<BR>";

         echo $maticna;

         echo "<BR>";

      

         ?>

      </p>

   </div>

</div>



#2
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Your very close to being correct. Replace the admin panel code with this :

<?php

//konekcija sa bazom i forma sa padajucom listom

include ("../baza/konekcija.php");

//include ("../include/forma.php");


?>



<form name="konfigurator" method="post" action="../index.php">

   <b>CPU</b>

    <select name="cpu">

    <?php

      $result = mysql_query("SELECT cpu FROM konfiguracije") or die(mysql_error());

      while($row = mysql_fetch_array($result)) {

      echo '<option value="$row[\'cpu\']">';

      echo $row['cpu'] ;

      echo '</option> ';

      }      


   ?>

   </select>

   <BR>

    <b>Maticna ploca</b>

    <select name="maticna">

    <?php

      $result = mysql_query("SELECT maticna FROM konfiguracije") or die(mysql_error());

      while($row = mysql_fetch_array($result)) {

      echo '<option value="$row[\'maticna\']">';

      echo $row['maticna'] ;

      echo '</option> ';

      }?>

<input name="ubaci" type="submit" id="ubaci" value="Objavi">


</form>

You need to set the value for the <option> tag so that a value is passed when posting to the index page. Untested, try it though. It should work ;)

#3
cedomirovic

cedomirovic

    Newbie

  • Members
  • Pip
  • 4 posts
thx that works but i wont when i handle that information to stay on index not when i refresh i don't have nothing, i hope you understud me

#4
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Not sure I understand... Some screenshots could help?

#5
cedomirovic

cedomirovic

    Newbie

  • Members
  • Pip
  • 4 posts
when i select something in admin panel i have that information on my index

but next time when i open my index i don't have

Attached Files



#6
DEViANT

DEViANT

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 358 posts
Well see, since the data gets posted from your admin page to your index page the data won't be retrieved unless its posted. To have the data there permanently you should consider using an SQL database. You can read up on PHP and SQL here :

PHP MySQL Introduction

I see that the data in the admin panel is already being pulled from a database though. So alternatively you can just alter your SQL tables and instead of posting the variables from the index page the index page can call the data from your SQL database, where applicable.

#7
cedomirovic

cedomirovic

    Newbie

  • Members
  • Pip
  • 4 posts
here my script if you can to show me directly

Attached Files