just for info: $_POST['key'] (with square brackets, but that's probably a typo)
Html form
Collapse
X
-
thank you, Dormilich for replying. It is now working.
Is there any function on php which reads the last value of data on the database table.
For eg: On database table
tbl_a
std_id name
1 Ram
2 Shyam
3 Hari
4 Kishor
In these above table. I want to read that last value of std_id(4) through php function or any idea if u have .
& one thing more is How to use primary key & foreign key on sql database.Comment
-
seems like there were a lot of typo's in my code. i also forgot mysql_select_db but you already knew i did.
the request is very simple i think:
for the question about primary key and foreign key, i would refer to the mysql forum since it isnt php anymore and ... i can't really answer that :-OCode:$result = mysql_query("SELECT * FROM tbl_a"); $anArray = mysql_fetch_assoc($result); $lastRecord = $anArray[(count($anArray)-1)];Comment
-
that's because only the first row was fetched…
depending on your DB system, there are functions that will fetch all results in one go (like PDOStatement->fetchAll()) where this would work.Comment
-
Hi, using this code won't protect you from SQL Injection, you're still inserting direct $_POST vars into your SQL query, I suggest you at least do something like:
[code=php]
$$key = addslashes($val ue);
/* or */
$$key=mysql_rea l_escape_string ($value);[/code]
And to be more accurate, the query for multiple inserts, as Markus mentioned
that is available since mySQL 4, so it should work perfectly (in case you are using mySQL 4 or higher), otherwise you must probably have sql syntax error or your number of inserts is limited by configuration.Multiple inserts, through one query, can be achieved with syntax like:
Expand|Select|W rap|Line Numbers
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),( 4,5,6),(7,8,9);
Not sure what the earliest version of MySQL this will work with, but it does for 5.1.Comment
Comment