Jump to content

getting data twice in array


murli800

Recommended Posts

My aim is to make an enquiry form and its database name is ashish and table name is mydata...everytime i am inserting data and then displaying it on the browser with the use of print_r getting each input data twice...attacthing my code ..help me..thanx in advance

 

this file is form.php

<?php include("dbconnect.php");

        include("cwfunction.php")?>

 

<form name="form1" action="#" method="post">

      Name<input name="stuname" type="text" value=""><br/>

    Address<input name="address" type="text" value=""><br/>

    Contact<input name="contact" type="text" value=""><br/>

    Email<input name="email" type="text" value=""><br/>

    Internet<input name="how" type="radio" value="internet"><br/>

    Friend<input name="how" type="radio" value="friend"><br/>

    Other<input name="how" type="radio" value="other"><br/>

 

    <input name="submit" type="submit" value="ENTER"><br/>

</form>

<?php

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

$stuname=$_POST['stuname'];

$address=$_POST['address'];

$contact=$_POST['contact'];

$email=$_POST['email'];

$how=$_POST['how'];

 

insert_data($stuname,$address,$contact,$email,$how,$connect);

display_data();

 

 

 

 

echo "<table border=1>";

    echo "<tr>";

        echo "<td>Sr.No</td>";

        echo "<td>Student Name</td>";

        echo "<td>Address</td>";

        echo "<td>Contact no</td>";

        echo "<td>email</td>";

        echo "<td>how</td>";

        echo "<td>edit</td>";

        echo "<td>delete</td>";

    echo "</tr>";

 

 

   

    echo "</table>";

 

?>

 

this file is dbconnect.php

<?php

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

$connect=  mysql_connect("localhost","root","") or die("Connection Error".  mysql_error());

        //echo "connection established";

        if(mysql_select_db("ashish",$connect))

        {

            //echo "<br/>database selected";

        }

       

 

?>

 

 

this file is cwfunction.php

<?php

/*

* To change this template, choose Tools | Templates

* and open the template in the editor.

*/

function insert_data($stuname,$address,$contact,$email,$how,$connect)

{

  global $stuname;

    global $address;

    global $contact;

    global $email;

  global $how;

    global $connect;

 

    $query="INSERT INTO mydata(student_name,address,contact,email,how) VALUES('$stuname','$address','$contact','$email','$how')";

    $result=mysql_query($query,$connect);

}

 

function display_data()

{

    echo "i m in display data";

    $query="SELECT * FROM mydata";

    $result=mysql_query($query);

    $row = mysql_fetch_array($result);

    print_r($row);

//    if($result)

//    {

//        $arr = array();

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

//        {

//            array_push($arr,$row);

//        }

//

//

//

//    }

 

    //return $arr;

}

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.