Results 1 to 3 of 3

Thread: mysqli dropdown

  1. #1
    Join Date
    May 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default mysqli dropdown

    I'm attempting a mysqli dropdown to select and print one record from table and update one
    field, ("lastused" ($currdate))in that record. I get the following errors: Any help?
    Notice: Undefined index: lastused in C:\xampp\htdocs\home\emaildrop.php on line 109

    Notice: Undefined index: target in C:\xampp\htdocs\home\emaildrop.php on line 110
    target Total results: 0

    Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\xampp\htdocs\home\emaildrop.php on line 141
    target username password emailused lastused purpose saved
    could not retrieve data from database
    PHP Code:
    <?php
     $db 
    = new mysqli('localhost''root''cookie''homedb');
    if(
    $db->connect_errno 0)
        {die(
    'Unable to connect to database [' $db->connect_error ']');}

    $lastused $_POST['lastused']; // 108 ****************************
    $target $_POST['target']; // 109 *********************************

    $currdate date('Y-m-d');    
    $lastused $currdate;
    if(
    $target=="email"){$target=$username;}
    //echo "lastused $lastused";
    echo "target $target";
    $sql = <<<SQL
    SELECT * FROM `oocust` WHERE 'target' = '$target'
    SQL;
    if(!
    $result $db->query($sql))
        {die(
    'There was an error running the query [' $db->error ']');}
    while(
    $row $result->fetch_assoc()) 
        {echo 
    $row['username'] . '<br />';}
    echo 
    'Total results: ' $result->num_rows;

    $result->free(); 
    $db->escape_string('This is an unescape "string"');
    $db->close();
    ?>
    <center>
      <table cellspacing=2 cellpadding=0 border=1>
       <tr> 
        <th bgcolor="#ccffff">target</TH>      
        <th bgcolor="#ccffff">username</TH> 
        <th bgcolor="#ccffff">password</TH>
        <th bgcolor="#ccffff">emailused</TH>
        <th bgcolor="#ccffff">lastused</TH>
        <th bgcolor="#ccffff">purpose</TH>
        <th bgcolor="#ccffff">saved</TH>
        <?php
    while($data mysql_fetch_array($result)) // 139 ******************************* 
        
    {
    echo
    '<tr>'
    // printing table row
    echo '
    <td>'
    .$data['target'].'</td>
    <td>'
    .$data['username'].'</td>
    <td>'
    .$data['password'].'</td>
    <td>'
    .$data['emailused'].'</td>
    <td>'
    .$data['lastused'].'</td>
    <td>'
    .$data['purpose'].'</td>
    <td>'
    .$data['saved'].'</td>'
    // looping all data to be printed till last row in the table
    echo'</tr>'
    // closing table row
       
    }
    echo 
    '</table>';  //closing table tag
    mysql_query("UPDATE emailtbl SET lastused=$lastused"); 
    $result=mysql_query("select lastused from emailtbl") or die ("could not retrieve data from database");
    $data=mysql_fetch_assoc($result);
    echo 
    'Total rows updated: ' $db->affected_rows;
    echo 
    "lastused ".$data['lastused'];
    mysql_close();
       
    ?>
       </table></center></body></html>
    Last edited by james438; 06-10-2014 at 02:03 AM. Reason: tiny fix to coding format.

  2. #2
    Join Date
    May 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    nobody knows mysqli?

  3. #3
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    Well first off you're mixing mysql and mysqli in the script you posted. The undefined index will result from the $_POST not having those array items when the script is run.
    You never know everything, I learn everyday!

Similar Threads

  1. Resolved mysql and mysqli connect
    By Deadweight in forum MySQL and other databases
    Replies: 1
    Last Post: 05-11-2014, 04:39 PM
  2. MySQLi and the PHP5.4 breaking changes.
    By ApacheTech in forum PHP
    Replies: 1
    Last Post: 07-28-2012, 04:30 PM
  3. Change syntax from mysqli to mysql
    By newphpcoder in forum PHP
    Replies: 0
    Last Post: 10-27-2011, 08:34 AM
  4. Mysqli vs Mysql and CMS
    By Victro in forum MySQL and other databases
    Replies: 2
    Last Post: 06-16-2010, 01:14 PM
  5. Replies: 3
    Last Post: 04-16-2008, 04:41 PM

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
  •