Posts: 113
Threads: 38
Joined: Oct 2009
Reputation:
1
(02-02-2010, 10:44 PM)Master of The Universe Wrote: That is because the file was not meant for direct access, it requires a SQL connection...
The file is included at the bottom of coin.php and since the coin.php has established connection it works.
But if you try to access the list.php on it's own it fails, to solve that you put this at the beginning of the list.php
PHP Code: if(!defined(@$connect)) { include "connect.php"; }
It will include the connect.php if $connect wasn't declared.
thanks..when I go to edit/delete a file, I receive this:
Not Found
The requested URL /coins/t.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Posts: 1,351
Threads: 111
Joined: Oct 2009
Reputation:
40
02-02-2010, 10:56 PM
(This post was last modified: 02-02-2010, 10:59 PM by Gaijin.)
Open the file, list.php and find this line;
PHP Code: echo "<td><a href=\"t.php?edit={$row['id']}\">Edit</a> | <a href=\"t.php?del={$row['id']}\">Delete</a>";
Then replace that line with this one;
PHP Code: echo "<td><a href=\"coin.php?edit={$row['id']}\">Edit</a> | <a href=\"coin.php?del={$row['id']}\">Delete</a>";
Sorry I forgot to change the href...
Posts: 113
Threads: 38
Joined: Oct 2009
Reputation:
1
(02-02-2010, 10:56 PM)Master of The Universe Wrote: Open the file, list.php and find this line;
PHP Code: echo "<td><a href=\"t.php?edit={$row['id']}\">Edit</a> | <a href=\"t.php?del={$row['id']}\">Delete</a>";
Then replace that line with this one;
PHP Code: echo "<td><a href=\"coin.php?edit={$row['id']}\">Edit</a> | <a href=\"coin.php?del={$row['id']}\">Delete</a>";
Sorry I forgot to change the href...
script is working fine so far. wanted to ask. anyways to make it so when I edit/delete a line, it'll refresh the page? currently, once I do either of the 2, I have to backspace out the url to get back to the /coin.php file.
also, I added another field to the database (I ran the query to add it and added it in the files and etc, but where in this section would I add it?
Code: $edit_id = (int) $_POST['id'];
$sql = "UPDATE `coin_info` SET `date` = '{$_POST['date']}',";
$sql .= "`price` = '{$_POST['price']}',`condition` = '{$_POST['condition']}',`year` = '{$_POST['year']}',";
$sql .= "`silver` = '{$_POST['silver']}',`gold` = '{$_POST['gold']}',`weight` = '{$_POST['weight']}' ";
$sql .= "WHERE `id` = '{$edit_id}' LIMIT 1 ;";
Posts: 1,351
Threads: 111
Joined: Oct 2009
Reputation:
40
It doesn't actually matter where you put it, but let's say you have created another field called, "record", and you have placed it in the database under the field "price"...
The query would look like this.
PHP Code: $edit_id = (int) $_POST['id']; $sql = "UPDATE `coin_info` SET `date` = '{$_POST['date']}',"; $sql .= "`price` = '{$_POST['price']}', `record` = '{$_POST['record']}',`condition` = '{$_POST['condition']}',`year` = '{$_POST['year']}',"; $sql .= "`silver` = '{$_POST['silver']}',`gold` = '{$_POST['gold']}',`weight` = '{$_POST['weight']}' "; $sql .= "WHERE `id` = '{$edit_id}' LIMIT 1 ;";
You will also need to add the input field in the HTML code, with the name "record"...
Code: <input type="text" name="record" />
For you other problem, that's how PHP works, but you can change these lines;
PHP Code: echo "Coin added!", "<br />"; # and echo "Edited {$edit_id}!", "<br />"; # and echo "Deleted ID ", $id, "<br />";
To this;
PHP Code: header("Location: coin.php");
The will refresh your page, but note that the header function needs to be called before any output has been made, echo or print...
Other wise it will return an error.
Posts: 113
Threads: 38
Joined: Oct 2009
Reputation:
1
(02-03-2010, 12:30 PM)Master of The Universe Wrote: It doesn't actually matter where you put it, but let's say you have created another field called, "record", and you have placed it in the database under the field "price"...
The query would look like this.
PHP Code: $edit_id = (int) $_POST['id']; $sql = "UPDATE `coin_info` SET `date` = '{$_POST['date']}',"; $sql .= "`price` = '{$_POST['price']}', `record` = '{$_POST['record']}',`condition` = '{$_POST['condition']}',`year` = '{$_POST['year']}',"; $sql .= "`silver` = '{$_POST['silver']}',`gold` = '{$_POST['gold']}',`weight` = '{$_POST['weight']}' "; $sql .= "WHERE `id` = '{$edit_id}' LIMIT 1 ;";
You will also need to add the input field in the HTML code, with the name "record"...
Code: <input type="text" name="record" />
For you other problem, that's how PHP works, but you can change these lines;
PHP Code: echo "Coin added!", "<br />"; # and echo "Edited {$edit_id}!", "<br />"; # and echo "Deleted ID ", $id, "<br />";
To this;
PHP Code: header("Location: coin.php");
The will refresh your page, but note that the header function needs to be called before any output has been made, echo or print...
Other wise it will return an error.
please tell me what I'm doing wrong-
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`description` = 'description' WHERE `id` = '7' LIMIT 1' at line 1
Edit failed!
description is the new line I added.
Code: $edit_id = (int) $_POST['id'];
$sql = "UPDATE `coin_info` SET `date` = '{$_POST['date']}',";
$sql .= "`price` = '{$_POST['price']}',`condition` = '{$_POST['condition']}',`year` = '{$_POST['year']}',";
$sql .= "`silver` = '{$_POST['silver']}',`gold` = '{$_POST['gold']}',`weight` = '{$_POST['weight']}' ";
$sql .="`description` = '{$_POST['description']}' ";
$sql .= "WHERE `id` = '{$edit_id}' LIMIT 1 ;";
Posts: 1,351
Threads: 111
Joined: Oct 2009
Reputation:
40
You forgot to add a comma.... try this query and take a look at the end of the third line.
Code: $edit_id = (int) $_POST['id'];
$sql = "UPDATE `coin_info` SET `date` = '{$_POST['date']}',";
$sql .= "`price` = '{$_POST['price']}',`condition` = '{$_POST['condition']}',`year` = '{$_POST['year']}',";
$sql .= "`silver` = '{$_POST['silver']}',`gold` = '{$_POST['gold']}',`weight` = '{$_POST['weight']}', ";
$sql .="`description` = '{$_POST['description']}' ";
$sql .= "WHERE `id` = '{$edit_id}' LIMIT 1 ;";
Posts: 113
Threads: 38
Joined: Oct 2009
Reputation:
1
ah..over looked it I suppose. thanks!
|