I have a form which takes a string from a database and posts it to another page problem is that post seems to be shortening the variable.

So if post should be "product name" it is shortened to "product" by post I think.

Any help would be great thanks.

Recommended Answers

All 5 Replies

Hi there,
Is "product name" the name of the input box & post variable or is that the value of the variable/text in the input box?

Here is the real code "product name" was just an example.
This is the part of the input form;

echo "<select name='type'>";
include("mysql_conn.php");
include("db_conn.php");

// Get a specific result from the "type" table
$result = mysql_query("SELECT * FROM type") or die(mysql_error());

while($row = mysql_fetch_array( $result )) {
$type = $row['type'];
echo  "<option value=$type>$type</option>";
}
echo "</select>";

Here is a some code from the processing form which adds user input to the database;

$prod_type = $_POST['type'];

$qry = "INSERT INTO products(prod_name, prod_desc, prod_skincond, prod_application, prod_benefits, prod_type, prod_price, prod_img, prod_size, prod_code) VALUES('$prod_name','$prod_desc','$prod_skincond','$prod_application','$prod_benefits','$prod_type','$prod_price','$img','$prod_size','$prod_code')";
$result = @mysql_query($qry);
echo "<select name='type'>";
include("mysql_conn.php");
include("db_conn.php");

// Get a specific result from the "type" table
$result = mysql_query("SELECT * FROM type") or die(mysql_error());

while($row = mysql_fetch_array( $result )) {
$type = $row['type'];
echo  "<option value=$type>$type</option>";
}
echo "</select>";

I think the problem might be here, try enclosing the value attribute for the select statement in quotes:

while($row = mysql_fetch_array( $result )) {
$type = $row['type'];
echo  "<option value=\"$type\">$type</option>";
}

Another thing you can try is, on the page that you post this form to, at the top:

echo "<pre>";
print_r($_POST);
echo "</pre>";
die();

Which will tell exactly what is coming through from your form.

All variables have a limit on the legth of values it can hold. If you are using Joomla or another CMS then often restrictions are placed and you can only post values using the methods designated in the API.

Thanks Menster Adding the quotes fixed the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.