SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 42
  1. #1
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error:-Query failed: Cannot add or update a child row:

    hello,

    i am getting following error,

    \****\***\**\insertion.php on line 111
    Query failed: Cannot add or update a child row: a foreign key constraint fails (`****/prod`, CONSTRAINT `prod_ibfk_1` FOREIGN KEY (`brand_id`) REFERENCES `brand` (`brand_id`))

    these are the tables here:-
    product(prod_id,brand_id,no_of_qt,notes,primary key(prod_id) foreign key(brand_id) references brand(brand_id),notes))

    brand(brand_id,brandname,primary key(brand_id));

    and i am applying query like this
    $query = "INSERT INTO prod(prod_id,brand_id,no_of_qt,colour,notes) values('".$prod_id."','".$brand_id."','".$no_of_qt."','".colour."','".$notes."')";
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());



    please help me,and tell me what is the problem, i have been solving this query since long. being newer not getting what is wrong here, please help me.
    thanks in advance.

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    AFAIK, the brand table is the parent one and product should be child since the brand_id in the product table is the foreign key that references to the brand table's brand_id primary key. So it seems that you tried to add a brand_id in the product table which does not exists in the brand table. So try to add brand in the brand table first then take the new brand_id and then only insert the product information in the product table with new brand_id.

    Does that give any sense?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please tell me first that is there any need to use foreign key to apply the operations like insertion/updation/deletion?

    if not then, please tell me how do i create my table using that i can apply the above operations?

    beacuse i am finding some problem with it
    1) if i use foreign key than error is coming which i have mention earlier.
    2)if i consider only primary keys,for to connect two tables,than its all messd-up,

    as you suggested me earlier, i am creating each of my page on diff. page.
    but ultimately, i want to show my result on one page. so what to do.
    please help me.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by deepson2 View Post
    please tell me first that is there any need to use foreign key to apply the operations like insertion/updation/deletion?
    not exactly

    you do not need to "use" the foreign key at all -- the database will use it automatically, i.e. it will check the keys for you during those operations

    the whole purpose of foreign keys is to ensure data integrity

    in this example, it is preventing you from adding a product for a brand that doesn't exist

    as rajug said, make sure you add the brand to the brand table first, before adding products for that brand
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    not able to send session value from one page to another

    hello there,
    i want to select rows from this page and send the same fethched information on the next page.
    following are the codes for it.
    1)select.php
    $query = "SELECT prod.prod_id,prod.no_of_qt,prod.colour,prod.notes,brand.brandname from prod,brand
    where prod.id='".prod_id."'";
    // echo $prod_no;
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());

    echo "<table>";

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

    /*echo "<tr>";

    foreach($row as $value){

    echo "<td>".$value."</td>";

    }

    echo "</tr>";*/
    $line = mysql_fetch_array($result, MYSQL_ASSOC);

    $_SESSION['$prod_id']=$line['prod_id'];
    $_SESSION['$no_of_qt']=$line['no_of_qt'];
    $_SESSION['colour']=$line['colour'];
    $_SESSION['$notes']=$line['notes'];
    $_SESSION['brandname']=$line['brandname'];
    <form action="update.php" method="POST" name="productFrm">
    <table>
    <tr><td>prod_id/td>
    <td>
    <input type="text" name="$prod_id" value="" /><label class="errorText"><?=$prod_idErr;?></label></td></tr>
    <tr><td colspan=1><input type="submit" name="Submit" onClick="javascript:return validatepersonal(blogFrm);" value="Get Details"/><input type="submit" name="Submit" onClick="javascript:return validatepersonal(blogFrm);" value="Back"/>
    </td></tr>
    </table> <br>


    2)update.php

    if($_SERVER['REQUEST_METHOD'] == "GET"){

    echo $_SESSION['prod_id'];
    echo $_SESSION['no_of_qt'];
    echo $_SESSION['notes'];
    echo $_SESSION['colour'];
    echo $_SESSION['brandname'];



    }
    else if($_SERVER['REQUEST_METHOD'] == "POST")
    {
    $prod_id = $_POST['prod_id'];
    $no_of_qt = $_POST['no_of_qt'];
    $notes = $_POST['notes'];
    $colour = $_POST['colour'];
    $brandname =$_POST['brandname'];

    but i am not getting a values. please help me,
    am i wrong to write syntax for sessions?

  6. #6
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can not get values on next page using sessions

    hello there,
    i want to select rows from this page and send the same fethched information on the next page.
    following are the codes for it.
    1)select.php
    $query = "SELECT prod.prod_id,prod.no_of_qt,prod.colour,prod.notes,brand.brandname from prod,brand
    where prod.id='".prod_id."'";
    // echo $prod_no;
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());

    echo "<table>";

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

    /*echo "<tr>";

    foreach($row as $value){

    echo "<td>".$value."</td>";

    }

    echo "</tr>";*/
    $line = mysql_fetch_array($result, MYSQL_ASSOC);

    $_SESSION['$prod_id']=$line['prod_id'];
    $_SESSION['$no_of_qt']=$line['no_of_qt'];
    $_SESSION['colour']=$line['colour'];
    $_SESSION['$notes']=$line['notes'];
    $_SESSION['brandname']=$line['brandname'];
    <form action="update.php" method="POST" name="productFrm">
    <table>
    <tr><td>prod_id/td>
    <td>
    <input type="text" name="$prod_id" value="" /><label class="errorText"><?=$prod_idErr;?></label></td></tr>
    <tr><td colspan=1><input type="submit" name="Submit" onClick="javascript:return validatepersonal(blogFrm);" value="Get Details"/><input type="submit" name="Submit" onClick="javascript:return validatepersonal(blogFrm);" value="Back"/>
    </td></tr>
    </table> <br>


    2)update.php

    if($_SERVER['REQUEST_METHOD'] == "GET"){

    echo $_SESSION['prod_id'];
    echo $_SESSION['no_of_qt'];
    echo $_SESSION['notes'];
    echo $_SESSION['colour'];
    echo $_SESSION['brandname'];



    }
    else if($_SERVER['REQUEST_METHOD'] == "POST")
    {
    $prod_id = $_POST['prod_id'];
    $no_of_qt = $_POST['no_of_qt'];
    $notes = $_POST['notes'];
    $colour = $_POST['colour'];
    $brandname =$_POST['brandname'];

    but i am not getting a values. please help me,
    am i wrong to write syntax for sessions?

  7. #7
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,251
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    i cannot help you with your php, but your query is wrong, you are not joining the prod and brand tables correctly

    tip: before embedding a query in a php script, debug the query first by running it directly in the database (i.e. outside the php script)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  8. #8
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In update.php
    write session_start() at the top of the page
    Barbara

  9. #9
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have written it already.. is it because i am fetching values from two table?

  10. #10
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all there is an error:
    PHP Code:
    $query "SELECT prod.prod_id,prod.no_of_qt,prod.colour,prod.notes,brand.brandname from prod,brand
    where prod.id='" 
    prod_id "'"
    The prod_id variable missing $.
    Umm! you have lots of errors in this page as well. You are trying to fetch the result two times with the same result resource which is not correct. So i think first page should not be displaying the records properly.

    And you don't have to use sessions to pass those values just pass the prod_id to another page by link and get the product information in the same way you are doing here.

    Really i still want to request you to follow some books and try the examples first.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  11. #11
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank for your suggestion,but i am trying small program to learn more about it, isn't it good idea? and in all books they have given operations on a single table. so i need to try myself right.

    anyways, i will follow your suggestion and try to read some more books.
    but here, i have written this code with the help of book only,
    i am not getting what to do exactly.
    could you please explain in simple way, as i am newcomer

  12. #12
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well deepson,
    I personally will be pleased to help you and appreciate your try to learn PHP but it seems that you are directly trying to implement everything without understanding. Please try to understand the functions what they do and how they work for you. PHP Manual is enough to understand particular function.

    If you are really following a book there must be some examples with two tables. If not try to find some tutorials for database as well. Otherwise first be perfect using with single tables.

    Never mind if I told you much but I want you to understand PHP with some effort because i am following few threads here in the forum.

    Good luck.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  13. #13
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yah.. i know i trying really big think..though i dont know much about it. but my sir ask me to do this only... what to do.any suggestion?

  14. #14
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok first put your code in php code tag.
    and below line
    PHP Code:
    $line mysql_fetch_array($resultMYSQL_ASSOC); 
    write
    PHP Code:
    print_r($line); 
    to check weather your array contain the values or not.
    Barbara

  15. #15
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are right barbra,
    some problem is there.
    i will check and see the o/p then will let you know thank you.

  16. #16
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes barbara,
    i am getting values in the format of array?
    what to do now?

  17. #17
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your select.php
    Change the lines

    PHP Code:
    $_SESSION['$prod_id']=$line['prod_id'];
    $_SESSION['$no_of_qt']=$line['no_of_qt'];
    $_SESSION['$notes']=$line['notes']; 
    to
    PHP Code:
    $_SESSION['prod_id']=$line['prod_id'];
    $_SESSION['no_of_qt']=$line['no_of_qt'];
    $_SESSION['notes']=$line['notes']; 
    and in update.php
    check for session values as
    PHP Code:
    session_start();
    print_r($_SESSION); 
    and let me no.
    Barbara

  18. #18
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its only showing empty array.

  19. #19
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have u started the session by session_start() in your select.php
    if yes and then still your session is empty,then please put your both code in php tag.
    Barbara

  20. #20
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1)select.php
    <?php
    session_start();
    ob_start();


    if($_SERVER['REQUEST_METHOD'] == "GET")

    {
    $prod_id = "";
    $no_of_qt = "";
    $notes = "";
    $colour = "";
    // $brand_id = "";
    $brandname ="";
    }


    else if($_POST['Submit'] == "Get Details" )
    {

    header("Location:update.php");

    if($_POST['Submit']=="Back")
    {
    header("Location3.php");
    }

    $prod_id = $_POST['prod_id'];
    // validation();

    }


    $link = mysql_connect('**8', '**', '**')
    or die('Could not connect: ' . mysql_error());
    echo 'Connected successfully';
    mysql_select_db('***') or die('Could not select database');

    // Performing SQL query
    echo "connectivity is done";
    $query = "SELECT * FROM prod join brand
    on prod.b_id=brand.b_id and prod_id='".$prod_id."'";
    // echo $prod_no;
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());

    echo "<table>";


    $line = mysql_fetch_array($result, MYSQL_ASSOC);
    print_r($line);

    $_SESSION['prod_id']=$line['$prod_id'];
    $_SESSION['no_of_qt']=$line['$no_of_qt'];
    $_SESSION['colour']=$line['$colour'];
    $_SESSION['notes']=$line['$notes'];
    $_SESSION['brandname']=$line['$brandname'];
    echo "</table>\n";


    //mysql_close($link);
    //mysql_free_result(link);








    ?>
    <html>
    <head>
    <body>
    <form action="update.php" method="POST" name="productFrm">
    <table>
    <tr><td>prod_id/td>
    <td>
    <input type="text" name="$prod_id" value="" /><label class="errorText"><?=$prod_idErr;?></label></td></tr>
    <tr><td colspan=1><input type="submit" name="Submit" onClick="javascript:return validatepersonal(blogFrm);" value="Get Details"/><input type="submit" name="Submit" onClick="javascript:return validatepersonal(blogFrm);" value="Back"/>
    </td></tr>
    </table> <br>
    </form>
    </body>
    <? { }?>
    <html>


    2)update.php
    <?php
    session_start();
    ob_start();

    /*$_SESSION['prod_no'];
    $_SESSION['no_of_qt'];
    $_SESSION['brands'];
    $_SESSION['notes'];
    echo $_SESSION['notes'];*/




    if($_SERVER['REQUEST_METHOD'] == "GET"){

    echo $_SESSION['prod_id'];
    echo $_SESSION['no_of_qt'];
    echo $_SESSION['notes'];
    echo $_SESSION['colour'];
    echo $_SESSION['brandname'];



    }
    else if($_SERVER['REQUEST_METHOD'] == "POST")
    {
    $prod_id = $_POST['prod_id'];
    $no_of_qt = $_POST['no_of_qt'];
    $notes = $_POST['notes'];
    $colour = $_POST['colour'];
    $brandname =$_POST['brandname'];

    validation();

    if($_POST['submit'] == "Update")
    {

    $prod_id = $_POST['prod_id'];
    $no_of_qt = $_POST['no_of_qt'];
    $notes = $_POST['notes'];
    $colour = $_POST['colour'];
    $brandname =$_POST['brandname'];

    // validation();
    }

    if($_POST['Submit'] == "Back")
    {

    header("Location3.php");

    }

    }
    /*function validation()
    {
    global $prod_id,$prod_idErr,$no_of_qt;


    /*if(ctype_alnum($var)){
    echo " This is alphanumeric <br/>";
    }else{ echo "this is not alphanumeric<br />";}*/


    $validate = 1;

    if(($prod_id == "") ){
    $prod_noErr = "Please enter your Product number";
    $validate = 0;

    }else if (!ctype_alnum($prod_id)){
    // echo " This is alphanumeric <br/>";

    $prod_idErr = "Please enter alphanumeric value";

    $validate = 0;


    }
    if(($validate == 1) ){



    // Connecting, selecting database
    $link = mysql_connect('****', '****', '****')
    or die('Could not connect: ' . mysql_error());
    echo 'Connected successfully';
    mysql_select_db('*****') or die('Could not select database');

    // Performing SQL query
    $query = "UPDATE prod set prod_id='".$prod_id."', no_of_qt='".$no_of_qt."',notes='".$notes."'";
    $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    //echo "Updation is done";
    // Printing results in HTML
    if(mysql_affected_rows() > 0){

    echo "Updation is done". mysql_affected_rows();

    }else{

    echo "not done";
    }
    }
    }*/




    ?>
    <html>
    <head>
    <body>
    <form action="<?=$PHP_SELF;?>" method="post" name="productFrm">
    <table>

    <tr><td>prod_id/td>
    <td>
    <input type="text" name="prod_id" value="<?=$_SESSION['prod_id'];?>">readonly<label class="errorText"><?=$prod_idErr;?></label></td></tr>
    <tr><td>Brand/td><td> <SELECT NAME="brandname" value="<$_SESSION['brandname']:?>">readonly<label class="errorText"><?=$prod_idErr;?></label></td></tr>

    </tr>
    <tr><td>no_of_qt/td>
    <td>
    <input type="text" name="no_of_qt" value="<?=$_SESSION['no_of_qt'];?>" /><label class="errorText"><?=$no_of_qtErr;?></label></td></tr>
    tr><td>Colour/td>
    <td>
    <input type="text" name="colour" value="<?=$_SESSION['colour'];?>" /><label class="errorText"><?=$no_of_qtErr;?></label></td></tr>
    <tr><td>notes/td>
    <td>
    <input type="text" name="notes" value="<?=$_SESSION['notes'];?>" /><label class="errorText"><?=$notesErr;?></label></td></tr>
    <tr><td colspan=3><input type="submit" name="submit" onClick="javascript:return validatepersonal(blogFrm);" value="Update"/><input type="submit" name="Submit" onClick="javascript:return validatepersonal(blogFrm);" value="Back"/></td></tr>
    </table> <br>
    </form>
    </body>

    just have look on these codes
    for table creation
    prod(id,pk auto_increment,prod_id,b_id,no_of_qt,colour,notes)
    brand(b_id,pk,brandname).

    please see what is wrong and let me know
    thanks for your great patients to bare me..
    thanks in advance.

  21. #21
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello deepson2,

    I think in your code,there are errors.
    from your program,I think what you want is
    you will put the product is in text box in select.php
    then store the information in select.php itself.
    And then display the product information in respective text boxes in update.php which then updates the product details.

    if it is so let me know,i am trying on my machine.
    and please put your code in php code tags.
    Barbara

  22. #22
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this
    select.php
    PHP Code:
    ob_start();
    session_start();
    $link mysql_connect('localhost''root''')
    or die(
    'Could not connect: ' mysql_error());
    echo 
    'Connected successfully';
    mysql_select_db('testdb',$link) or die('Could not select database');
    echo 
    "connectivity is done";
    if(
    $_SERVER['REQUEST_METHOD'] == "GET")
    {
    $prod_id "";
    $no_of_qt "";
    $notes "";
    $brandname ="";
    }
    else if(
    $_POST['Submit'] == "Get Details" )
    {
        
    $prod_id $_POST['prod_id'];    
        
    $query "SELECT * FROM product join brand on product.brand_id=brand.brand_id and prod_id='".$prod_id."'";
        
    // echo $prod_no;
        
    $result mysql_query($query) or die('Query failed: ' mysql_error());    
        
    $line mysql_fetch_array($resultMYSQL_ASSOC);    
        
    $_SESSION['prod_id']=$line['prod_id'];
        
    $_SESSION['no_of_qt']=$line['no_of_qt'];    
        
    $_SESSION['notes']=$line['notes'];
        
    $_SESSION['brandname']=$line['$brandname'];
        
    header("Location:update.php");
    }

    if(
    $_POST['Submit']=="Back")
    {
        
    header("location3.php");

    Code HTML4Strict:
    <html>
    <head>
    <body>
    <form action="" method="POST" name="productFrm">
    <table>
    	<tr>
    		<td>prod_id</td>
    		<td>
    			<input type="text" name="prod_id" value="" />
    			<label class="errorText"><?php echo $prod_idErr;?></label>
    		</td>
    	</tr>
    	<tr>
    		<td colspan=1>
    		<input type="submit" name="Submit" value="Get Details"/>
    		<input type="submit" name="Submit" value="Back"/>
    		</td>
    	</tr>
    </table> <br>
    </form>
    </body>
    <html>

    and update.php

    PHP Code:
    session_start();
    ob_start();
    print_r($_SESSION); 
    you have to change the column name and table name as per your database table
    and let me know.
    Barbara

  23. #23
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    hi...
    what is a php tag actually?

  24. #24
    SitePoint Evangelist barbara1712's Avatar
    Join Date
    Apr 2007
    Location
    India
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    while replying to the thread
    there is a php code button on toolbar.click on it and write your
    php code in
    PHP Code:
     and 
    tag.
    Barbara

  25. #25
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    session_start
    ();
    //ob_start();

    $_SESSION['prod_no'];
    $_SESSION['no_of_qt'];
    $_SESSION['brands'];
    $_SESSION['notes'];
    echo 
    $_SESSION['notes'];

    echo 
    'Welcome to page #2<br />';


    // You may want to use SID here, like we did in page1.php
    //echo '<br /><a href="p2.php">page 1</a>';
    if($_SERVER['REQUEST_METHOD'] == "GET"){
                                      
                                 echo 
    $_SESSION['$prod_id']; 
                               echo 
    $_SESSION['$brandname'];
                               echo   
    $_SESSION['$qt_of_no'];  
                               echo   
    $_SESSION['$notes']; 
                             
         
          }
    else if(
    $_SERVER['REQUEST_METHOD'] == "POST")
               {

                  
                       if(
    $_POST['submit'] == "Update")
                       {

               
    $prod_id                     $_POST['prod_id'];
               
    $brandname                       =$_POST['brandname'];
               
    $no_of_qt                     $_POST['no_of_qt'];
               
    $notes                         $_POST['notes'];
               
               
    //validation();
              
    }
                   
                        if(
    $_POST['Submit'] == "Back")
                     {
                                           
             
    header("Location:p3.php");                     
                                                      
                    }
                   
               
        }


     
    // Connecting, selecting database
     
    $link mysql_connect('''''')
     or die(
    'Could not connect: ' mysql_error());
      echo 
    'Connected successfully';
      
    mysql_select_db('') or die('Could not select database');

     
    // Performing SQL query
     
    $query "UPDATE  product set  no_of_qt='".$no_of_qt."',notes='".$notes."'";
     
    $result mysql_query($query) or die('Query failed: ' mysql_error());
    //echo "Updation is done";
      // Printing results in HTML
       
    if(mysql_affected_rows() > 0){

     echo 
    "Updation is done"mysql_affected_rows();

       }else{

     echo 
    "not done";
     

     }
    HTML Code:
    <html>
    <head>
    <body>
    <form action="<?=$PHP_SELF;?>" method="post" name="productFrm">
    <table>
    
    <tr><td>prod_id:</td>
    <td>
    <input type="text" name="prod_id" value="<?=$_SESSION['prod_id'];?>" readonly/><label class="errorText"><?=$prod_idErr;?></label></td></tr>
    <tr><td>brandname:</td><td> <SELECT NAME="brandname" value="<?=$_SESSION['brandname'];?>" readonly/><label class="errorText"><?=$brand_idErr;?></label>
        <OPTION VALUE="select">SELECT</option>
        <OPTION VALUE=Lee>Lee</option>
        <OPTION VALUE=Denim>Denim</option>
        <option value=pepe>pepe</option>
        <option value=spyker>spyker</option>
        
        </SELECT></td></tr>
    </tr>
    <tr><td>no_of_qt:</td>
    <td>
    <input type="text" name="no_of_qt" value="<?=$_SESSION['no_of_qt'];?>" /><label class="errorText"><?=$no_of_qtErr;?></label></td></tr>
    <tr><td>notes:</td>
    <td>
    <input type="text" name="notes" value="<?=$_SESSION['notes'];?>" /><label class="errorText"><?=$notesErr;?></label></td></tr>
    <tr><td colspan=4><input type="submit" name="submit" onClick="javascript:return validatepersonal(blogFrm);" value="Update"/><input type="submit" name="Submit" onClick="javascript:return validatepersonal(blogFrm);" value="Back"/></td></tr>
    </table> <br>
    </form>
    </body>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •