<?php
$q = mysql_query("INSERT INTO mytable VALUES('test')"); $rownumber = mysql_insert_id(); //$rownumber contains the id of the new row ?>
0 Comments
<?php
$query = mysql_query("SELECT number FROM table ORDER BY number DESC LIMIT 2"); $second_highest = mysql_result($query,1,0); echo "the answer to your question is $second_highest"; ?> <?php
$db = mysql_connect("HOST", "USERNAME", "PASSWORD"); mysql_select_db("DATABASE_NAME",$db); ?> Another common query is to get to the current time in addition to the date within mysql.
When you want to log when something happens - for instance a post to your message board, this will be a particularly useful thing to know. With the current time and date you will need to use NOW() like so: <?php $update = mysql_query("UPDATE my_users SET lastlogin = NOW() WHERE username = 'elvis'"); ?> You can store a image in a database making the database table field of BLOB type. Later you can query the database fecth the content of image as usual and display this fetched-image on a webpage (or whatever the way like) using php headers
This means exactly what it says and is one of the clearer PHP errors! Basically you have sent some information to the web browser before your call to header().
However, it can be tricky to spot if this is just a little whitespace. If there is nothing obvious, then turn on hidden characters in your text editor and you should be able to see any little bits of whitespace that are being sent to the browser before your call to header. use ob_start() line at the beginning of the page This is a syntax error, meaning that there is something in your code stopping it from being parsed correctly and therefore run.
What you should do is check carefully at the lines around where the error is for any simple mistakes - for instance forgetting to include semi-colons at the end of statements, or not using " correctly or ' correctly in your statements. They can be quite fiddly to find, but by carefully checking the code around the line generating the area, you should be able to find the mistake you have made with your syntax and resolve the T_variable error. This error means exactly that - you are using a constant that has not been declared anywhere in the script.
Now, if you mean to be using constants in the script, then you simply have forgotten to define it, so make sure that you do so. More often than not however, this happens when you forget to put the $ infront of a variable name, and so you just need to insert the $ immediately before the name of that variable to fix the error. This happens when you try to convert an array to a string within your code.
The notice or error will tell you exactly what line this is happening at so you can amend your code accordingly. It may be that you passed the wrong variable to a function or are not using it correctly for what you want to achieve. Either way this is one of the easier errors to debug and fix to get your code doing what you want it to do. |