MySQL Insert Query Doesn't Work (PHP) -
i need in understanding why simple insert query doesn't work.
the code below:
<?php // db info define ( 'db_host', '' );`enter code here` define ( 'db_user', '' ); define ( 'db_password', '' ); define ( 'db_name', '' ); create_db_connection (); function create_db_connection() { global $con; $con = mysql_connect ( db_host, db_user, db_password ) or die ( "connection not established" ); $db = mysql_select_db ( db_name, $con ) or die ( "database not connected" ); } $sql= "insert 'tbl_bonaproval' (orderid,restid) values (20001,98765)"; if (mysqli_query ( $db, $sql )) { echo "successfully inserted " . mysqli_affected_rows ( $db ) . " row"; } else { echo "error occurred: " . mysqli_error ( $db ); } function close_mysql_connection() { global $con; mysql_close ( $con ); } $result = mysql_query ( "select * `tbl_bonaproval`" ); $row = mysql_fetch_array ( $result ); print_r ( $row ); // print array echo $row ['table field name']; // print field data // $sql=mysql_query('insert tbl_bonaproval (orderid, restid) values (24553, 01001);'); // echo $sql; mysql_close ( $conn ); class callback { } ?>
you should try mysqli instead of predecessor mysql. here's simplified code of yours:
<?php $conn=mysqli_connect("yourhost","yourusername","yourpassword","yourdatabase"); if(mysqli_connect_errno()){ echo "error".mysqli_connect_error(); } mysqli_query($conn,"insert tbl_bonaproval (orderid, restid) values ('20001','98765')"); $result = mysqli_query ($conn, "select * tbl_bonaproval"); while($row = mysqli_fetch_array ($result)){ echo $row['table field name']; /* print field data */ } ?>
Comments
Post a Comment