#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    United Kingdom
    Posts
    3
    Rep Power
    0
    What I'm trying to do is display the records in a table format, and then when hit the insert button at the bottom of the page. It then goes to another script which then displays the form, and then inserts the values in the database.

    If you look at both scripts, can anyone tell me where I am going wrong...

    display3.php

    <html>
    <head>
    </head>

    <body>
    <?php

    // set up some variables

    // server name
    $server = "localhost";

    // username
    $user = "oz";

    // password
    $password = "smarties12";

    // database to query
    $db = "oz";

    // open a connection to the database
    $connection = mysql_connect($server, $user, $password) or die("invalid server or user");

    // formulate the SQL query - same as above
    $query = "select * from unix_team_links" or die("Error in query");

    // run the query on the database
    $result = mysql_db_query($db, $query, $connection) or die("Error in query");

    // display the result

    echo "<form method=post action=addon.php>";
    echo "<table width=450 border=1 cellspacing=0 cellpadding=0>";
    echo "<tr>
    <td width=150 align=left><b>UID</b></td>
    <td width=100 align=left>Title</td>
    <td width=100 align=left>URL</td>
    <td width=100 align=left>&nbsp;</td>
    </tr>";

    // with a while loop
    // this loop will iterate as many times as there are records

    while($myrow = mysql_fetch_array($result))
    {
    $uid = $myrow["uid"];
    $title = $myrow["title"];
    $url1 = $myrow["url1"];


    echo "<tr><td width=150 align=left>$uid</td><td width=100
    align=left>$title</td><td width=100 align=left><a
    href=$url1>$title</a></td><td width=100 align=left>&nbsp;</td></tr>";
    echo "<tr><td colspan=4 align=right><input type=submit name=submit value=Insert More></td></tr>";
    echo "</form>";
    }

    // memory flush
    mysql_free_result($result);

    ?>


    </body>
    </html>

    addon.php

    <?php

    // check if the form has been submitted display form

    if($submit)
    {
    ?>

    <html>
    <head><basefont face="Arial"</head>
    <body>
    <h3>Enter your Details</h3>
    <form method="post" action="addon.php">
    <table
    <tr>
    <td>UID</td>
    <td><input name="username" length="5" maxlength="4"></td>
    </tr>
    <tr>
    <td>Title</td>
    <td><input name="title1" length="30" maxlength="30"></td>
    </tr>
    <tr>
    <td>URL</td>
    <td><input name="url1" length="30"></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    <?php
    }
    // or process form input
    else
    {
    ?>

    <?php

    // connect to database

    // initilise database conection

    $conn = mysql_connect("localhost", "oz", "smarties12") or die("invalid server or user");

    // select database

    mysql_select_db("oz", $conn);

    // formulate and run query

    $query="insert into unix_team_links(uid,title1,url1) values ('$username','$title1','$url1')";

    $result = mysql_query($query,$conn) or die("Error in query");

    ?>

    <html>
    <head><basefont face="Arial"></head>
    <body>
    <center>
    <h3>Success!!</h3>
    <table>
    <tr>
    <td><?php echo $username; ?>'s has been saved</td>
    </tr>
    </center>
    </body>
    </html>

    <?php

    }

    ?>
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    // formulate the SQL query - same as above
    $query = "select * from unix_team_links" or die("Error in query");
    >>


    yea,
    i just gone through the script .and changed few lines..try that...

    display3.php

    <html>
    <head>
    </head>

    <body>
    <?php

    // set up some variables

    // server name
    $server = "localhost";

    // username
    $user = "oz";

    // password
    $password = "smarties12";

    // database to query
    $db = "oz";

    // open a connection to the database
    $connection = mysql_connect($server, $user, $password) or die("invalid server or user");

    // formulate the SQL query - same as above
    $query = "select * from unix_team_links";


    mysql_select_db($db,$connection);

    //select your database..


    // run the query on the database
    $result = mysql_query($query,$connection) or die("Error in query");

    // display the result

    if(mysql_num_rows($result)>0){
    //yea, result is their...

    echo "<form method=post action=addon.php>";
    echo "<table width=450 border=1 cellspacing=0 cellpadding=0>";
    echo "<tr>
    <td width=150 align=left><b>UID</b></td>
    <td width=100 align=left>Title</td>
    <td width=100 align=left>URL</td>
    <td width=100 align=left> </td>
    </tr>";

    // with a while loop
    // this loop will iterate as many times as there are records

    while($myrow = mysql_fetch_array($result))
    {
    $uid = $myrow["uid"];
    $title = $myrow["title"];
    $url1 = $myrow["url1"];


    echo "<tr><td width=150 align=left>$uid</td><td width=100
    align=left>$title</td><td width=100 align=left><a
    href="$url1">$title</a></td><td width=100 align=left> </td></tr>";
    echo "<tr><td colspan=4 align=right><input type=submit name=submit value=Insert More></td></tr>";
    echo "</form>";
    }
    }else{
    //no result for your query..
    echo "No !! Resultsn";
    }
    ?>
    </body>
    </html>

    addon.php


    <html>
    <head><basefont face="Arial"></head>
    <body>

    <?php

    // check if the form has been submitted display form

    if(isset($submit))
    {
    //when clicks on submit button..

    // connect to database

    // initilise database conection

    $conn = mysql_connect("localhost", "oz", "smarties12") or die("invalid server or user");

    // select database

    mysql_select_db("oz", $conn);

    // formulate and run query

    $query="insert into unix_team_links(uid,title1,url1) values ('$username','$title1','$url1')";

    $result = mysql_query($query,$conn) or die("Error in query");
    ?>

    <center>
    <h3>Success!!</h3>
    <table>
    <tr>
    <td><?php echo $username; ?>'s has been saved</td>
    </tr>
    </center>


    <?php
    }
    else
    {
    // or process form input
    ?>
    <h3>Enter your Details</h3>
    <form method="post" action="addon.php">
    <table
    <tr>
    <td>UID</td>
    <td><input name="username" length="5" maxlength="4"></td>
    </tr>
    <tr>
    <td>Title</td>
    <td><input name="title1" length="30" maxlength="30"></td>
    </tr>
    <tr>
    <td>URL</td>
    <td><input name="url1" length="30"></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
    </tr>
    </table>
    </form>

    <?php
    }
    ?>
    </body>
    </html>


    Good Luck!!


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited September 13, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    United Kingdom
    Posts
    3
    Rep Power
    0
    Didn't work I'm afraid!!

    Originally posted by woldie501:
    What I'm trying to do is display the records in a table format, and then when hit the insert button at the bottom of the page. It then goes to another script which then displays the form, and then inserts the values in the database.

    If you look at both scripts, can anyone tell me where I am going wrong...

    display3.php

    <html>
    <head>
    </head>

    <body>
    <?php

    // set up some variables

    // server name
    $server = "localhost";

    // username
    $user = "oz";

    // password
    $password = "smarties12";

    // database to query
    $db = "oz";

    // open a connection to the database
    $connection = mysql_connect($server, $user, $password) or die("invalid server or user");

    // formulate the SQL query - same as above
    $query = "select * from unix_team_links" or die("Error in query");

    // run the query on the database
    $result = mysql_db_query($db, $query, $connection) or die("Error in query");

    // display the result

    echo "<form method=post action=addon.php>";
    echo "<table width=450 border=1 cellspacing=0 cellpadding=0>";
    echo "<tr>
    <td width=150 align=left><b>UID</b></td>
    <td width=100 align=left>Title</td>
    <td width=100 align=left>URL</td>
    <td width=100 align=left>*</td>
    </tr>";

    // with a while loop
    // this loop will iterate as many times as there are records

    while($myrow = mysql_fetch_array($result))
    {
    $uid = $myrow["uid"];
    $title = $myrow["title"];
    $url1 = $myrow["url1"];


    echo "<tr><td width=150 align=left>$uid</td><td width=100
    align=left>$title</td><td width=100 align=left><a
    href=$url1>$title</a></td><td width=100 align=left>*</td></tr>";
    echo "<tr><td colspan=4 align=right><input type=submit name=submit value=Insert More></td></tr>";
    echo "</form>";
    }

    // memory flush
    mysql_free_result($result);

    ?>


    </body>
    </html>

    addon.php

    <?php

    // check if the form has been submitted display form

    if($submit)
    {
    ?>

    <html>
    <head><basefont face="Arial"</head>
    <body>
    <h3>Enter your Details</h3>
    <form method="post" action="addon.php">
    <table
    <tr>
    <td>UID</td>
    <td><input name="username" length="5" maxlength="4"></td>
    </tr>
    <tr>
    <td>Title</td>
    <td><input name="title1" length="30" maxlength="30"></td>
    </tr>
    <tr>
    <td>URL</td>
    <td><input name="url1" length="30"></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    <?php
    }
    // or process form input
    else
    {
    ?>

    <?php

    // connect to database

    // initilise database conection

    $conn = mysql_connect("localhost", "oz", "smarties12") or die("invalid server or user");

    // select database

    mysql_select_db("oz", $conn);

    // formulate and run query

    $query="insert into unix_team_links(uid,title1,url1) values ('$username','$title1','$url1')";

    $result = mysql_query($query,$conn) or die("Error in query");

    ?>

    <html>
    <head><basefont face="Arial"></head>
    <body>
    <center>
    <h3>Success!!</h3>
    <table>
    <tr>
    <td><?php echo $username; ?>'s has been saved</td>
    </tr>
    </center>
    </body>
    </html>

    <?php

    }

    ?>
    [/QUOTE]

  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    please post the error lines..


    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    United Kingdom
    Posts
    3
    Rep Power
    0
    Shiju

    What I've done now is alter the !$submit variable so that now it reads !$username, because the script thought that the user has submitted the form which bypasses the form being displayed, which now works like a dream!! But hey thanks for the help!

    I'm in the early stages in learning PHP, could you recommend any good websites which suggest in learning more. I know hotscripts.com is a good site I've come across..

Similar Threads

  1. Replies: 2
    Last Post: February 11th, 2004, 03:15 PM
  2. Updating database problem
    By mahugl in forum PHP Development
    Replies: 1
    Last Post: February 2nd, 2004, 01:32 AM
  3. Problems updating mysql database using Php
    By bassist84 in forum PHP Development
    Replies: 2
    Last Post: January 18th, 2004, 04:26 PM
  4. Updating database browser-side?
    By ace2600 in forum HTML Programming
    Replies: 3
    Last Post: January 12th, 2004, 04:11 PM
  5. Database Fetching and updating Data
    By deathsythe in forum PHP Development
    Replies: 8
    Last Post: January 3rd, 2004, 11:02 PM

IMN logo majestic logo threadwatch logo seochat tools logo