1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Array help!!!

Discussion in 'PHP' started by hasanzadeh, Jul 26, 2010.

  1. #1
    Hi,
    I have a table that when operator insert an Id and want to edit data ,he can add new data also.i have a problem with this scripts ,can anyone edit my script or help me?
    thanks
     
    Last edited: Jul 26, 2010
    hasanzadeh, Jul 26, 2010 IP
  2. Deacalion

    Deacalion Peon

    Messages:
    438
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Could you post the code and explain the problem in detail?
     
    Deacalion, Jul 26, 2010 IP
  3. hasanzadeh

    hasanzadeh Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    My Scripts that Not Complated because i begin learn php for afew weeks and i dont know how do it :
    config:
    <?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $dbname = 'Array';
    $connect = mysql_connect ($dbhost, $dbuser, $dbpass)  OR die (mysql_erorr());
    mysql_select_db ($dbname, $connect)OR die (mysql_erorr());
    ?>
     
    
    PHP:
    Add_Edit_Form.php:
    <html>
    <head>
    <link href="style.css" rel="stylesheet">
    </head>
    <body>
    <table align="center" id="tablet" width="27%" >
    <tr>
       <td id="main">Enter Your Id And Click Add_EDIT  </td>   
    </tr>
    <tr>   
       <td class='text'><form method='POST' action='Add_Edit.php'><p align='center'>
    Your ID :<input type="text" name="Id" size="5">
    <input type='submit' value='Add_EDIT' class='btn'></p>
    </form></td>
    </tr>
    </table>
    </form>
    </table>
    
    PHP:
    Add_Edit.php:
    html>
    <head>
    <link href="style.css" rel="stylesheet">
    <title> Learn : Array </title>
    </head>
    <body>
    <table width="55%"  align="center" cellspacing="1"  id="tablet" >
      <tr>    
        <td id="main">Name</td>
        <td id="main">Family</td>
        <td id="main">City</td>
        <td id="main">Country</td>
        
      </tr>
    <?php
    include"config.php";
    
    $query=mysql_query("SELECT * FROM `learn` WHERE  Id='$_POST[Id]' ");
    while($row=mysql_fetch_array($query)){
       $Number=$row[Number];
        $Id=$row[Id];
        $Name=$row[Name];
        $Family=$row[Family];
        $City=$row[City];
        $Country=$row[Country];
    
    echo ('<form method="POST" action="MkeditId.php">');?>
    
       
      
      <tr>
       <input type='hidden' name='Number[]' value="<?php echo"$Number";?>"</td></td>
       <input type='hidden' name='Id[]' value="<?php echo"$Id";?>"</td></td>
         <td id='tmain'><input type='text' name='Name[]' value="<?php echo"$Name";?>"</td>
        <td id='tmain'><input type='text' name='Family[]' value="<?php echo"$Family";?>"</td>
        <td id='tmain'><input type='text' name='City[]' value="<?php echo"$City";?>"</td>
        <td id='tmain'><input type='text' name='Country[]' value="<?php echo"$Country";?>"</td>
        </tr>
             <?php
    }
    ?>  
       <tr>
         <td id='tmain'><input type='text' name='Name[]' ></td>
        <td id='tmain'><input type='text' name='Family[]' ></td>
        <td id='tmain'><input type='text' name='City[]'> </td>
        <td id='tmain'><input type='text' name='Country[]' ></td>
        </tr>
        <tr>
         <td id='tmain'><input type='text' name='Name[]'> </td>
        <td id='tmain'><input type='text' name='Family[]' ></td>
        <td id='tmain'><input type='text' name='City[]' ></td>
        <td id='tmain'><input type='text' name='Country[]' ></td>
        </tr>
        
        <?php
    
      echo('<table width="35%" border="0" align="center" ><tr><div align="center"><input type="submit" value="Add_Edit" name="B1" class="btn"><input type="reset" value="Reset" class="btn"></p>
    
    </tr></form>');
    ?>
     
    
    PHP:
    MkediId.php:
    <?php
    include "config.php";
    $Data =array( n=>($_POST['Number']),i=>($_POST['Id']),na=>($_POST['Name']),f=>($_POST['Family']),c=>($_POST['City']),co=>($_POST['Country']));
    
    $Howmany=count($_POST['Name']);
    
           $i=0;
        while($i<$Howmany)  {   
           $Number=$Data["n"][$i];
           $Id=$Data["i"][$i];
           $Name=$Data["na"][$i];
           $Family=$Data["f"][$i];
           $City=$Data["c"][$i];
           $Country=$Data["co"][$i];
     
             $EditData = "UPDATE `learn` SET Name='$Name', Family= '$Family',city='$City',country='$Country' where Number='$Number' ";
    
    $result = mysql_query($EditData) or die(mysql_error());   
                  $i++;
                 
                         }                  
       
    if($EditData){
       echo "<p class='text'>Your data is Edit Sucsesfull";
    }
    else{
    echo "<p class='text'>There Is a Problem.Please Try Again";   
    }
    
    ?>
    
    PHP:
     
    hasanzadeh, Jul 26, 2010 IP