SitePoint Sponsor |
|
User Tag List
Results 51 to 75 of 151
-
Mar 29, 2006, 06:55 #51
she will be my first chose.
thanks spikeZ for joining
will you care to share your expertise ?
jelena ill say this to you thanks for all the help specially the diffrent methods
you tought me i apriciated.
however, if this is a project for money i will not mind sharing part of the profit
after all the porpose of community is to help each othere and learn from each other
right spikeZ?
any way may be one day all be teaching begginers even if the Qs were silly like my
Qs corrently.
-
Mar 29, 2006, 07:01 #52
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Don't worry hisham, we are all here to learn! I was just kidding and Jelena is a great teacher
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Mar 29, 2006, 07:04 #53
indeed she is.
thanks spikeZ
-
Mar 29, 2006, 07:24 #54
would you help me please
am trying to delete a record.!
it display
Records deleted: %d 0
29
the address bar
http://localhost/Practise/test2/dele...?article_ID=29
for me the code looks ok
PHP Code:<?php
include "connect.php";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$article_id = $_GET['article_ID'];
$sql = 'DELETE FROM articles WHERE articleID = "$article_id" ';
mysql_query($sql) or die(mysql_error());
//i got this from the manual
echo ("Records deleted: %d\n". mysql_affected_rows());
echo '<br />';
echo $article_id;
?>
-
Mar 29, 2006, 07:38 #55
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Here you go
PHP Code:$sql = "DELETE FROM articles WHERE articleID = '".$article_id."'";
mysql_query($sql) or die(mysql_error());
//i got this from the manual
echo ("Records deleted:".$article_id);
-- Jelena --
-
Mar 29, 2006, 07:48 #56
its working heeeha
i cant belive my self.
ahhh i need practise and practise so i will not do such mistakes
. .
about the word thats the less i can do at the corrent time
-
Mar 29, 2006, 08:04 #57
Do you know any tutorials or may be example that can learn how to direct
the admin
example
when the admin click delete it goes to a page stating this record hase been
deleted and in may be a timer of 5secound he goes to the display page
which he can delete or edit the records
i tryed posting a link in the delete page but when i click the page do not
refresh is this becouse am using localhost ?
-
Mar 29, 2006, 08:18 #58
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
why don't you just show him a link
Code:<a href="article_list.php">Back to list of articles</a>
Code:<a href="" onclick="history.go(-1);">Go Back</a>
-- Jelena --
-
Mar 29, 2006, 08:32 #59
Actually thats what i did i just thouht may be there is
othere way to go around it.
Or even go with back button
Code:<a href="" onclick="history.go(-1);">Go Back</a>
-
Mar 29, 2006, 09:07 #60
This is the Read code
but it does not display the Date !?
is there a special way to get the date from the DB.
Notice: Undefined variable: row in E:\Practise\test2\read.php on line 68
PHP Code:include "connect.php";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$article_id = $_GET['article_ID'];
$sql = "SELECT * FROM articles WHERE articleID = '".$article_id."'";
mysql_query($sql) or die(mysql_error());
$res = mysql_query($sql);
$num = mysql_fetch_row($res);
if (!$res) {
echo 'Could get record: ' . mysql_error();
exit;
}
/*
echo $row[0]; // atticle id
echo $row[1]; // article name
echo $row[2]; // summary
echo $row[3]; // author
echo $row[4]; // content
echo $row[5]; // notes
echo $row[6]; //date added
echo $row[7]; //status
*/
?>
<table width="720" border="1" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="181" height="30" valign="top">Name </td>
<td width="539" valign="top"><?php echo $num[1]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Summary</td>
<td valign="top"><?php echo $num[2]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Author</td>
<td valign="top"><?php echo @$num[3]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Content</td>
<td rowspan="2" valign="top"><?php echo $num[4]; ?></td>
</tr>
<tr>
<td height="190"> </td>
</tr>
<tr>
<td height="42" valign="top">Note</td>
<td valign="top"><?php echo @$row[5]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Date added </td>
<td valign="top"><?php echo $row[6]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Status</td>
<td valign="top"><?php echo @$row[7]; ?></td>
</tr>
</table>
<?php mysql_close($conn); ?>
-
Mar 29, 2006, 09:20 #61
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
try this out. I prefer using mysql_fetch_assoc really.
PHP Code:include "connect.php";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$article_id = $_GET['article_ID'];
$sql = "SELECT * FROM articles WHERE articleID = '".$article_id."'";
mysql_query($sql) or die(mysql_error());
$res = mysql_query($sql);
$num = mysql_fetch_assoc($res);
if (!$res) {
echo 'Could get record: ' . mysql_error();
exit;
}
?>
<table width="720" border="1" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="181" height="30" valign="top">Name </td>
<td width="539" valign="top"><?php echo $num["article_name"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Summary</td>
<td valign="top"><?php echo $num["summary"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Author</td>
<td valign="top"><?php echo $num["author"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Content</td>
<td rowspan="2" valign="top"><?php echo $num["content"]; ?></td>
</tr>
<tr>
<td height="190"> </td>
</tr>
<tr>
<td height="42" valign="top">Note</td>
<td valign="top"><?php echo $row["article_note"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Date added </td>
<td valign="top"><?php echo $row["date_added"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Status</td>
<td valign="top"><?php echo $row["status"]; ?></td>
</tr>
</table>
<?php mysql_close($conn); ?>
If date still doesn't want to display, try to do
PHP Code:var_dump($num);
-- Jelena --
-
Mar 29, 2006, 09:35 #62
for empty fields in the database i get this errors
line 56 in the date
Notice: Undefined variable: row in E:\Practise\test2\read.php on line 51
Notice: Undefined variable: row in E:\Practise\test2\read.php on line 56
Notice: Undefined variable: row in E:\Practise\test2\read.php on line 60
-
Mar 29, 2006, 09:40 #63
var_dump() is very intersting
it gives me
array(8) { ["articleID"]=> string(1) "9" ["article_name"]=> string(10) "xcnvdmjdgm" ["summary"]=> string(12) "dmhsdkmgdgmk" ["author"]=> string(11) "dgjmdghjmdg" ["article_content"]=> string(13) "dghmhjmhklto;" ["notes"]=> string(5) "dgmdg" ["date_added"]=> string(15) "Sun-26-Mar-2006" ["status"]=> string(1) "0" }
-
Mar 29, 2006, 10:13 #64
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:<?php
include "connect.php";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$article_id = $_GET['article_ID'];
$sql = "SELECT * FROM articles WHERE articleID = '".$article_id."'";
mysql_query($sql) or die(mysql_error());
$res = mysql_query($sql);
$num = mysql_fetch_assoc($res);
if (!$res) {
echo 'Could get record: ' . mysql_error();
exit;
}
?>
<table width="720" border="1" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="181" height="30" valign="top">Name </td>
<td width="539" valign="top"><?php echo $num["article_name"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Summary</td>
<td valign="top"><?php echo $num["summary"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Author</td>
<td valign="top"><?php echo $num["author"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Content</td>
<td rowspan="2" valign="top"><?php echo $num["article_content"]; ?></td>
</tr>
<tr>
<td height="190"> </td>
</tr>
<tr>
<td height="42" valign="top">Note</td>
<td valign="top"><?php echo $num["notes"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Date added </td>
<td valign="top"><?php echo $num["date_added"]; ?></td>
</tr>
<tr>
<td height="30" valign="top">Status</td>
<td valign="top"><?php echo $num["status"]; ?></td>
</tr>
</table>
<?php mysql_close($conn); ?>-- Jelena --
-
Mar 29, 2006, 11:31 #65
its fully functional thanks to you
i been 11 stight infront of the computer
my right eaye down see thinks clear any more my time is up.
thanks agine
take care
-
Mar 29, 2006, 12:17 #66
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
You are really welcome
Let me know if you find problems with edit function.-- Jelena --
-
Mar 29, 2006, 22:07 #67
hi there lovely morning in south east asia today
ok this morning i started working on the edit part and i came up with this
i know its not that efficient, may be all inhance it slowly.
comment on it please.
edit1
PHP Code:
<?php
include "connect.php";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$article_id = $_GET['article_ID'];
$sql = "SELECT * FROM articles WHERE articleID = '".$article_id."'";
mysql_query($sql) or die(mysql_error());
$res = mysql_query($sql);
$num = mysql_fetch_assoc($res);
if (!$res) {
echo 'Could get record: ' . mysql_error();
exit;
}
?>
<form action="edit2.php" method="post">
Article ID <br />
<input name="articleid" type="text" id="articleid" value="<?php echo $num["articleID"];?>" size="15" maxlength="15" />
<br />
Article Name <br />
<input name="articlename" type="text" id="articlename" value="<?php echo $num["article_name"];?>" size="80" maxlength="80" />
<br />
Summary <br />
<textarea name="summary" cols="50" rows="3" wrap="physical" id="summary"><?php echo $num["summary"];?>
</textarea>
<br />
Author <br />
<input name="author" type="text" id="author" value="<?php echo $num["author"];?>" size="50" maxlength="50" />
<br />
Article Content <br />
<textarea name="articlecontent" cols="100" rows="20" wrap="physical" id="articlecontent"><?php echo $num["article_content"];?></textarea>
<br />
Notes <br />
<textarea name="notes" cols="50" rows="3" wrap="physical" id="notes"><?php echo $num["notes"];?></textarea>
<br />
Date Posted <br />
<input name="date" type="text" id="date" value="<?php echo $num["date_added"];?>" size="30" maxlength="30" />
<br />
Status <br />
<input name="status" type="text" id="status" value="<?php echo $num["status"];?>" size="30" maxlength="30" />
<br />
<input name="" type="submit" value="Submit" />
</form>
<?php
mysql_free_result($res);
mysql_close($conn);
?>
PHP Code:<?php
include "connect.php";
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('connecting to MySQL failed');
mysql_select_db($dbname);
$article_id = $_POST['articleid'];
$articlename = $_POST['articlename'];
$summary = $_POST['summary'];
$author = $_POST['author'];
$articlecontent = $_POST['articlecontent'];
$notes = $_POST['notes'];
$status = $_POST['status'];
$sql = "UPDATE articles "."SET article_name = '$articlename',
summary = '$summary',
author = '$author',
article_content='$articlecontent',
notes='$notes', status = '$status'"
. "WHERE articleID = '$article_id'";
mysql_query($sql) or die(mysql_error());
$res = mysql_query($sql);
if (!$res) {
echo 'Could get record: ' . mysql_error();
exit;
}else {echo 'OK';}
mysql_close($conn);
?>
-
Mar 30, 2006, 02:50 #68
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Hello there
No, actually your edit is quite fine. There are few things I would change:
I would put articleid as hidden field in a form like:
PHP Code:<input name="articleid" type="hidden" id="articleid" value="<?php echo $num["articleID"];?>" />
-- Jelena --
-
Mar 30, 2006, 03:06 #69
hi there i hope you are having a lovely day in country ?
all do that thanks for remainding me on that, its going to be a mess
if the admin change the id number.
i think this is the simplest article system ever been done with PHP
i have one q if i want to implement authontication on this script
how do i go about it.
shall i use DB or just text file to store
shall i think of encription shall i put the user name and passward in
the script it self. may be session.?
what would you do if your in my place (your Profissional opinion) please.?
thanks'
-
Mar 30, 2006, 03:16 #70
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
If we are talking about protecting admin area, I would go with htaccess to protect administration section (if it's available on a server).
-- Jelena --
-
Mar 30, 2006, 03:19 #71
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Also, next stage would be for you to create functions which will perform various actions. For example, you could create a function for adding new article, place it in separate file and include it where it is needed.
I would also create a configuration file where I would put various configuration setting like DB details for example, definitions of paths, urls etc..
Give me some time, and I'll show you an example.-- Jelena --
-
Mar 30, 2006, 03:52 #72
according to http://en.wikipedia.org/wiki/Htaccess
its apache server (i never tryed Apache server) feature which make you setup the directory permission
and ofcorse many othere features like block serten IP addreses and the list go own
its a big scop topic to study with my corrent position in PHP.
i was thinking of something simpler. may be session
Do you know any good tutorials for begginers about sessions.?
-
Mar 30, 2006, 03:56 #73
reading more about it its very handy for security.
-
Mar 30, 2006, 04:40 #74
- Join Date
- Feb 2005
- Location
- Universum, 3rd Corner
- Posts
- 3,000
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Let me explain what I have mentioned in my previous post.
This would be next stage of creating your project little bit in order.
This is also a basic concept but you should get an idea:
I will add 3 more files: functions.php, config.php, common.php
firstly config.php
PHP Code:<?php
//db settings
define("BASESERVER","localhost");
define("BASEUSER","roots");
define("BASEPASS", "555456");
define("BASENAME","site");
?>
common.php
PHP Code:<?php
include_once "config.php";
include_once "functions.php";
session_start();
//connect to the base
if(!($db = @mysql_pconnect(BASESERVER, BASEUSER, BASEPASS))) //connect to base host
die("Cannot connect to the base server.");
if(!@mysql_select_db(BASENAME,$db)) //select base
die("Database doesn't exist!!!");
//common functions
function my_query($sql)
{
GLOBAL $_SERVER["PHP_SELF"];
GLOBAL $db;
if(($result = @mysql_query($sql,$db)) == 0) //Execute SQL query
{
echo "\n<hr>Database error: <strong>".mysql_error()."</strong><br /><br />\n";
die("Query was (<strong>$sql</strong>) in file <strong>".$_SERVER["PHP_SELF"]."</strong>");
}
else
return $result;
}
?>
Also, you will notice my_query function which basically execute the given query. You will probably find id handy later on.
And functions.php
PHP Code:/**
*
* Simple function for adding article
*
* Function expects an array with article details
* it will perform all neccesary checks
* On error it will set session with error and return false
* On success, it will add record into database and return true
*
*/
function article_add($data)
{
if(empty($data["article_name"]))
{
$_SESSION["error"] = "Please enter The Article Name";
return false;
}
else if(empty($data["summary"]))
{
$_SESSION["error"] = "Please enter a summary";
return false;
}
else if(empty($data["article_content"]))
{
$_SESSION["error"] = "Please enter a content";
return false;
}
$sql = "INSERT INTO articles SET";
$sql .= " article_name = '".$data["article_name"]."'";
$sql .= ", summary = '".$data["summary"]."'";
$sql .= ", author = '".$data["author"]."'";
$sql .= ", article_content = '".$data["article_content"]."'";
$sql .= ", notes = '".$data["notes"]."'";
$sql .= ", date_added = NOW()";
$sql .= ", Status = '0'";
my_query($sql);
return true;
}
Now, your file which adds article in database should look like this:
PHP Code:<?php
include_once "common.php";
$article["article_name"] = $_POST['articlename'];
$article["summary"] = $_POST['summary'];
$article["author"] = $_POST['author'];
$article["article_content"] = $_POST['bodycontent'];
$article["notes"] = $_POST['notes'];
if(article_add($article))
{
//success
//do whatever you want to do on succes
}
else
{
//error
$_SESSION["article"] = $article;
header("Location: add11.php");
}
?>
This is first stage of course, and lots of changes can be done to all those files, but it's wise to go step by step
As for the sessions, they are good for usage for logging in users, but you should firstly decide where would you like to store username/password. I suggested htacces because it's the easiest way and it's just fine for the start.Last edited by jelena; Mar 30, 2006 at 08:10. Reason: fixed syntax error..
-- Jelena --
-
Mar 30, 2006, 06:00 #75
clean Code, it make me realise am at level 7 of 100 in PHP
but thats will not stop me.
Originally Posted by jelena
i understand from htacces its for apache servers, what about
IIS, if can do in ISS as well please point me to a tutorial.
i dare not ask you more about article system after i saw your code
you done alot.
Bookmarks