Jump to content


Strange insert problem

  • Please log in to reply
4 replies to this topic

#1 buchman

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 March 2006 - 10:48 AM

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

$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);
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 :)

#2 redbullmarky

  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 30 March 2006 - 12:01 PM

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:
$insertquery = mysql_query($insertsearch) or die(mysql_error());
and see if you get an error
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 buchman

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 March 2006 - 12:07 PM

Yes you were right

I get this now

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

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.

$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));");

sample data
'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

#4 buchman

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 March 2006 - 12:28 PM

Ok I tried to escape the strings, but now nothing but empty rows are inserted

$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());

#5 buchman

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 March 2006 - 12:45 PM

Can't seem to edit, existing posts. but it was the escaped characters being passed. Thanks for helping me fix it

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users