Asked  9 Months ago    Answers:  5   Viewed   351 times

I have got this code so insert values into a table in MySQL through PHP. I have tried all the possible Insert syntax, it does not insert the data... this are the codes that i used.

$param = "xyzxyz";
$param1 = "sdfdfg";
$sql = "INSERT INTO trail (User_Name, Quiz_ID) VALUES ('".$param."','".$param1."')";
$result = $mysql->query($sql);
   echo "successful";
   echo mysql->error;
   echo "successful"
   echo mysql->error;

I even tried the following sql syntax

"INSERT INTO trail (User_Name, Quiz_ID) VALUES ('$param1','$param1')";

"INSERT INTO `trail` (`User_Name`, `Quiz_ID`) VALUES ('$param1','$param1')";

and i tried several other none of them inserts anything into the table. and this is the table in MySQL;


User_Name varchar(35)
Quiz_ID varchar(35)

It does not insert anything nor does it display any error. And I have the correct DB connection because i am able to Select from the table. Its just the insert that is tricky.

Any help would be much appreciated.




My tables were InnoDB tables and when i changed my tables to MyISAM the insert worked fine. Well i have never encountered this problem before. Well that did the trick for the time being.

If i want to use InnoDB engine for transactions? How can i get php to be able to insert values in InnoDB table? Any one got any suggestion? And i am using WAMP server and the MySQL is version 5.5.24. And i did change the InnoDB conf in my.ini but that did not seem to work either?

Wednesday, March 31, 2021
answered 9 Months ago

You've mixed procedural and object-oriented MySQLi styles. This has led to you trying to use the functions like mysqli_query($mysqli) instead of the member functions like $mysqli->query(). Your $mysqli is an object, not a resource handle.

And, you're not performing any error checking on your query. If you were, you'd see that you have mistakenly used single quotes to delimit table and field names, not backticks.

$sql = "INSERT INTO `nlcc_ver1`.`tUsers`
       (`userID`, `userName`, `userPassword`, `userHash`,
        `user_first_name`, `user_last_name`, `user_corps`,
        `is_admin`, `is_trg`, `is_sup`, `is_co`)
       VALUES (NULL, '" . $userName . "', '" . $hash . "', '" . $salt . "', '" .
               $f_name . "', '" . $l_name . "', '" . $corps . "', '" . $admin .
               "', '" . $trg . "', '" . $sup . "', '" . $co . "')";

$hostname_Database = "localhost";
$database_Database = "nlcc_ver1";
$username_Database = "root";
$password_Database = "";

$mysqli = new mysqli($hostname_Database, $username_Database, $password_Database, $database_Database); 
if (mysqli_connect_errno()) {
   printf("Connect failed: %sn", mysqli_connect_error());

$result = $mysqli->query($sql);
if (!$result) {
   printf("%sn", $mysqli->error);

echo "Query run. Inserted UserID " . $mysqli->insert_id . "<br />";

I strongly suggest using the manual as your reference. It's quite clear on how to use these functions when you're using either procedural or object-oriented style MySQLi.

Wednesday, March 31, 2021
answered 9 Months ago

yo need create the user "pma" in mysql or change this lines(user and password for mysql):

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

Linux: /etc/phpmyadmin/

Tuesday, July 13, 2021
answered 5 Months ago

The file is not required, and only needed for custom configurations

phpmyadmin will first refer to ./libraries/config.default.php to retrieve the default values.

If for some reason you need to modify the default values, and the ./ file doesn't exist, you will need to create one as per the Installation documentation.

You will also need to configure pmadb for some of phpmyadmin's special features such as bookmarks.

Monday, August 16, 2021
answered 4 Months ago

I think the problem may be in the way you've laid out the information to be inserted.

This should work:

$insert=("INSERT INTO phpbb_members (emailAddress, uid, valid, firstandlast, propic, memberName)
VALUES ('$me[email]', '$uid', '1', '$me[name]', '$propic', '$newuser')");
        mysql_query($insert) or die('Error, insert query failed');

Hope it helps!

EDIT: I'm pretty sure the information to be inserted has to be inside ' '.

Thursday, August 19, 2021
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :