Jump to content


Photo

Reload page after submitting


  • Please log in to reply
5 replies to this topic

#1 Levinax

Levinax
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 12 April 2006 - 09:18 PM

so i have a script where i can update entries in my database. i have all the SQL worked out to where i know that hitting the submit button successfully updates the information in the database. however, the information on the form on the current page still displays the old information. if i hit F5 and refresh the page, it comes up with the new info, but i was wondering if there was a way to do it so it would automatically refresh after hitting the submit button?

here is my function... i know its got to be something with my data flow... but i am not a programmer (my boss seems to think i am though =\ )

function edit_form($db, $hostname)
{
if (isset($hostname))
        {
        echo "Update Entry Form";
        $edittype = "update";
        //query db and put results in array to populate form
        $lkup = "SELECT * FROM info WHERE hostname = '$hostname'";
        $editqry = pg_query($db, $lkup);
        $editres = pg_fetch_array($editqry);
        }
else
        {
        echo "Add New Form";
        $edittype = "insert";
        }

echo"<BR>";

echo"
<BR>
<table>
        <form method=POST name=input>
                <tr><td>Hostname:</td><td>      <input type=\"text\" name=\"host\" value=\"$hostname\"></td></tr>
                <tr><td>MAC:</td><td>           <input type=\"text\" name=\"mac\" value=\"$editres[mac_address]\"></td></tr>
                <tr><td>OS:</td><td>            <input type=\"text\" name=\"os\" value=\"$editres[os]\"></td></tr>
                <tr><td>SP:</td><td>            <input type=\"text\" name=\"sp\" value=\"$editres[service_pack]\"></td></tr>
                <tr><td>CPU:</td><td>           <input type=\"text\" name=\"cpu\" value=\"$editres[processor]\"></td></tr>
                <tr><td>RAM:</td><td>           <input type=\"text\" name=\"ram\" value=\"$editres[ram]\"></td></tr>
                <tr><td>HDD:</td><td>           <input type=\"text\" name=\"hdd\" value=\"$editres[hard_drive]\"></td></tr>
                <tr><td>Optical:</td><td>       <input type=\"text\" name=\"cdr\" value=\"$editres[optical_type]\"></td></tr>
                <tr><td>FDD:</td><td>           <input type=\"text\" name=\"fdd\" value=\"$editres[floppy]\"></td></tr>
                <tr><td>Dell Tag:</td><td>      <input type=\"text\" name=\"dell\" value=\"$editres[dell_service_tag]\"></td></tr>
                <tr><td>Location:</td><td>      <input type=\"text\" name=\"locat\" value=\"$editres[location]\"></td></tr>
                <tr><td>Store:</td><td>         <input type=\"text\" name=\"store\" value=\"$editres[store]\"></td></tr>
                <tr><td>Dept:</td><td>          <input type=\"text\" name=\"dept\" value=\"$editres[dept]\"></td></tr>
                <tr><td>Comments:</td><td>      <input type=\"text\" name=\"comment\" value=\"$editres[comments]\"></td></tr>
                <input type=hidden name=edit value=$edittype>
                <tr><td colspan=\"2\" align=\"center\"><input type=submit value=\"Submit\" action=\"$updqry\" onlcick=\"edit_form($db, $hostname)\"></td></tr\
>
        </form>
</table>
";

if($edittype = "update"){
        $updtbl = "UPDATE info
           SET mac_address='$_POST[mac]', os='$_POST[os]', service_pack='$_POST[sp]', processor='$_POST[cpu]', ram='$_POST[ram]',
           hard_drive='$_POST[hdd]', optical_type='$_POST[cdr]', floppy='$_POST[fdd]', dell_service_tag='$_POST[dell]', store='$_POST[store]',
           dept='$_POST[dept]', location='$_POST[locat]', comments='$_POST[comment]'
           WHERE hostname = '$hostname'";
        }
else if($edittype = "addnew"){
        $updtbl = "INSERT INTO info
           VALUE '$_POST[host]', '$_POST[mac]', '$_POST[os]', '$_POST[sp]', '$_POST[cpu]', '$_POST[ram]',
           '$_POST[hdd]', '$_POST[cdr]', '$_POST[fdd]', '$_POST[dell]', '$_POST[store]',
           '$_POST[dept]', '$_POST[comment]', '$_POST[locat]'";
        }

$updqry = pg_query($db, $updtbl);
}



#2 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 13 April 2006 - 12:12 AM

hi, try changing
<form method=POST name=input>
to
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" name="input">

got a problem? Google helps many of those in need

#3 Levinax

Levinax
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 April 2006 - 04:45 PM

[!--quoteo(post=364234:date=Apr 12 2006, 05:12 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 12 2006, 05:12 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
hi, try changing
<form method=POST name=input>
to
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" name="input">
[/quote]

nope, that gives me the following error:

[Thu Apr 13 09:34:16 2006] [error] PHP Parse error:  parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/test/public_html/test/test4.php on line 262


#4 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 13 April 2006 - 06:26 PM

are you echoing the form inside of php? if you are try this :
echo ' ....

<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="input">

hope that helps!
got a problem? Google helps many of those in need

#5 Levinax

Levinax
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 13 April 2006 - 06:34 PM

[!--quoteo(post=364512:date=Apr 13 2006, 11:26 AM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 13 2006, 11:26 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
are you echoing the form inside of php? if you are try this :
echo ' ....

<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="input">

hope that helps!
[/quote]

yes, i am echoing it in PHP, and that gives me the same parse error.

#6 earl_dc10

earl_dc10
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 13 April 2006 - 06:50 PM

ensure that your echo statement uses single quotes for the echoing ', if you have doubles " you'll need to do an escape slash
echo "
<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\" name=\"input\">

got a problem? Google helps many of those in need




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users