Jump to content

Recommended Posts

Hi

I have a form where reps add reports. I also have a link where reps can lookup account no by entering their name and customer name. once account no is found they have to type that number in the form. Is possible to auto-select account no from lookup page and add it to the account no textbox on the form.
i have added a link in account lookup page but not sure what to do next to make it work.

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Account No|Customer Name |Town | Post Code |Rep Name | Click to add
xxxx | abc |xyz | xxxx xxx |aaaaa |ADD [/quote]

here is the code:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
<?php

require 'conn.php';

if (($_GET['customer_name']!=""))
{
$sql = "select * from rep_table WHERE repname like '".$_GET['repname']."' and";
if ($_GET['customer_name']!="")
{
$sql = $sql." CUSTOMER_NAME LIKE '".$_GET['customer_name']."%'";
}

$result = mysql_query($sql);
if (!$result)
{
echo 'Could not run query: ' . mysql_error();
}

echo "<table border=1 align='center' class='rep' width ='' " .
"cellspacing='0'"."callpadding='5'>\n";
echo "<tr><th class='searchHeader'><caption><b> Search Results</b></caption> </th></tr>\n";
echo "<tr><td align='center'><b>Account No:</td><td><b>Customer Name:</td><td><b>Town:</td><td><b>Post Code:</td><td><b>Rep Name:</b></td><td>Click to add</td></tr>";

if ($result and !mysql_num_rows ($result))
{
echo "<tr class='row1'><td colspan='4'>No results found that match the ";
echo "search term(s)";
echo '</br><font color="red">please go back and try again</font></br>';

}
else
{
while($row = mysql_fetch_array($result, MYSQL_BOTH))
{
$ACCOUNT_NO=$row["ACCOUNT_NO"];
$CUSTOMER_NAME=$row["CUSTOMER_NAME"];
$ADDRESS3=$row["ADDRESS3"];
$POST_CODE=$row["POST_CODE"];
$Rep_Name=$row["Rep_Name"];

echo "<tr><td align='center'>$ACCOUNT_NO</td>
<td>$CUSTOMER_NAME</td>
<td>$ADDRESS3</td>
<td>$POST_CODE</td>
<td>$Rep_Name</td>
<td><a href='repform.php?cmd=update&account_no=$ACCOUNT_NO'>ADD</a></td></tr>";
}
}
}
echo "</table>";
?> [/quote]

thanks in advance
Sab
Link to comment
https://forums.phpfreaks.com/topic/11569-select-and-copy-data-by-a-click/
Share on other sites

Hi just some general points first.

There are quite a few issues with the _GET verification. First of all you should always ?isset() _GET vars. The second if query is the same as the first so it should be emmited. Aslo "AND" should be moved to the optional sql as it will make an open query if the optional is not appended.

I will not go into the code too much, but what you could can do is simply add a ?user=<?=$user?> on the redirect back to the other page, or added the user lookup on the same page (hidden until $_GET['search']) and add it with java onclick="documentgetElementById('user_name').value="<?=$user_name?>";"

here's a quick run over what I stated in a verbal form:

<first page>
<? if (isset ($_GET['add_account'])) include ("serachform.php"); ?>
in searchform.php,
onclick add, value of user in form on first page is set to the value from search query

I am assuming this is what you meant by autoselecting yes?
i think what he meant was when the user selects account info based on the account number in order to add/edit account information, he wants the known value (the account number) to be automatically put as the value in the text input field (see [b]Wisewood's[/b] post)
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.