I am currently working on a project. And have been assigned to get up to speed quickly on php. And even though I love the language, it's not easy to get up to speed in like 2 seconds :-)
The code I will list below is supposed to have four parts:
1. Not logged in. List up all text from the database.
2. Logged in. List up all text from the database. But now with an "edit" button, with the possibility to jump to number 3.
3. Logged in, and pressed the edit button.
A form should show here, and the possibility to insert text into a field, and press submit.
4. Like number two, but now with the added text below.
The code I have is like this:
Expand|Select|Wrap|Line Numbers
- <?php include ("c:/db.inc");
- error_reporting(E_ALL);
- ini_set('display_errors', '0');
- //global $id = intval( mysql_real_escape_string( $_GET['id'] ));
- //global $itemid = intval( mysql_real_escape_string( $_GET['Itemid'] ));
- if ($my->id && $my->id > 0) { //if logged in
- //this code tells me that I am logged in.
- //show edit so I can show form
- $query = "SELECT * FROM jos_ibruk_issues WHERE jos_issues.contentid= '$id' ORDER BY text desc";
- $result = mysql_query($query);
- while($row= mysql_fetch_array($result)) {
- echo"$row[text]<BR>";
- }
- } else { //not logged in, list up text
- $query = "SELECT * FROM jos_issues WHERE jos_issues.contentid= '$id' ORDER BY text desc";
- $result = mysql_query($query);
- while($row= mysql_fetch_array($result)) {
- echo"$row[text]<BR>";
- }
- //mysql_close();
- }
- if ($my->id && $my->id > 0) { //&& $_POST['Submit'] == 'sumbmit') { //IF logged in and have pressed the EDIT "link"
- if($_POST['submit'] == 'Submit') {//if submit when have pressed EDIT link in number 2.
- //echo "Submit has been pressed <BR>";
- if(!$_POST['text'] || $_POST['text'] == "") {
- echo "there is a problem. did you fill out anything in the form?<BR>";
- }
- else {
- //all ok, insert into db.
- $id = intval( mysql_real_escape_string($_GET['id']));
- $as_text = addslashes($_POST['text']);
- $tr_text = trim($as_text);
- $query = "INSERT INTO jos_issues(ID,text,contentid)
- VALUES(NULL,'$tr_text','$id')";
- $result = mysql_query($query);
- echo "thanks for posting these issues<BR>";
- $id = intval( mysql_real_escape_string( $_GET['id'] ));
- //echo "id = $id";
- $query = "SELECT * FROM jos_issues WHERE jos_issues.contentid= '$id' ORDER BY text desc";
- $result = mysql_query($query);
- while($row= mysql_fetch_array($result)) {
- echo"$row[text]<BR>";
- }
- }
- }
- $adresse = "http://localhost/demotest/index.php?option=com_content&task=view&" . "id=" . "$id" . "&Itemid=" . "$itemid";
- print <<<END
- <html>
- <form id="form1" name="frmname" method="post" action="<? echo $_SERVER['$adresse'];?">
- <label>Text
- <input type="text" name="text" />
- </label>
- <label>
- <input type="submit" name="submit" value="Submit" />
- </label>
- </form>
- </html>
- END;
- }
- ?>
Can you please help me with this? I have been sitting with this for several days now. I should have been finished with this already, and my boss is breathing down my neck. And he haven't brushed his teeth today :-)
Phropman