Jump to content

Archived

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

buchman

Strange insert problem

Recommended Posts

basically i'm having a problem doing a compound search of some results

[code]
$newtablequery = mysql_query($newtable);

    //while ($row = mysql_query($titlequery)) {
    echo mysql_num_rows($titleresult);
    //$titlerow = mysql_fetch_row($titleresult);

    while($rs = mysql_fetch_array($titleresult))
    {
        echo $rs;
        $insertsearch = ("INSERT into search  values ('$rs[0]','$rs[1]','$rs[2]','$rs[3]','$rs[4]','$rs[5]','$rs[6]','$rs[7]','$rs[8]','$rs[9]','$rs[10]') ");
        $insertquery = mysql_query($insertsearch);
      
    }
[/code]
i'm trying to insert the results from a search into a new table, but it only inserts 3 records even though it says there are ten rows and it cycles 10 times through
the loop.
You have to bear with me, i've only just started with php this week :)

Share this post


Link to post
Share on other sites
there's a possibility that some types of data being read from one table can't be put directly into the other, possibly due to quotes, etc.

change this line:
[code]
$insertquery = mysql_query($insertsearch) or die(mysql_error());
[/code]
and see if you get an error

Share this post


Link to post
Share on other sites
Yes you were right

I get this now

[code]
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Reilly','0596000278','12','33.00','Programming Perl','programmin
[/code]

how to I work around this, I really don't have a clue

heres where I created the search table to store info, its exactly the same as the book table where I get the data from.

[code]
$newtable = ("create table search
(
bookid char(12),
dimensions char(30),
availability char(30),
booktype char(20),
publisher char(20),
isbn char(20),
itemsinstock int(3),
price float(5,2),
title char(50),
toc char(36),
picture char(36));");

[/code]

sample data
[code]
'A512', '9.0x7.2x1.8 inches', 'Ships same day', 'Programming', 'Wrox Press', '0764543849', 12, 30.00, 'Beginning VB.NET Programming', 'vbnet.htm', 'vbnet.jpg'

'A524', '9.2x7.0x1.8 inches', 'Ships same day', 'Programming', 'O' Reilly', '0596000278', 12, 33.00, 'Programming Perl', 'programmingperl.htm', 'programmingperl.jpg'

I just copied some of the rows using mysql query browser
[/code]

Share this post


Link to post
Share on other sites
Ok I tried to escape the strings, but now nothing but empty rows are inserted

[code]
$newid = mysql_escape_string($row[0]);
    $dimensions = mysql_escape_string($row[1]);
    $availability = mysql_escape_string($row[2]);
    $booktype = mysql_escape_string($row[3]);
    $publisher = mysql_escape_string($row[4]);
    $isbn = mysql_escape_string($row[5]);
    $itemsinstock = mysql_escape_string($row[6]);
    $price = mysql_escape_string($row[7]);
    $title = mysql_escape_string($row[8]);
    $toc = mysql_escape_string($row[9]);
    $picture = mysql_escape_string($row[10]);
        
        $insertsearch = "INSERT into search  values ('$newid','$dimensions','$availability','$booktype','$publisher','$isbn','$itemsinstock','$price','$title','$toc','$picture') ";
        //$insertsearch = ("INSERT into search  values ('$rs[0]','$rs[1]','$rs[2]','$rs[3]','$rs[4]','$rs[5]','$rs[6]','$rs[7]','$rs[8]','$rs[9]','$rs[10]') ");
        $insertquery = mysql_query($insertsearch) or die(mysql_error());
[/code]

Share this post


Link to post
Share on other sites
Can't seem to edit, existing posts. but it was the escaped characters being passed. Thanks for helping me fix it

Share this post


Link to post
Share on other sites

×

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.