Jump to content
Larry Ullman's Book Forums

futumuch

Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by futumuch

  1. Hi all,
    i am trying to insert some data into a table via a php function as below
     

    function save_link($new_link)
     {
       echo 'new link = '.$new_link; #just to make sure the code gets to here
              if (mysqli_connect_errno())
                {
                echo "Failed to connect to MySQL: " . mysqli_connect_error();
                }
                else
                {
                echo 'success! were in!';
                }
     
    $query = "INSERT INTO college_values 
      (link_code, year_2011, year_2012, year_2013, year_2014) 
      VALUES 
      ('AAAB',0,0,0,0)";
     
    $retval = mysql_query($query, $dbc);
    if(! $retval )
    {
    die('Could not enter data: ' . mysql_error());
    }
          return $result;
     }

     
    but i get the following message -
    Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in....
     
    I have tried many different combinations of $query but the one above does work if I paste it into the query section of PHPMyAdmin.I can substitute the query for a SELECT and it works fine. I just cant see why the INSERT doest work.

    Many thanks.

  2. hi,

    I am try to learn PHP and MySQL with the help of Larry's excellent book. Most of the time, I find the book easy to follow and I can find the answer I need, however I have now hit a wall!

    I want to count the amount of rows in a table that meet a certain criteria and then use this number in a PHP while loop.

    My query is - 

     

    $SQL_count = SELECT COUNT(*) FROM college_notes WHERE link_code = 'CHES'

    and I used this

    $result_count = mysqli_query($dbc, $SQL_count);

     

    My problem is that the variable $result_count doesnt seem to be usable. If I use echo to dump it on the screen, i get this -

     

    Catchable fatal error: Object of class mysqli_result could not be converted to string in/home/www

    I have also tried using AS to get an alias and $result_count['alais'] but got a message stating that the variable wasnt an array.

     

    Thanks in advance for any help!

    Dave

×
×
  • Create New...