[Gloucs] mysql insert query
Glyn Davies
glynd at walmore.com
Sun Nov 20 22:37:38 UTC 2011
All, found this in my Gmail drafts. Not sure why I didn't send it
straight away. Anyway, php-mcrypt problem is fixed too.
Hi All,
Thanks Bob for your reply and to the other one I received directly.
Anyhoo, I have managed to solve it. It was a problem in my php and
some incorrect SQL syntax. The insert now works as I thought it
should.
Seemed to be one of those problems that 'went away' after I had left
it alone for a while. Well, I worked through my errors pretty quickly
tonight.
Oddly, Ubuntu had decided yesterday to do a partial dist upgrade and
that gnaggered my php (well, the php-mcrypt part of it).
On 9 November 2011 14:49, Bob Wilkinson <rwilkinson at messagelabs.com> wrote:
> On Sun, Nov 06, 2011 at 10:23:37PM +0000, Glyn Davies wrote:
>> 'lo
>>
>> I have a noddy mysql query which I'm sure someone can help me with. Am
>> a complete novice with mysql and SQL in general.
>>
>> Assume you have two tables. Hopefully I have described this okay.
>>
>> Authors
>> id - auto_num, primary key
>> Name - Author's name
>>
>> and
>>
>> Books
>> id - auto_num, primary key
>> Title - Book title
>> Author - Author.id, foreign key
>>
>> Say you want to insert a book into the db.
>>
>> Add the Author, get the id for that Author's entry, then add the book
>> with the Author value being that previosly learnt.
>>
>> First insert is easy as is getting the id.
>>
>> But I'm failing to insert into the Books table due to foreign key
>> restraints. Can I insert? Should it be an update?
>
> Hi Glyn
>
> I notice no one has replied (that I have seen). However, I think
> that you do want an insert - something like
>
> insert into Books values ("Janet and John learn C", 123) where
>
> 123 is the ID of authors "Enid Blyton and Dennis Ritchie"
>
> If you had an entry for "Janet and John learn C" and you get the
> second edition which had an additional author, then you want to use
> an update command if you want to replace the author id.
>
> BTW - what error message did you see regarding foreign key
> restraints?
>
> Bob
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________
>
> _______________________________________________
> gloucs mailing list
> gloucs at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/gloucs
>
--
Best Regards
Glyn Davies
More information about the gloucs
mailing list