Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Multi drop down list upis i update u databas

[es] :: PHP :: Multi drop down list upis i update u databas

[ Pregleda: 1456 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

nindza@
WwW - Nis,Bg

Član broj: 57064
Poruke: 367
*.mbb.telenor.rs.



+6 Profil

icon Multi drop down list upis i update u databas03.05.2012. u 01:52 - pre 145 meseci
Postovani Online Forum Prijatelji,

Imam jedan malo poveci problem koji me muci zadnjih nekoliko dana, a koji koliko vidim ne umem da resim ili mi vise nista pametno ne pada na pamet kao resenje.

Imam formu koja zapisuje u bazi sledece podatke:

email, country, city, adress, user, date, info,

Code:
<title> Add New</title>

<?php

include("config.php");
mysql_connect($dbhost, $dbuname, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error()); 

?>


<?php
if(!empty($_POST['user']) && !empty($_POST['email'])) {     
 $email = mysql_real_escape_string($_POST['email']);     
 $country = mysql_real_escape_string($_POST['country']);     
 $city = mysql_real_escape_string($_POST['city']);    
 $user = mysql_real_escape_string($_POST['user']);     
 $date = mysql_real_escape_string($_POST['date']);        
 $adress = mysql_real_escape_string($_POST['adress']);      
 $info = mysql_real_escape_string($_POST['info']);  

$checkuser = mysql_query("SELECT * FROM Users WHERE user = '".$user."'");

     if(mysql_num_rows($checkuser) == 1)
     {
        echo "<h1>Error</h1>";
        echo "<p>Sorry, the username is taken.<a href=\"add.php\">Enter</a>new user name.</p>";
     }
     else
     {

$registerquery = mysql_query(
        "INSERT INTO Users (email, country, city, user, date, adress, info) 
        VALUES ('".$email."', '".$country."', '".$city."', '".$user."', '".$date."', '".$adress."', '".$info."')");
        if($registerquery)
        {
            echo "<h1>Successful Add</h1>";
            echo "<p>Your entry has been successfully created :).<meta http-equiv='refresh' content='2;url=add.php'></p>";
        }
        else
        {
            echo "<h1>Error</h1>";
            echo "<p>Sorry, registration failed.<a href=\"add.php\">Please try again.</a></p>";
            echo mysql_error(); 

        }
     }
}
else
{
    ?>


<div align="center">

<a href="add.php"> Add New</a>&nbsp;/&nbsp;
<a href="update.php">Update</a>&nbsp;/&nbsp;
<a href="search.php">Search</a>

    <form method="post" action="add.php" name="registerform" id="registerform">

  <table width="700" border="0" cellpadding="0">
  <tr>
    <td width="120"><label for="email">email: *</label></td>
    <td width="250"><input type="text" name="email" id="email" /></td>
    <td width="120"><label for="country">country:</label></td>
    <td width="250"><input type="text" name="country" id="country" /></td>
    </tr>
  <tr>
    <td width="120"><label for="city">city:</label></td>
    <td width="250"><input type="text" name="city" id="city" /></td>
    <td width="120"><label for="user">user:</label></td>
    <td width="250"><input type="text" name="user" id="user" /></td>
    </tr>
  <tr>
    <td width="120"><label for="date">date:</label></td>
    <td width="250"><input type="text" name="date" id="date" /></td>
    <td width="120"><label for="adress">adress:</label></td>
    <td width="250"><input type="text" name="adress" id="adress" /></td>
    </tr>
  <tr>
    <td width="120">&nbsp;</td>
    <td width="250">&nbsp;</td>
    <td width="120">&nbsp;</td>
    <td width="250">&nbsp;</td>
    </tr>
  <tr>
    <td width="120">&nbsp;</td>
    <td width="250">&nbsp;</td>
    <td width="120">&nbsp;</td>
    <td width="250">&nbsp;</td>
    </tr>
  <tr>
    <td width="120"><label for="info">Info:</label></td>
    <td colspan="3"><textarea dir="ltr" name="info" type="text"></textarea></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right"><input type="submit" name="register" id="register" value="Add New" /></td>
    <td align="center"><input type="reset" name="reset" id="reset" value="Cancel" /></td>
  </tr>
  </table>
    </form>
  </div>


    <?php
}
?>


Zatim imam formu koja treba da radi upadate za izabrane podatke tj da ih lista po selekciji, po user & email. Gde prvo mora da izabere country da bi mu dozvolilo da bira --->city zatim da mu izlista sve --> user i sve tako do kraja gde ce da mu u polje info iscita txt poruku koja se menja.

Jednostavni primer za tako nesto kako bih da resim ali ne znam kako jeste na sajtu cineplexx odabir bioskopa --> datum --> film --> vreme

Code:
<title> Update </title>
<?php

include("config.php"); // include database configuration
mysql_connect($dbhost, $dbuname, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error()); 

?>


<?php
if(!empty($_POST['user']) && !empty($_POST['email'])) {     
 $email = mysql_real_escape_string($_POST['email']);     
 $country = mysql_real_escape_string($_POST['country']);     
 $city = mysql_real_escape_string($_POST['city']);    
 $user = mysql_real_escape_string($_POST['user']);     
 $date = mysql_real_escape_string($_POST['date']);        
 $adress = mysql_real_escape_string($_POST['adress']);      
 $info = mysql_real_escape_string($_POST['info']);  



$registerquery = mysql_query(
"UPDATE Users SET country='$country', city='$city', user='$user', date='$date', adress='$adress', info='$info' WHERE email='$email');         VALUES ('".$email."', '".$country."', '".$city."', '".$user."', '".$date."', '".$adress."', '".$info."')");
        if($registerquery)
        {
            echo "<h1>Successful Update</h1>";
            echo "<p>Your entry has been successfully created.<a href=\"index.php\">click here</a>.</p>";
        }
        else
        {
            echo "<h1>Error</h1>";
            echo "<p>Sorry, registration failed. Please try again.</p>";
            echo mysql_error(); 

        }
     }

else
{
    ?>

<div align="center">

<a href="add.php"> Add New</a>&nbsp;/&nbsp;
<a href="update.php">Update</a>&nbsp;/&nbsp;
<a href="search.php">Search</a>

    <form method="post" action="update.php" name="registerform" id="registerform">

  <table width="700" border="0" cellpadding="0">
  <tr>
    <td width="120"><label for="email">email: *</label></td>
    <td width="250"><label><input name="email" type="text" id="email" size="64" value="<?php echo "$email"; ?>" /></label>

    </td>
    <td width="120"><label for="country">country:</label></td>
    <td width="250"><input type="text" name="country" id="country" /></td>
    </tr>
  <tr>
    <td width="120"><label for="city">city:</label></td>
    <td width="250"><input type="text" name="city" id="city" /></td>
    <td width="120"><label for="user">user:</label></td>
    <td width="250">
<?php $sql = ("SELECT user From Users");
echo"<select name='user'>";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)){
echo '<option value="'.$row["user"].'">'.$row["user"].'</option>';
}
echo "</select>"; 
?>  

    <input type="text" name="user" id="user" /></td>
    </tr>
  <tr>
    <td width="120"><label for="date">date:</label></td>
    <td width="250"><input type="text" name="date" id="date" /></td>
    <td width="120"><label for="adress">adress:</label></td>
    <td width="250"><input type="text" name="adress" id="adress" /></td>
    </tr>
  <tr>
    <td width="120">&nbsp;</td>
    <td width="250">&nbsp;</td>
    <td width="120">&nbsp;</td>
    <td width="250">&nbsp;</td>
    </tr>
  <tr>
    <td width="120">&nbsp;</td>
    <td width="250">&nbsp;</td>
    <td width="120">&nbsp;</td>
    <td width="250">&nbsp;</td>
    </tr>
  <tr>
    <td width="120"><label for="info">Info:</label></td>
    <td colspan="3"><textarea dir="ltr" name="<?php echo "$info"; ?>" type="text"></textarea></td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td align="right"><input type="submit" name="register" id="register" value="Update" /></td>
    <td align="center"><input type="reset" name="reset" id="reset" value="Cancel" /></td>
  </tr>
  </table>
    </form>
  </div>

    <?php
}
?>



Poslednja forma koja treba da izigrava kao nekog pretrazivaca, koji ce da isto odabirom country --> zatim city islistati koliko ima user po country i city.

Code:
<title> Search </title>
<?php

include("config.php"); // include database configuration
mysql_connect($dbhost, $dbuname, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error()); 

?>


<?php
if(!empty($_POST['city']) && !empty($_POST['country'])) {     
// $email = mysql_real_escape_string($_POST['email']);     
 $country = mysql_real_escape_string($_POST['country']);     
 $city = mysql_real_escape_string($_POST['city']);    
// $user = mysql_real_escape_string($_POST['user']);     
// $date = mysql_real_escape_string($_POST['date']);        
// $adress = mysql_real_escape_string($_POST['adress']);      
// $info = mysql_real_escape_string($_POST['info']);    

    ?>


<div align="center">

<a href="add.php"> Add New</a>&nbsp;/&nbsp;
<a href="update.php">Update</a>&nbsp;/&nbsp;
<a href="search.php">Search</a>

    <form method="post" action="search.php" name="registerform" id="registerform">
  <table width="700" border="0" cellpadding="0">
  <tr>
    <td width="120"><label for="country">country: *</label></td>
    <td width="250"><input type="text" name="country" id="country" /></td>
    <td width="120"><label for="city">city: *</label></td>
    <td width="250"><input type="text" name="city" id="city" /></td>
    <td width="120"><label for="adress ">adress :</label></td>
    <td width="250"><input type="text" name="adress " id="adress " /></td>
    </tr>
  </table>
  <table width="700" border="0" cellpadding="0">
    <tr>
      <td width="205">How many users in this country: </td>
      <td>&nbsp;</td>
      </tr>
    <tr>
      <td>How many users in this city:</td>
      <td>&nbsp;</td>
      </tr>
  </table>
  <table width="700" border="0" cellpadding="0">
    <tr>
      <td width="120">&nbsp;</td>
      <td width="250">&nbsp;</td>
      <td align="right"><input type="submit" name="register" id="register" value="Search" /></td>
      <td align="center"><input type="reset" name="reset" id="reset" value="Print" /></td>
    </tr>
  </table>
    </form>
  </div>


    <?php
}
?>


Iskreno moram da priznam da sam se mnogo upekljao, i da sam se posle duzeg vremena totalno pogubio i da vise nemam nijednog pametnog resenja, tj imam ovo sto sam ovde okacio ali nije to to. znam da sam nesto sigurno ispustio ili progutao, ako kojim slucajem imate neki prelog kako da resim ovo Unapred vam se Mnogo Zahvaljujem od Srca



Ako zelite nesto da promenite na bolje, krenite da razmisljate kako bi ste to uradili . . .
 
Odgovor na temu

doktor83
Subotica

Član broj: 293583
Poruke: 50

Sajt: www.oxo.rs


+1 Profil

icon Re: Multi drop down list upis i update u databas03.05.2012. u 13:23 - pre 145 meseci
Pogledaj ovaj primer sa jqueryjem , mozes da resis na ovaj nacin.

Php ajax
----------------------------------------------------------
www.oxo.rs
 
Odgovor na temu

[es] :: PHP :: Multi drop down list upis i update u databas

[ Pregleda: 1456 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.