harryb Posted November 9, 2010 Share Posted November 9, 2010 I'm using PHP to get a list of names from a mysql database, which then produces a drop down list for the user to select an option and then progress to the next page where the selection is displayed with other stuff. My problem is that my drop down list works fine, but when the user goes to the next page only the first part of the string is displayed, ie if the string is Fred Bloggs, only Fred is shown. I can get it to work by adding ' ' around the string name in the option section, but this shows 'Fred Bloggs' in the drop down list which isn't very pretty. I haven't got the actual code to hand at the moment, but any ideas on where I'm going wrong? Cheers Quote Link to comment https://forums.phpfreaks.com/topic/218192-only-the-first-part-of-a-string-comes-through/ Share on other sites More sharing options...
Adam Posted November 9, 2010 Share Posted November 9, 2010 Could be a million things. Would be much quicker if (when you have it) you provided the code. Quote Link to comment https://forums.phpfreaks.com/topic/218192-only-the-first-part-of-a-string-comes-through/#findComment-1132186 Share on other sites More sharing options...
monkeytooth Posted November 9, 2010 Share Posted November 9, 2010 Initial loop for creating the Dropdown, and the handlers from one page to the next and how you send the names over to the next page would be the most helpful. When you get the code to show so we can help you with it. What I might do in a senerio like this, though i dont know the full on data your pushing around, how much of it your pushing around and so on. But is, I would store the array of names from one page to the next in a session variable. I might recreate the array in a different manor, maybe implode() the data into a csv and store it in a session moving on to the next, page or something. Just an idea, not thee most secure of ideas depending on what the data is, and how its being used. But still food for thought none the less. Quote Link to comment https://forums.phpfreaks.com/topic/218192-only-the-first-part-of-a-string-comes-through/#findComment-1132192 Share on other sites More sharing options...
harryb Posted November 9, 2010 Author Share Posted November 9, 2010 Here's the code I'm using: This is the part that gets the value from the database <?php include '../connect.php'; //Connects to the database with user details etc echo"<FORM ACTION='get_sheet1.php' METHOD='POST'>"; // Performing SQL query $query = 'SELECT Distinct eng_name FROM time_sheet'; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); print "<p>Select an Engineer from the list:\n"; print "<select name=\'eng_name\'>\n"; while ($row = mysql_fetch_assoc($result)){ $eng_name = $row['eng_name']; print "<option value=$eng_name>$eng_name\n"; //If I change this line to print "<option value='$eng_name'>'$eng_name'\n"; it works } print "</select>\n"; print "</p>\n"; echo"<INPUT TYPE='SUBMIT' VALUE='Next page'> </form>"; // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); ?> This is in get_sheet1.php $eng_name = htmlspecialchars($_POST['eng_name']); echo "Engineer ", $eng_name; Quote Link to comment https://forums.phpfreaks.com/topic/218192-only-the-first-part-of-a-string-comes-through/#findComment-1132292 Share on other sites More sharing options...
jdavidbakr Posted November 9, 2010 Share Posted November 9, 2010 <option value=$eng_name> will fail if there are spaces in $eng_name - you want to enclose this is quotes for sure. Quote Link to comment https://forums.phpfreaks.com/topic/218192-only-the-first-part-of-a-string-comes-through/#findComment-1132415 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.