drew4663 Posted November 29, 2012 Share Posted November 29, 2012 I have a textbox that you can enter a provider name and it searches for the name and displays the results. The code I use is.... mysql_connect ("mydomain", "username","password") or die (mysql_error()); mysql_select_db ("dbname"); $term = $_POST['term']; $sql = mysql_query("select * from providers where provider like '%$term%'"); $ID = $_GET['providerID']; while ($row = mysql_fetch_array($sql)){ echo '<br/> ProviderID: '.$row['providerID']; echo '<br/> Provider: '.$row['provider']; echo '<br/> Service: '.$row['service']; echo '<br/> Phone: '.$row['phone']; echo '<br/> Tier: '.$row['tier']; echo '<a href="update.php?providerID=<?php echo $ID; ?>">Update</a>'; This is what it will give me on the page. ProviderID: 1 Provider: Comcast Service: Cable Phone: 866-511-6489 Tier: National Business Tech Support Update <----- link When I click update the URL says..... http://wwww.mydomain...php?providerID=<?php echo $ID; ?> here is the code for the update.php file <?php $ID=$_GET['providerID']; mysql_connect ("mydomain", "username","password") or die (mysql_error()); mysql_select_db ("dbname"); $sql = "select * from `providers` where ID = $ID"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)){ $providerID = $row['providerID']; $provider = $row['provider']; $service = $row['service']; $phone = $row['phone']; $tier = $row['tier']; //we will echo these into the proper fields } mysql_free_result($query); ?> <html> <head> <title>Edit User Info</title> </head> <body> <form action="updateinfo.php" method="post"> <p>provider id:<br/> <input type="text" value="<?php echo $providerID;?>" name="providerID" disabled/> <br/> Provider:<br/> <input type="text" value="<?php echo $provider;?>" name="provider"/> <br/> Service:<br/> <input type="text" value="<?php echo $service;?>" name="service"/> <br/> Phone:<br/> <input type="text" value="<?php echo $phone;?>" name="phone"/> <br> Tier:<br/> <input type="text" value="<?php echo $tier;?>" name="tier"/> </br> <br> <br> <input type="submit" value="submit changes"/> </p> </form> </body> </html> All I am trying to do is when I create a search to be able to click on update and it allow me to update that particular record via the ID. Any clues or pointers? Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/ Share on other sites More sharing options...
MDCode Posted November 29, 2012 Share Posted November 29, 2012 You are already using php to echo so using php inside the echo will not work. change the apostrope in that echo to a quotation: " because variables will not be parsed single quoted. Remove the php tags and it will work Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396087 Share on other sites More sharing options...
drew4663 Posted November 29, 2012 Author Share Posted November 29, 2012 Thank you for your assistance. I tried.... echo "<a href='update.php?providerID=$ID'>Update</a>"; and it resulted in http://mydomain.com/update.php?providerID= I am also getting these errors..... Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /xxx/xxxx/x/xxxxxx/xxxx/xxxxx/update.php on line 10 Warning: mysql_free_result() expects parameter 1 to be resource, boolean given in /xxx/xxxx/x/xxxxxx/xxxx/xxxxx/update.php on line 21 Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396096 Share on other sites More sharing options...
drew4663 Posted November 29, 2012 Author Share Posted November 29, 2012 (edited) FYI - When I manually put in a number here... $sql = "select * from `providers` where ID = 3"; It works great. So, I am guessing that I am having an issue with maybe the way the records are pulled in from the search. This is my html file for my search..... search.html <html> <head> <title>Search the Database</title> <link href="search_providers.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <form action="search.php" method="post"> <div id="providername"> <p>Search: <input type="text" name="term" /> </p> </div> <div id="providersubmit"> <p> <input type="submit" name="submit" value="Submit" /></p></div> </form> </div> </body> </html> Here is the php file for the result of the search. search.php mysql_connect ("mydomain", "username","password") or die (mysql_error()); mysql_select_db ("dbname"); $term = $_POST['term']; $sql = mysql_query("select * from providers where provider like '%$term%'"); $ID = $_GET['providerID']; while ($row = mysql_fetch_array($sql)){ echo '<br/> ProviderID: '.$row['providerID']; echo '<br/> Provider: '.$row['provider']; echo '<br/> Service: '.$row['service']; echo '<br/> Phone: '.$row['phone']; echo '<br/> Tier: '.$row['tier']; echo "<a href='update.php?providerID=$ID'>Update</a>"; So here is what the search will get me. Sometimes it will pull one record or ten depends on what you enter into the search, but I am wanting whatever records are pulled to have that update link reference that particular id and post it in the url and load it in the html form. I'm not sure if I am making myself clear or not so bare with me. Example: ProviderID: 7 Provider: AT&T - Ameritech, SW Bell, SBC, Bell South Service: DSL, T1 Phone: 888-434-6186 Tier: AT&T Advanced Technical Support Update <----link should read when mouse-hover "http://www.mydomain.com/update.php(and then the ID # 7) ProviderID: 8 Provider: AT&T - SBC Global Service: DSL Phone: 1-877-722-3755 Tier: Tier 1 - Tech Support Update <----link should read when mouse-hover "http://www.mydomain.com/update.php(and then the ID # ProviderID: 9 Provider: AT&T Bell South Service: DSL Phone: 888-321-2375 Tier: Tier 1 Update <----link should read when mouse-hover "http://www.mydomain.com/update.php(and then the ID # 9) ProviderID: 10 Provider: AT&T Service: T1 Phone: 888-613-6330 opt 2, 1, 1, 1 Tier: Tier 1 Update <----link should read when mouse-hover "http://www.mydomain.com/update.php(and then the ID # 10) After I click the update link I want the html form to load that ID and other info so that it can be edited. Edited November 29, 2012 by drew4663 Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396099 Share on other sites More sharing options...
MDCode Posted November 29, 2012 Share Posted November 29, 2012 You are querying with $_GET['providerID']. Is provider ID already in the url when you are querying? if not, that is where your error is coming from Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396145 Share on other sites More sharing options...
drew4663 Posted November 29, 2012 Author Share Posted November 29, 2012 (edited) Ok, so I am now able to get the ID into the URL. Any ideas how to get it from the URL to the textbox? URL looks like.... http://mydomain.com/update.php?=1 Edited November 29, 2012 by drew4663 Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396194 Share on other sites More sharing options...
MDCode Posted November 29, 2012 Share Posted November 29, 2012 (edited) I assume it is actually http://domain.com/up...hp?providerID=1 <input type="text" value="<?php echo htmlspecialchars($_GET['providerID']); ?>"> Edited November 29, 2012 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396196 Share on other sites More sharing options...
drew4663 Posted November 29, 2012 Author Share Posted November 29, 2012 (edited) Yes. That is correct. This echo "<br/><a href='update.php?providerID=$row[providerID]'>Update</a>"; Produces http://mydomain.com/update.php?providerID=1 Now I have the update.php code of...... <?php mysql_connect ("localhost", "username","password") or die (mysql_error()); mysql_select_db ("dbname"); $sql = "select * from `providers` where providerID = $providerID"; $query = mysql_query($sql); while ($row = mysql_fetch_array($query)){ $providerID = $row['providerID']; $provider = $row['provider']; $service = $row['service']; $phone = $row['phone']; $tier = $row['tier']; //we will echo these into the proper fields } mysql_free_result($query); ?> <html> <head> <title>Edit User Info</title> </head> <body> <form action="updateinfo.php" method="post"> <p>provider id:<br/> <input type="text" value="<?php echo htmlentities($_GET['providerID'],ENT_QUOTES); ?>" name="providerID" disabled/> <br/> Provider:<br/> <input type="text" value="<?php echo $provider;?>" name="provider"/> <br/> Service:<br/> <input type="text" value="<?php echo $service;?>" name="service"/> <br/> Phone:<br/> <input type="text" value="<?php echo $phone;?>" name="phone"/> <br> Tier:<br/> <input type="text" value="<?php echo $tier;?>" name="tier"/> </br> <br> <br> <input type="submit" value="submit changes"/> </p> </form> </body> </html> Doing it this way does put the "providerID" in the correct field but none of the other fields populate and I still get the boolean errors because of this line not being correct. $sql = "select * from `providers` where providerID = $providerID"; Any suggestions of what I should be putting there? Should I remove the echo htmlentities($_GET['providerID'],ENT_QUOTES); and place it after WHERE? Edited November 29, 2012 by drew4663 Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396216 Share on other sites More sharing options...
drew4663 Posted November 29, 2012 Author Share Posted November 29, 2012 I changed this line and it is now not giving any errors but it is only pulling the last record. $sql = "select providerID, provider, service, phone, tier from providers where providerID"; Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396229 Share on other sites More sharing options...
drew4663 Posted November 29, 2012 Author Share Posted November 29, 2012 I finally got it to work......thanks everyone for pointing me in the correct direction. $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; $pathFragments = explode('=', $url); $end = end($pathFragments); $sql = mysql_query("select * from providers where providerID like $end"); while ($row = mysql_fetch_array($sql)){ $providerID = $row['providerID']; $provider = $row['provider']; $service = $row['service']; $phone = $row['phone']; $tier = $row['tier']; Quote Link to comment https://forums.phpfreaks.com/topic/271327-using-id-inside-an-echo-for-a-url/#findComment-1396266 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.