Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my insert not working in php?
    primarykey
    data
    text
    <p>I have an insert statement I am querying to the DB.</p> <pre><code>$notes_sql = 'INSERT into notes SET order_id = "'.$_GET['order_id'].'", date_added = "'.$date_added.'", note_message = "'.$_SESSION['note_message'].'"'; $notes_result = $conn-&gt;query($notes_sql) or die(mysqli_error($conn)); </code></pre> <p>I know the sql statement is correct, because when I try to echo it out and run that echo'd statement in phpMyadmin, it inserts it fine.</p> <p>When I try to run the insert statement, I get the following error:</p> <p><strong>INSERT command denied to user 'ideapale_amquery'@'localhost' for table 'notes'</strong></p> <p>Line 74 is the line line of code that queries the statement.</p> <p>I also know that I am correctly connecting to the DB through an included connection.php file, since I am using variables from that included file on the page I am working on.</p> <p>I'm guessing I am somehow not correctly connecting to the DB, but I am not sure what it is. I copied the code for this page from another page that works fine, so I don't understand why it is not working.</p> <p>Why is my insert not working in php?</p> <p>***** UPDATE *****</p> <p>This is my connection script:</p> <pre><code>function dbConnect($type) { if($type == 'query'){ $user = 'ideapale_amquery'; $pwd = 'xxxxxxxxxxx'; } else if($type == 'admin') { $user = 'ideapale_amadmin'; $pwd = 'xxxxxxxxxxxx'; } else { exit('Unrecognized connection type'); } $conn = new mysqli('localhost', $user, $pwd, 'ideapale_offorders') or die('Cannot open database'); return $conn; } </code></pre> <p>This is how I am connecting to the connection script from the page I am on:</p> <pre><code>$conn = dbConnect('admin'); </code></pre> <p>I am connecting to the DB using the admin privileges, so I don't understand why it thinks I want to use the 'amquery' username. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload