Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
php script
#11
(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.
Reply
#12
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...
Reply
#13
(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 ;";
Reply
#14
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.
Reply
#15
(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 ;";
Reply
#16
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 ;";
Reply
#17
ah..over looked it I suppose. thanks!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP Framework List: An Ultimate Guide to 102 PHP Frameworks for Web Developers tk-hassan 0 953 07-27-2020, 11:26 PM
Last Post: tk-hassan
  Req. Upload PHP script. 3 X P L 0 I T 1 1,350 07-14-2012, 05:19 PM
Last Post: 'Snorlax
  PHP Video Tutorials (PHP For Beginners) Eleqtriq 4 3,689 10-10-2011, 01:00 PM
Last Post: Greyersting
  optimize mysql through a php script andrewjs18 7 3,377 10-05-2011, 06:31 PM
Last Post: John.
  Creating a simple PHP/MySQL login script ndee 16 10,530 05-14-2011, 02:18 AM
Last Post: モrainee

Forum Jump:


Users browsing this thread: 1 Guest(s)