Jump to content

Recommended Posts

It seems that either my data is not getting passed or is not being read in correctly.

Here is the code which I am attempting to use to pass my data:

 

<code>

<td><form action="EditCustomer.php" method="GET">

<input type="hidden" name="customer_id" value="<?echo($data['customer_id']);?>"/>

<input type="submit" style="height:50px" style="width:100px" name="Edit Record" value="Edit Record"/></form></td>

</code>

 

Here is where I am trying to call the data:

<code>

<?php

include 'common.php';

?>

 

<Title>Edit Customer</title>

<?

dbConnect();

$result=dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);

print_r($GET)

?>

<html>

<body>

<table>

<tr>

<td><input type="text" style="width:148px" name="FirstName" value="<?echo$GET['first_name'];?>"/></td>

</tr>

</table>

</body>

</html>

<?

dbClose();

?>

</code>

 

The textbox right now is blank.  Where did I go wrong?

Link to comment
https://forums.phpfreaks.com/topic/142109-problems-with-get-method/
Share on other sites

ok....let's step this piece by piece...first, confirm your hidden input is populating correctly. do this by making it a normal field that you can see:

 

<td><form action="EditCustomer.php" method="GET">
                  <input type="text" name="customer_id" value="<?php echo $data['customer_id']; ?>"/>
                  <input type="submit" style="height:50px" style="width:100px" name="Edit Record" value="Edit Record"/></form></td>

 

does that print text boxes out with the proper IDs in them?

<td><form action="EditCustomer.php" method="POST">
                  <input type="hidden" name="customer_id" value="<? echo $data['customer_id'];?>"/>
                  <input type="submit" style="height:50px" style="width:100px" name="Edit Record" value="Edit Record"/></form></td>

 

 

<?php
include 'common.php';
?>

<Title>Edit Customer</title>
<?php
dbConnect();
$result=mysql_query("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_POST['customer_id']);


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

?>
<html>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?echo $row['first_name'];?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?php
}
dbClose();
?>

<td><form action="EditCustomer.php" method="POST">
                  <input type="hidden" name="customer_id" value="<? echo $data['customer_id'];?>"/>
                  <input type="submit" style="height:50px" style="width:100px" name="Edit Record" value="Edit Record"/></form></td>

 

 

<?php
include 'common.php';
?>

<Title>Edit Customer</title>
<?
dbConnect();
$result=mysql_query("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_POST['customer_id']);


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

?>
<html>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?echo $row['first_name'];?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
}
dbClose();
?>

 

those queries won't work...you can't just change the function from dbQuery() to mysql_query() like that...

<td><form action="EditCustomer.php" method="POST">
                  <input type="hidden" name="customer_id" value="<? echo $data['customer_id'];?>"/>
                  <input type="submit" style="height:50px" style="width:100px" name="Edit Record" value="Edit Record"/></form></td>

 

 

<?php
include 'common.php';
?>

<Title>Edit Customer</title>
<?php
dbConnect();

$result=mysql_query("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id =  $_POST['customer_id']");


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

?>
<html>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?echo $row['first_name'];?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?php
}
dbClose();
?>

 

dont see anything wrong with this query

well...first off...this is all sorts of wrong:

<?echo$GET['first_name'];?>

...but i don't think that is the problem. where is the first_name coming from? the database?

 

Probably not, but still good practice. Makes debugging easier imo.

 

Just noticed he is also using:

 

print_r($GET)

 

Instead of

print_r($_GET);

 

Which may print the variables.

 

 

Yes that textbox does contain the correct customer_id.

 

ok, switch that back to a hidden input, and let's move on to EditCustomer.php. What are you using for your database queries. aka, where is dbQuery() coming from? is that something you wrote or got from somewhere else? i ask because i need to know what dbQuery() returns. if you want, just post the code for that function.

I had tried $_GET as well and it also returned nothing.  I get the feeling that it is not actually getting the data from the previous page though I do not know if this is a result of the connection string being incorrect or if it is a result of the submit button on the page before it being wrong.

function dbQuery($query)

{

global $is_connected, $link, $results;

if ($is_connected != 1)

{

dbConnect();

}

 

$counter = count($results) + 1;

 

for($incr = (func_num_args() - 1); $incr > 0; $incr--)

{

$argvalue = func_get_arg($incr);

$query = str_replace("%" . $incr . "", "'" . dbEscape($argvalue) . "'", $query);

}

 

$results[$counter] = mysql_query($query);

 

if (ISDEBUG)

{

$err = mysql_error();

if ($err != "")

{

echo $query;

echo $err;

}

}

return $counter;

}

I had tried $_GET as well and it also returned nothing.  I get the feeling that it is not actually getting the data from the previous page though I do not know if this is a result of the connection string being incorrect or if it is a result of the submit button on the page before it being wrong.

 

when you click one of the Edit Record buttons, does the URL not look like:

EditCustomer.php?customer_id=123

This is the URL that button takes me to:  something/EditCustomer.php?customer_id=21249&Edit+Record=Edit+Record

good

 

as for your DB functions...they are a little weird. the function returns a counter. how do you access the result from the DB query? is there a function to fetch data or are you supposed to access $result directly?

I access $result directly.

 

ok...so try this out:

<?php
include 'common.php';
?>

<Title>Edit Customer</title>
<?php
dbConnect();
$c = dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);
if(!is_array($result[$c]) || !count($result[$c]))
  die("Customer not found");
$customer = $result[$c][0];
?>
<html>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?php echo $customer['first_name']; ?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
dbClose();
?>

Change this

!count($result[$c])

 

To be

count($result[$c]) < 1

 

EDIT:

And if that does not work, try running the same query, with joins etc, via phpMyAdmin and see what it pulls up. There is the off chance that the query is limiting itself.

oops...needs to be $results...not $result:

 

<?php
include 'common.php';
?>

<Title>Edit Customer</title>
<?php
dbConnect();
$c = dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);
if(!is_array($results[$c]) || !count($results[$c]))
  die("Customer not found");
$customer = $results[$c][0];
?>
<html>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?php echo $customer['first_name']; ?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
dbClose();
?>

i'm still wrong...try:

 

<?php
include 'common.php';
?>

<Title>Edit Customer</title>
<?php
dbConnect();
$c = dbQuery("SELECT * FROM customers c LEFT JOIN orders o ON c.customer_id=o.customer_id WHERE c.customer_id = %1", $_GET['customer_id']);
if(!is_array($results[$c]) || !count($results[$c]))
  die("Customer not found");
$customer = mysql_fetch_assoc($results[$c]);
?>
<html>
   <body>
      <table>
         <tr>
            <td><input type="text" style="width:148px" name="FirstName" value="<?php echo $customer['first_name']; ?>"/></td>
         </tr>
      </table>
   </body>
</html>
<?
dbClose();
?>

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.