Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

While viewing a detail page, a hidden form submits into a seperate table without having to click...

Guest
Oct 07, 2010 Oct 07, 2010

Hello, everyone:

I am having hard time explaining what I want.

Is there a way to insert data into a table without clicking on the submit button.

Let me explain.  I have a table that I want to populate.  In DW4 I have created a list of records.  I click on a link which opens a seperate page showing the details of my choosing.  What I want to do is have a seperate hidden table in my detail page that inserts my record I selected.  In my hidden table which is created by DW4 insert record to add certain information about the user and his/her choice of record.  The problem I am facing is DW4 creates a submit button.

My question is, in my list of records, when I click on a link from the list of records to view my details, how can I insert hidden information to another table without clicking on the submit button (which I do not want anyone to see) while in the detail page without it refreshing the page.  Is this possible.

I hope I have not made this confusing for anyone.

Thank you,

AdonaiEchad

TOPICS
Server side applications
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2010 Oct 07, 2010

Use AJAX

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

I know this sounds stupid.  But how do I do that.  I am not familuar with AJAX.  Does DW4 have it in their Spry insert select?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

My question is, in my list of records, when I click on a link from the list of records to view my details, how can I insert hidden information to another table without clicking on the submit button

Ajax is not necessary. You click a link to visit the detail page. Make the link submit the form with hidden fields. Problem solved!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

How do I make the link submit the form fileds?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

How do I make the link submit the form fileds?

lots of info here:

http://www.google.com/search?q=link+submit+form

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 08, 2010 Oct 08, 2010

>Ajax is not necessary. You click a link to visit the detail page.

>Make  the link submit the form with hidden fields. Problem solved!

He doesn't want the page to refresh when the data is inserted. If I understand correctly, he wants the user to interact with the page and have his interactions captured in the database as they occur.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

bregent wrote:

>Ajax is not necessary. You click a link to visit the detail page.

>Make  the link submit the form with hidden fields. Problem solved!

He doesn't want the page to refresh when the data is inserted. If I understand correctly, he wants the user to interact with the page and have his interactions captured in the database as they occur.

My understanding is that he wants info pertaining to the details of the link that was clicked in order to arrive at the detail page. So link page, click on link, go to detail page, enter info into databse. As suggested the link clicked to arrive at the detail page can be a form submit that enters info into the database.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 08, 2010 Oct 08, 2010

>My understanding is that he wants info

>pertaining to the details of the  link that

>was clicked in order to arrive at the detail page.

If that's the case then you're right, it's simple. I'm still not sure of the exact workflow he intends.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

You can also use spry if you want to stay on one page and enter info into the db without page reload.

<script src="http://labs.adobe.com/technologies/spry/includes/SpryData.js" type="text/javascript"></script>

<script type="text/javascript">

<!--

var update = function () {

//get the value of the form data

var the_info = document.info_form.the_info.value;

// update database

window.Spry.Utils.updateContent('response', 'update.php?info=' + the_info);

}

//-->

</script>


<form method="post" name="info_form" action="">

<input type="hidden" name="the_info" value="info here" />

<a href="#" title="update" onClick="update()">update without reload here</a>
<div id="response"></div>

</form>

Then on update.php (assuming php is being used since it was never mentioned = FAIL!!!) put the query to insert/update/whatever your table:

<?php require_once('Connections/your_connection_file.php');
  if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  {
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
  case "text":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;
  case "long":
  case "int":
  $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  break;
  case "double":
  $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  break;
  case "date":
  $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  break;
  case "defined":
  $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  break;
  }
  return $theValue;
  }
  }
  //get the info
  $the_info = "-1";
  if (isset($_GET['info'])) {
  $the_info = $_GET['info'];
  }
  mysql_select_db($database_your_connection, $your_connection);
  $query_the_info = sprintf("INSERT INTO info_table (the_info) VALUES (%s)", GetSQLValueString($the_info, "text"));
  $the_info = mysql_query($query_the_info, $your_connection) or die(mysql_error());


// let user know the database is updated
  echo "<span id=\"response\">Database Updated</span>";

?>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

As iPHP states that's what I want.

For example lets say the list page is the following.

list.php

Show details for link 1

Show details for link 2

Show details for link 3

Show details for link 4

Show details for link 5

I know that on my link 3 <a> tag shows the following.

<a href="details.php?link=<?php echo $row_rsUsers['linkid']; ?>">Show details for link 3</a>

Once I click on that link 3 it goes to details.php page.

There I see all the details pertaining to the Link 3 that I clicked on.

When the details.php page is showing, on that page can a hidden form populate a different table and processed behind the sceen without refreshing.

Or as I am hearing in this form it is better that the table that I wish to be populated is populated through selecting a link which will initiate the submit.  So how does it work if my hidden form with no submit button populates the hidden form in the list.php once I click on my link 3 where it directs me to my details.php page?

list.php

Show details for link 1

Show details for link 2

Show details for link 3

Show details for link 4

Show details for link 5

I know that on my link 3 <a> tag shows the following.

<a href="details.php?linkid=<?php echo $row_rsUsers['linkid']; ?>">Show details for link 3</a>

<form id="userInfo" name="userInfo" method="post" action="">
  <input type="hidden" name="username" id="<?php echo $row_rsUsers['username']; ?>" />
  <input type="hidden" name="linkid" id="<?php echo $row_rsUsers['linkid']; ?>" />
  <input type="hidden" name="useremail" id="<?php echo $row_rsUsers['useremail']; ?>" />
  <input type="hidden" name="browser" id="<?php echo $_SERVER['HTTP_USER_AGENT']; ?>" />
</form>

I hope this explains better my thinking.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

As iPHP states that's what I want.

When the details.php page is showing, on that page can a hidden form populate a different table and processed behind the sceen without refreshing.

No no no dude. Do not put the form on details.php Put the form on list.php and, as suggested earlier with provided examples and explanation in post #5, use the link to submit the form.

So how does it work if my hidden form with no submit button populates the hidden form in the list.php once I click on my link 3 where it directs me to my details.php page?

What do you mean "how does it work"?... Put the php code to process the form data on details.php so when details.php is loaded from clicking on link that submits form in list.php the POST data from the form submission on list.php will insert the populated data into details.php before the page is loaded.

If the dynamic data in your form is from a recordset on details.php then no form is required anyway, simply run a query on details.php to insert the dynamic data from the recordset into another table. Seems redundant to populate so many fields if they're already in another table, IMO. All's you'd need is the primary key ID for link and user then add any additional data that isn't part of the original table.  (looks like browser type is all that's "really" being added into the new table)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

Ok, so I looked at the examples that are out there such as below.

<a href="javascript:getsupport('Paid')">Paid Support</a>

I was able to use it, however, how do I incorporate the javascript to my dynamic link such as below?

<a href="details.php?link=<?php echo $row_rsUsers['linkid']; ?>">Show details for link 3</a>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 08, 2010 Oct 08, 2010

I looked at the examples that are out there such as below.

<a href="javascript:getsupport('Paid')">Paid Support</a>

how do I incorporate the javascript to my dynamic link such as below?

<a href="details.php?link=<?php echo $row_rsUsers['linkid']; ?>">Show details for link 3</a>

<form id="userInfo" name="userInfo" method="post" action="details.php?link=<?php echo $row_rsUsers['linkid']; ?>">

make sense?

Honestly though, I'd bag the whole form idea and think about my recommendation in the last paragraph of the last post (#11) that I submitted.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 09, 2010 Oct 09, 2010

Because I am not strong in PHP, if what you are saying regarding

last paragraph of the last post (#11)

Entering a query as you had suggested.

If the dynamic data in your form is from a recordset on details.php then no form is required anyway, simply run a query on details.php to insert the dynamic data from the recordset into another table. Seems redundant to populate so many fields if they're already in another table, IMO. All's you'd need is the primary key ID for link and user then add any additional data that isn't part of the original table.  (looks like browser type is all that's "really" being added into the new table)

How do I...

Run a query on details.php to insert the dynamic data from the recordset into another table.

What would the query be using the info I gave above.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 09, 2010 Oct 09, 2010

>How do I...

Run a query on details.php to insert the dynamic data from the recordset into another table.

As iPHP suggested, you probably don't need to. You simply need to store the id of the link they click on. The details are already in another table and can be derived by a simple SQL query. In some cases, you may want to store details from one table into another table, if data in the source is subject to change and you need to capture the 'as is' state.  But you always need to ask yourself if you need to be storing redundant data. If you do, then use the MySQL insert-select syntax:

http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 04, 2010 Nov 04, 2010

I am going to refine my thinking here, it maybe a little bit of a repeat.

In my list.php page where I have links that goes to my details.php.

In my details.php page can it execute without refreshing, without hitting a submit button through a form or using AJAX?

Once I click on my list.php link that leads me to my details.php page as soon as that details.php page opens up in my browser, can there be a hidden form or some PHP code that can insert into a different table?  Some information from that different table that is being populated is from the details.php page and some is other stuff like I.P. address and timestamps.

I hope this simplifies what I am looking for.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 04, 2010 Nov 04, 2010

Your refinement is a complete repeat of the discussion. It doesn't simplify what you're looking for because you've already been clearly described what you're looking for and you've been provided with a solution. As stated before: use the info passed from list.php to run a query on details.php. Here's an example:

list.php has links w/ URL parameters like so:

<a href="details.php?id=1">product 1</a>

<a href="details.php?id=2">product 2</a>

<a href="details.php?id=3">product 3</a>

<a href="details.php?id=4">product 4</a>

On details.php set a query to insert a record into the db based on the URL parameter and session variable of the logged in user:

INSERT INTO table_name (product_id, client, ip_address, date)
VALUES ($_GET['id'], $_SESSION['username'], $_SERVER['REMOTE_ADDR'], date("Y-m-d"))

Forget about the hidden form. Don't ever mention it again in this discussion thread. Use an INSERT MySQL query to insert dynamic values into your database table.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 04, 2010 Nov 04, 2010

>Once I click on my list.php link that leads

>me to my details.php page as  soon as that

>details.php page opens up in my browser,

>can there be a  hidden form or some PHP

>code that can insert into a different table?

You don't need a hidden form. Forms are a user interface device - used to gather data input from users. You simply need to to execute a script when the page opens. The script can process data passed to it from forms on other pages, from session variables, from server variables, or from query strings. You can then use that data in you insert statement. Or you can use it to extract more data from your database that can then be used in your insert statement. You don't need AJAX to accomplish any of this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 04, 2010 Nov 04, 2010

In your statement,

You simply need to to execute a script when the page opens. The script can process data passed to it from forms on other pages, from session variables, from server variables, or from query strings. You can then use that data in you insert statement. Or you can use it to extract more data from your database that can then be used in your insert statement.

how do I make a query that inserts as you stated.

Sounds rediculous but I do not know how to hand code this.  I am so used to having DW4 code the insert but it creates a form for me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 04, 2010 Nov 04, 2010

AdonaiEchad wrote:

In your statement,

You simply need to to execute a script when the page opens. The script can process data passed to it from forms on other pages, from session variables, from server variables, or from query strings. You can then use that data in you insert statement. Or you can use it to extract more data from your database that can then be used in your insert statement.

how do I make a query that inserts as you stated.

Sounds rediculous but I do not know how to hand code this.  I am so used to having DW4 code the insert but it creates a form for me.

I provided an example in the last reply. Here's a hand-hold:

<?php

// If URL parameter is set and user is logged in then connect to database and insert query.

if ((isset($_GET['id'])) && (isset($_SESSION['username']))) {

$servername='localhost';
$dbuser='xxxxxx';
$dbpassword='xxxxxx';
$dbname='xxxxxx';

// Connect to server and select database.
mysql_connect("$servername", "$dbuser", "$dbpassword")or die("cannot connect");
mysql_select_db("$dbname")or die("cannot select DB");

// Insert data into database

mysql_query("INSERT INTO table_name

(product_id, client, ip_address, date)
VALUES

($_GET['id'], $_SESSION['username'], $_SERVER['REMOTE_ADDR'], date("Y-m-d"))");

} ?>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 01, 2010 Dec 01, 2010
LATEST

Everything is working properly.

I want to take it to the next level, how do I update just like I have inserted.

Insert

--------

// Insert data into database

mysql_query("INSERT INTO table_name

(product_id, client, ip_address, date)
VALUES

($_GET['id'], $_SESSION['username'], $_SERVER['REMOTE_ADDR'], date("Y-m-d"))");

} ?>

Update

---------

$colname_getUser = "-1";
if (isset($_GET['userid'])) {
  $colname_getUser = $_GET['userid'];
}
mysql_select_db($database_conOnDemand, $conOnDemand);
$query_getUser = sprintf("SELECT * FROM useracct WHERE userid = %s", GetSQLValueString($colname_getUser, "text"));
$getUser = mysql_query($query_getUser, $conOnDemand) or die(mysql_error());
$row_getUser = mysql_fetch_assoc($getUser);
$totalRows_getUser = mysql_num_rows($getUser);

// update data into database

mysql_query("UPDATE useracct SET lastlogindate=%s, WHERE userid=%s",
                       GetSQLValueString(date('Y-m-d H:i:s'), "date"),
                       GetSQLValueString($row_getUser['userid'], "text"));

I cannot get the update to fill in the field "lastlogindate"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines