danjoe_15 Posted January 23, 2009 Share Posted January 23, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/ Share on other sites More sharing options...
gaza165 Posted January 23, 2009 Share Posted January 23, 2009 Not quite sure what you are doing here, are you planning to bring the customer details back from the database and put them in tables. and you are bringing back the record based on the customer id passed from another form? Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744258 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 Change all instances of <?echo($data['customer_id']);?> To be <?php echo ($data['customer_id']); ?> Spacing will not kill ya, and use <?php over <? cause the short tags can be turned off. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744260 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744261 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 I have tried the first 2 sugguestions and they did not fix the issue. first_name is coming from a database yes. The customers table. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744266 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744269 Share on other sites More sharing options...
gaza165 Posted January 23, 2009 Share Posted January 23, 2009 <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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744270 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 <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... Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744277 Share on other sites More sharing options...
gaza165 Posted January 23, 2009 Share Posted January 23, 2009 <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 Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744281 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 Yes that textbox does contain the correct customer_id. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744284 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744285 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744292 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744295 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 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; } Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744298 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744306 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 This is the URL that button takes me to: something/EditCustomer.php?customer_id=21249&Edit+Record=Edit+Record Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744315 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744320 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 I access $result directly. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744324 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 print_r($_GET) prints out: Array ( [customer_id] => 21249 [Edit_Record] => Edit Record ) Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744349 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744365 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 It returned customer not found. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744371 Share on other sites More sharing options...
danjoe_15 Posted January 23, 2009 Author Share Posted January 23, 2009 I however just checked my customer database and there is a record with that customer_id Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744377 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744378 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744380 Share on other sites More sharing options...
rhodesa Posted January 23, 2009 Share Posted January 23, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/142109-problems-with-get-method/#findComment-744382 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.