Jump to content

Only the first part of a string comes through


harryb

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.