Welcome to Dream.In.Code
Become a PHP Expert!

Join 150,170 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,290 people online right now. Registration is fast and FREE... Join Now!




Data not inserting into Mysql

 
Reply to this topicStart new topic

Data not inserting into Mysql

samf
29 Aug, 2008 - 02:15 AM
Post #1

D.I.C Head
**

Joined: 11 Aug, 2008
Posts: 78


My Contributions
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:

CODE
          <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:

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

        $infoilm=$_SESSION['details'];
        if ($infoilm){
//            $str=implode(",", $info2);
            $ilmstr='';
            foreach ($infoilm as $ilmt){
                $ilmstr.=$ilmt.', ';
            }
            $ilmstr=trim ($ilmstr,', ');
            echo  $ilmstr.'<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

CODE
        $ilm = $_SESSION['info'];
    foreach($ilm as $val)'<br />';
    $ilmstring = implode(',' , $ilm);
    echo $ilmstring.'<br />';    
    foreach($ilm as $val)    
    $insert="INSERT INTO dealerguide (ilmissue) VALUES ('$ilmstring')";    
    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.

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.


User is online!Profile CardPM
+Quote Post

JackOfAllTrades
RE: Data Not Inserting Into Mysql
29 Aug, 2008 - 04:33 AM
Post #2

Cantankerous Old Fart
Group Icon

Joined: 23 Aug, 2008
Posts: 862



Thanked: 89 times
Dream Kudos: 50
My Contributions
Your code as posted (that's going into MySQL) is syntactically incorrect and would fail at compilation, so I've tried to guess a bit what's happening here, and therefore this could be wrong.

Can you (maybe) see the problem now?
php
$ilm = $_SESSION['info'];
foreach($ilm as $val)
{
$ilmstring = implode(',' , $ilm);
echo $ilmstring;
}
foreach($ilm as $val)
{
$insert="INSERT INTO dealerguide (ilmissue) VALUES ('$ilmstring')";
}

User is offlineProfile CardPM
+Quote Post

samf
RE: Data Not Inserting Into Mysql
29 Aug, 2008 - 07:34 AM
Post #3

D.I.C Head
**

Joined: 11 Aug, 2008
Posts: 78


My Contributions
Thanks,

I see what ive done wrong in that code but still the information doesnt seem to be registering with the session and entering information the string in mysql.

Anyone else able to shed some light on this?
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 03:09AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month