MySQLi and INSERT to mysql
Posted: Fri Mar 07, 2008 11:41 am
Hi guys,
I'm new to php and mysql but have been trying to insert to my mysql database using insert with mysqli.
I seem to be able to do SELECT statements but I cant INSERT, the code seems to run but not insert and records.
Here's the code:
<?php
$mysqli = new mysqli('host', 'username', 'pssword', 'db');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $mysqli->prepare("INSERT INTO establishments (ename) VALUES (?)");
$stmt->bind_param('s', $ename);
$ename = 'hotel1';
/* execute prepared statement */
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
/* close statement and connection */
$stmt->close();
/* close connection */
$mysqli->close();
?>
Am I doing something obviously wrong?
Can anybody help!!?
Thanks in advance,
T.
I'm new to php and mysql but have been trying to insert to my mysql database using insert with mysqli.
I seem to be able to do SELECT statements but I cant INSERT, the code seems to run but not insert and records.
Here's the code:
<?php
$mysqli = new mysqli('host', 'username', 'pssword', 'db');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $mysqli->prepare("INSERT INTO establishments (ename) VALUES (?)");
$stmt->bind_param('s', $ename);
$ename = 'hotel1';
/* execute prepared statement */
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
/* close statement and connection */
$stmt->close();
/* close connection */
$mysqli->close();
?>
Am I doing something obviously wrong?
Can anybody help!!?
Thanks in advance,
T.