Jump to content

Variable doesn't pass data into database


ipPHPadmin

Recommended Posts

Hello all,

 

I can't get the data store in the $ART_ID variable to pass into the database.  The original $Artisan variable is set up like this: 1. Artisan Name.  So the explode is taking just the number. If I put an echo after the explode and the $ART_ID variable it outputs the correct information but it doesn't store in the database as that data.  The query is in correct order too.

Thanks in advance. 

 

 

 

$CType_Type = $_REQUEST["CTYPE_Type"];

$Artisan = $_REQUEST['Artisan'];

$Quantity = $_POST['Quantity'];

$HAnswer1 = $_POST["HAnswer1"];

$HAnswer2 = $_POST["HAnswer2"];

$HAnswer3 = $_POST["HAnswer3"];

$HAnswer4 = $_POST["HAnswer4"];

 

$break = explode(".", $Artisan);

$ART_ID = $break[0];

 

if(!$Quantity)

{

die('Quantity field is empty. Please enter the quantity of handicrafts made.');

}

else

{

 

$ctypeQuery = mysql_query("SELECT CTYPE_ID FROM CraftType WHERE CTYPE_Type = '".$CType_Type."'");

 

while($row = mysql_fetch_array($ctypeQuery))

{

$CTYPE_ID = $row["CTYPE_ID"];

 

$sql = ("INSERT INTO Handicraft VALUES (`HANDI_ID`, '".$Quantity."', 'NULL', '".$CTYPE_ID."', '".$ART_ID."', 'NULL', '1')");

 

if(!mysql_query($sql))

{

die('Error inserting Handicraft Type into table: ' . mysql_error());

}

else

                { -----data in this section doesn't affect the rest of the code---- }

      }

}

Link to comment
https://forums.phpfreaks.com/topic/220103-variable-doesnt-pass-data-into-database/
Share on other sites

$sql = ("INSERT INTO Handicraft VALUES (`HANDI_ID`, '".$Quantity."', 'NULL', '".$CTYPE_ID."', '".$ART_ID."', 'NULL', '1')");

 

try changing it to

 

$sql = "INSERT INTO Handicraft VALUES (`HANDI_ID`, '$Quantity', NULL, '$CTYPE_ID', '$ART_ID', NULL, 1)";

 

OR

keeping it simple omit null values but be sure to include the column names when u do so

like

 

insert into (col_name1,col_name2,col_name4,col_name6) values ('blah','blah','blah','blah')

Alright, first off, thanks for the timely responses devilinc.  As for your questions, I am trying to insert just the "1" part and the data type of the database field is correct.  I tried what you said in your most recent post and it worked! Do you have any idea why removing the " and . would make it work correctly?

 

Thanks again for the help.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.