Posts

Showing posts with the label mysqli

Sql Triggers-Implementation Issue

Sql Triggers-Implementation Issue Hi guys i am making 2 tables for implementing triggers-- create table emp(id int primary key identity(1,1), name char(40), salary varchar(50), gender char(40), departmentid int); insert into emp(name,salary,gender,departmentid) values ('jimmi',4800,'Male',4); create table emp_audit ( id int primary key identity(1,1), audit varchar(60) ); alter trigger trigger_em_update on emp for update as begin Declare @Id int Declare @oldname char(40),@newname char(40) Declare @oldsal int,@newsal int Declare @oldgen char(40),@newgen char(40) Declare @olddeptid int,@newdeptid int Declare @auditstring nvarchar(max) --select * from deleted; select * into #temptable from inserted; while(Exists(select id from #temptable)) --boolean condition if there are rows are not Begin set @auditstring ='' --if there are many rows we still select the first one select Top 1 @Id =id,@newname=name,@newgen=gender,@newsal=salary,@newdeptid=departmentid ...

PHP query using an association from another query

PHP query using an association from another query I am trying to INSERT into my SQL table in PHP using an association I already returned from a previous SELECT query. But the compiler is giving me a syntax error 'unexpected $EOF'. Essentially, this is what I am doing: $query2 = "SELECT * FROM users WHERE user_name='$user.username'"; $result2 = mysqli_query($db, $query2); $new_user = mysqli_fetch_assoc($result2); $query3 = "INSERT INTO new_table (new_user_id) VALUES('$new_user['user_id']');"; mysqli_query($db, $query3); Query 3 is the one giving me the error. I have referenced variables like this before with the fetch association. I'm incredibly new to PHP, but isn't that fetch by association just creating a dictionary? Any ideas? Thanks, Can you post the output of $new_user['user_id']? – Steve Mulvihill Jul 1 at 2:30 ...

How to debug php/MySQL COUNT(id) returning 1 instead of total entries value

How to debug php/MySQL COUNT(id) returning 1 instead of total entries value I need the total number of entries in my database. Question: Why does the line "print_r($rows)" return "Array ( [COUNT(id)] => 79 )" but then the line "$recordCount = Count($row); echo " record count = " . $recordCount;" returns "record count = 1". I've tried a massive amount of different versions of this code, but I cant type them all here or it would take forever to read. Here is the current version of the code, which is giving me the unexpected results I mention above: // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM games ORDER BY id DESC LIMIT $startRow, $rowsPerPage"; $result = $conn->query($sql); $sql = "SELECT COUNT(id) FROM games"; $results = $conn-...