SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem PHP and mysql

    Hi there

    being relatively new to this type of programming, I am having one or two problems:
    the two most important are:

    1. I keep getting a response of "Not valid argument" for my mysql query: mysql_fetch_array. The result is still ok but the error warning is annoying. What is the correct argument?

    2. Having problems viewing information just inserted into mysql table. I'm trying to use the argument "mysql_insert_id()". I don't seem to be able to get the right syntax so that I can get the id or to pass this id onto the next page (xxxxx.php?id=$id....... and so on.

    Can anyone help me, possible with a few lines of script that actually work.

    Thnx

    Fritz

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you post some of the script your having problems with? Then people will be able to point you in the right direction

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Member
    Join Date
    Jul 2001
    Location
    UK
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP and mySQL Problem

    Here's the code that I'm having trouble with:

    1. Re: mysql_insert_id()

    After inserting data, I want to review it by using the mysql_insert_id argument and need to put the id into the next header:
    <?php

    $sql = "INSERT INTO authors SET last_name='$last_name',first_name='$first_name'";


    $id_new = $mysql_insert_id;

    if (mysql_query($sql)) {


    echo("
    <TD><A HREF='viewauthor.php?id=$id_new'>VIEW</A></TD>
    ")
    >

    2. Re: mysql_fetch_array()

    After the following line is called, the correct info is retrieved but I get a warning: "invalid mysql argument":

    //if ($id) {

    // query the DB

    $sql = "SELECT * FROM authors WHERE id=$id";

    $result = mysql_query($sql);

    $myrow = mysql_fetch_array($result);
    .....

    ?>


  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $id_new = $mysql_insert_id;

    don't you need an argument for that?
    also, your treating it like a variable, but it's a function. take out the $ and add () at the end then try it.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try using this

    Code:
    $id_new = mysql_insert_id();

    This should work. Your syntax was incorrect.
    i dunno...

  6. #6
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea, thats what i said.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  7. #7
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Defender1
    yea, thats what i said.
    yea.. but i was more precise
    i dunno...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •