Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retrieving form data error

    Hello

    I've set up this table of customers details and I'm trying to retrieve particular
    customer details with the following code.

    I keep getting the following error messsage and I'm not sure what it means?

    Warning: 0 is not a MySQL result index in <file name...> on line 7.

    If anywone could give me some advice on what I should, I'd be very gratefull!

    Thanks!

    Michael

    <?php
    $customer_no = $_POST[$customer_no];
    $mysql_link = mysql_connect ("unix.lsbu.ac.uk", "paleckaa", "butteph9");
    $testresult = mysql_select_db ("paleckaa", $mysql_link);
    $query="SELECT * FROM customers WHERE customer_no=$customer_no";
    $query_result = mysql_query ($query, $mysql_link);
    if ( mysql_num_rows ($query_result)>0) {
    print "<table border=\"1\" width=\"100%\">";
    while ($row = mysql_fetch_row ($query_result)) {
    print "<td width=\"10%\">$row[customer_no]</td>";
    print "<td width=\"30%\">$row[first_name]</td>";
    print "<td width=\"30%\">$row[last_name]</td>";
    print "<td width=\"30%\">$row[email]</td>";
    print "</tr>";
    }
    print "</table>";
    }
    ?>

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    <?php
    mysql_connect
    ('unix.lsbu.ac.uk''paleckaa''butteph9') or exit(mysql_error());
    mysql_select_db ('paleckaa') or exit(mysql_error());
    $result mysql_query("SELECT * FROM customers WHERE customer_no = '" $_POST['customer_no'] . "'") or exit(mysql_error());
    if (
    mysql_num_rows($result))
    {
        echo 
    '<table border="1" width="100%">';
        while (
    $row mysql_fetch_assoc($result))
        {
            echo 
    '
            <td width="10%">' 
    $row['customer_no'] . '</td>
            <td width="30%">' 
    $row['first_name'] . '</td>
            <td width="30%">' 
    $row['last_name'] . '</td>
            <td width="30%">' 
    $row['email'] . '</td>
            </tr>
            '
    ;
        }
        echo 
    '</table>';
    }
    else
    {
        echo 
    'no rows matching ' $_POST['customer_no'];
    }
    ?>

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    Thank you for your fast reply! I've tried your script and it's telling me "no rows matching"? I've jst checked my database and the primary keys are customer_no so I'm very confused

    Any advice would be much appreciated!

    Thank you

    Michael

  • #4
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    Quote Originally Posted by apalecka View Post
    I've tried your script and it's telling me "no rows matching"? I've jst checked my database and the primary keys are customer_no so I'm very confused
    ...then you are passing a customer # that is not in the table

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But now I'm even more confused as every number I try from the table returns the no rows matching error, even though I've checked them...

  • #6
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    echo the query to the browser before running to make sure your POST vars are being passed as you expect them to be

  • #7
    New Coder
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry, i'm very new to this I don't know what that means
    Thanks
    michael

  • #8
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    $query "SELECT * FROM your_table");
    //$result = mysql_query($query) or die...

    echo $query;
    //outputs
    SELECT FROM your_table 
    So if you have variables in your query, you can verify that they are truly adding there values into the query. IF not you need to find out why

  • #9
    New Coder
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok! Thx! But now if i put 2 into my form it returns '2' and 'no rows matching'
    but there is a row for customer_no 2 in the database ... so why doesn't it returns whats in that row?

    Thank a lot for ur patient for beginners!!!
    Michael
    Last edited by apalecka; 04-02-2007 at 10:09 PM.

  • #10
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Do what iLLin says, and copy the SQL into a tool that directly connects to your database (phpmyadmin, MySQL Query Browser, etc.) and see what it does.

    Then post the query here so we can see it.

    EDIT: Also, I'd strip out the username/password from your post.
    Last edited by aedrin; 04-02-2007 at 10:47 PM.

  • #11
    New Coder
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually i tried that one and its working Thank you!



    <?php
    $mysql_link = mysql_connect ("xxx", "xxx", "xxx");
    $testresult = mysql_select_db ("xxx", $mysql_link);
    $query="SELECT * FROM customers WHERE customer_no=$_POST[customer_no]";
    $query_result = mysql_query ($query, $mysql_link);
    if ( mysql_num_rows ($query_result)>0) {
    print"<table border=\"1\" width=\"100%\">";
    while ($row = mysql_fetch_array ($query_result)) {
    print "<td width=\"10%\">$row[customer_no]</td>";
    print "<td width=\"30%\">$row[firstname]</td>";
    print "<td width=\"30%\">$row[lastname]</td>";
    print "<td width=\"30%\">$row[email]</td>";
    print "</tr>";
    }
    print "</table>";
    echo $query;
    }
    ?>

  • #12
    New Coder
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    supplied argument is not a valid MySQL result resource in

    Hi so i've got that thing but how do I make validation of email( no duplikates) i tried that but its not working error says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... on line 10

    I cannot find what the problem is. Any help would be much appreciated

    Micheal

    <?php
    $mysql_link = mysql_connect ("xxx", "xxx", "xxx")
    or die ('Unable to connect!');
    $testresult = mysql_select_db ("xxx", $mysql_link)
    or die ('Unable to connect database!');

    $query="SELECT email FROM customers where email=$_POST[email]";
    $query_result = mysql_query ($query, $mysql_link);

    if ( mysql_num_rows ($query_result)>0) {
    echo("This email is already registered.");
    echo $query;
    }

    else {

    $f_n = $_POST[f_n]; $l_n = $_POST[l_n]; $email = $_POST[email]; $password = $_POST[password];
    $query="INSERT INTO customers (firstname, lastname, email, password)
    VALUES ('$f_n', '$l_n', '$email', '$password')";
    $result = mysql_query($query, $mysql_link);
    echo ("$f_n Thank you for registering! Please remember your login details:<br><br>");
    echo ("First name: $f_n <br>");
    echo ("Last name: $l_n <br>");
    echo ("Email: $email <br>");
    echo ("Password: $password <br><br>");
    echo ("Now try to LOG IN - click ");
    echo ("<a href=http://....>here</a>");
    }
    ?>

  • #13
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts

  • #14
    New Coder
    Join Date
    Apr 2007
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    supplied argument is not a valid MySQL result resource in

    Oh ok! Sorry right! So once again:

    --------------------------------------------------------------------------

    Hi so i've got that thing but how do I make validation of email( no duplikates) i tried that but its not working error says: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ... on line 10

    I cannot find what the problem is. Any help would be much appreciated

    Micheal

    PHP Code:
    <?php 
    $mysql_link 
    mysql_connect ("xxx""xxx""xxx")
    or die (
    'Unable to connect!');
    $testresult mysql_select_db ("xxx"$mysql_link)
    or die (
    'Unable to connect database!');

    $query="SELECT email FROM customers where email=$_POST[email]";
    $query_result mysql_query ($query$mysql_link);

    if ( 
    mysql_num_rows ($query_result)>0) {
    echo(
    "This email is already registered.");
    echo 
    $query;
    }

    else {

    $f_n $_POST[f_n]; $l_n $_POST[l_n]; $email $_POST[email]; $password $_POST[password]; 
    $query="INSERT INTO customers (firstname, lastname, email, password)
    VALUES ('$f_n', '$l_n', '$email', '$password')"
    ;
    $result mysql_query($query$mysql_link);
    echo (
    "$f_n Thank you for registering! Please remember your login details:<br><br>");
    echo (
    "First name: $f_n <br>");
    echo (
    "Last name: $l_n <br>");
    echo (
    "Email: $email <br>");
    echo (
    "Password: $password <br><br>");
    echo (
    "Now try to LOG IN - click ");
    echo (
    "<a href=http://....>here</a>");
    }
    ?>


  •  

    Posting Permissions

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