Jump to content

PHP/Mqsql problem, data not being inserted!


samf_20

Recommended Posts

Hi,

I am creating an online form which should take information to from one page using a multiple-select box then display the selected fields in order confirmation page. This part of the code works fine, Then I press the submit (complete order) button and the information should then get stored into the MySQL database as a string. So if I selected jan,feb and apr it will store into MySQL like jan,feb,apr all in the same field.

 

I think the main problem is that the information that is stored in the confirmation page is not being registered with the final order complete page.

 

Here is the code:

 

FirstPage:

 

 

          <select name="ilm[]" size="7" multiple="multiple">
            <option value="January"> January </option>
            <option value="February"> February </option>
            <option value="April"> April </option>
            <option value="May-Buyers-Guide"> May Buyers Guide </option>
            <option value="July"> July </option>
            <option value="August"> August </option>
            <option value="October"> October </option>
          </select></center>    </td>

 

Just a normal Multiple-select table.

 

Second page:

 

 

     	 <?php
	$_SESSION['details'] =$_POST['ilm'];

	$info2=$_SESSION['details'];
	if ($info2){
//			$str=implode(",", $info2);
		$str='';
		foreach ($info2 as $t){
			$str.=$t.', ';
		}
		$str=trim ($str,', ');
		echo $str.'<br>';
	}
 ?>    

 

This is the code I use to display the select information from the table as a string.

 

Third Page:

 

This is the code that I am using to try and put the string into mysql

 

            $ilm = $_SESSION['details'];  
    foreach($ilm as $value)  
    {  
        $str = implode(',' , $ilm);  
        echo $str;  
    }  
    foreach($ilm as $value)  
    {  
        $insert="INSERT INTO dealerguide (ilmissue) VALUES ('$str')";  
} 
mysql_query($insert);

 

 

I have tried echo'ing the string and it does not display the it probably meaning there is something else wrong which I cannot find. It seems not to find the on the seconds page therefore not inserting it into the MysQl database.

 

Any help will be appreciated.

 

Thanks

 

PS: I have got SESSION_Start on all the pages at the very top. Also the code does not display teh forms thats because I would be sending you about 700lines of code that is unnecessary.

 

CODE

<form name="form1" method="post" action="./onlineFormPage2.php">

 

all of the form headers look like this and are pointing to the correct php page.

This is incorrect. You do not implode in a loop

            
$ilm = $_SESSION['details'];  
    foreach($ilm as $value)  
    {  
        $str = implode(',' , $ilm);  
        echo $str;  
    }  
    foreach($ilm as $value)  
    {  
        $insert="INSERT INTO dealerguide (ilmissue) VALUES ('$str')";  
} 
mysql_query($insert);

 

Should be

$insert="INSERT INTO dealerguide (ilmissue) VALUES ('".implode(",",$_SESSION['details'])."')";
mysql_query($insert);

Thanks for the reply, when I do this it does help. The MySql field that the data is getting inserted into no longer says 'null' it is just blank now. Also i get this error message:

 

Warning: implode() [function.implode]: Invalid arguments passed in C:\Web_Services\sugar\sams_tests\includes\sql.php on line 40

 

It just sits at the top but doesnt stop the statement functioning? is this saying it cannot read implode or I got to create a function for it?

Bump, still on-going problems. It did just make the mysql field blank and not display null but now mysql doesnt get anything, not even a null on a new line.

 

On all pages I got session_start(); and on the first page I have:

 

$details=$_SESSION['details'];
$_SESSION['details']=null;

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.