954,598 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem with $_post

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.

bjg5858
Newbie Poster
10 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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?

Menster
Junior Poster
175 posts since Jun 2009
Reputation Points: 49
Solved Threads: 22
 

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);
bjg5858
Newbie Poster
10 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 
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.

Menster
Junior Poster
175 posts since Jun 2009
Reputation Points: 49
Solved Threads: 22
 

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.

kronikmedia
Junior Poster in Training
65 posts since May 2008
Reputation Points: 10
Solved Threads: 1
 

Thanks Menster Adding the quotes fixed the problem.

bjg5858
Newbie Poster
10 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You