Go Back   Dynamic Drive Forums > General Coding > PHP
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-14-2007, 02:22 AM
Tristan S.S. Tristan S.S. is offline
Junior Coders
 
Join Date: Nov 2006
Location: 90 miles north of Las Vegas
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation Some PHP and MySQL Help (2)

Hi.

1) I am wanting to make a admin page to alow someone to update a mysql database. I would like to know how to make 2 text fields that display the current contents of the rows in the table, and when you change them and click update the pages refreshes, the table updates and the new contents are in the text field.

2) I would also like to know if anyone knows how to allow someone to pay for a program with paypal, then be able to download it after a succesful payment. However also so that no one could just type the url to file and download it. Does anyone know how to do this?

I thank you greatly in advance !

- Tristan
Reply With Quote
  #2  
Old 02-14-2007, 03:01 AM
blm126's Avatar
blm126 blm126 is offline
Senior Coders
 
Join Date: Sep 2005
Posts: 882
Thanks: 0
Thanked 3 Times in 3 Posts
Default

These are both rather complex programs. For 1 check PHPmyAdmin, and for number two, well do a search there is a lot of stuff out there for cheap/free that does this.
__________________
-Brady
Reply With Quote
  #3  
Old 02-14-2007, 03:47 AM
mechatama25 mechatama25 is offline
New Comer (less than 5 posts)
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

for no 1:

here are some things you can do.

1. In one php script you can set the form to target itself (action="")
2. Have a trigger hidden input in the form. eg: input name: trigger, value:1
3. Make a process that only activates if the trigger input is posted to the page, which will then updates the mysql database.
4. To show the current values inside a textfield simply echo the textfield inside the mysql_fetch_assoc or whatever fetch function you use. eg: echo "<textarea>{$row['value']}</textarea>";

hope that helped
Reply With Quote
  #4  
Old 02-16-2007, 04:33 PM
Tristan S.S. Tristan S.S. is offline
Junior Coders
 
Join Date: Nov 2006
Location: 90 miles north of Las Vegas
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am still not sure. Thanks, but does anyone knw the actual code for this.

Just say my database url is : http://myserver.net/098/
My Password is : Bob
My Username is : Joe
My database table is : News
And the two fields I am trying to update are are : Text1 and Text2

What would be the code to display the contents of the two field into a textbox on the screen that is editable and on "submit" updates the table and the two rows. I know how to type out the MySQL query for the update part, but the actual displaying of the contents into a text box is where I am stuck.
Reply With Quote
  #5  
Old 02-17-2007, 01:55 AM
TheBigT TheBigT is offline
Junior Coders
 
Join Date: Feb 2005
Posts: 96
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I find that this little file works well.

https://sourceforge.net/projects/phpminiadmin/

The person would have to know how to type in the queries and such, but it is a nice little tool.

However, if you want someone to make that program, it would require a lot of work. Mechatama25 told you one way to do it.

And lastly, it is bad to post your login information for your database in a public forum. I would advise against it in the future.
Reply With Quote
  #6  
Old 02-17-2007, 07:41 PM
Tristan S.S. Tristan S.S. is offline
Junior Coders
 
Join Date: Nov 2006
Location: 90 miles north of Las Vegas
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey thanks...

It's a nice program but probably a little to complex for what I am looking for.

And don't worry! that login information is fake, I know enough not to do something as stupid as that.

Well if there is not a simple snippet of code anyone can give me, then Its probably not worth my troubles.

Thanks anyway.
Reply With Quote
  #7  
Old 02-17-2007, 08:13 PM
thetestingsite's Avatar
thetestingsite thetestingsite is offline
The Guy That Moderates
 
Join Date: Sep 2006
Location: St. George, UT
Posts: 2,795
Thanks: 3
Thanked 156 Times in 154 Posts
Default

Sorry, coming in to this thing a little late; and I'm still not sure I fully understand what you want, but here goes. Try the following:

Code:
<?php

$DBserver = "localhost"; //change to match your db server
$DBuser = "username"; //change to your db username
$DBpass = "password"; //change to your db password
$DB = "news"; //change to your db
$table = "news"; //change to the table in the db

$conn = mysql_connect($DBserver, $DBuser, $DBpass);
mysql_select_db($DB);


if ($_POST['action'] == "update") { //if form was submitted, update table

$id = $_POST['id'];
$text1 = $_POST['text1'];
$text2 = $_POST['text2'];


mysql_query("UPDATE `$table` SET `text1`= '$text1', `text2` = '$text2' WHERE `id` = '$id'");

header('Location: '.$_SERVER["PHP_SELF"]);
}

else { //if form not submitted, display form

$info = mysql_query("SELECT * FROM `$table` WHERE `id` = '$id'");

$qry = mysql_fetch_array($info);
?>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="hidden" name="action" value="update">
<input type="hidden" name="id" value="<?php echo $_REQUEST['id'];?>">

Text 1: <input type="text" name="text1" value="<?php echo $qry['text1'];?>"> 

Text 2: <input type="text" name="text2" value="<?php echo $qry['text2'];?>">

<input type="submit" value="Update Info">
</form>

<?php
}
?>

Hope this is something like what you wanted. To get it to work properly, you would need to call the page like so:

Quote:
test.php?id=id
Where "id" (in red) is the id that identifies the row for which you are trying to update.

Sorry for not explaining much more, short on time right now. If you need any further help, let me know or perhaps another member could help you further.

Hope this helps.
Reply With Quote
  #8  
Old 02-17-2007, 10:19 PM
Tristan S.S. Tristan S.S. is offline
Junior Coders
 
Join Date: Nov 2006
Location: 90 miles north of Las Vegas
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou!

I will play around with the scripts and see what I come up with, again THANKYOU!
Reply With Quote
  #9  
Old 02-18-2007, 02:02 AM
thetestingsite's Avatar
thetestingsite thetestingsite is offline
The Guy That Moderates
 
Join Date: Sep 2006
Location: St. George, UT
Posts: 2,795
Thanks: 3
Thanked 156 Times in 154 Posts
Default

No problem, let me know if you need any further help.
Reply With Quote
  #10  
Old 02-18-2007, 02:06 AM
Tristan S.S. Tristan S.S. is offline
Junior Coders
 
Join Date: Nov 2006
Location: 90 miles north of Las Vegas
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi there thetestingsite.

I been trying to get the text box to display the contents of the row but it does seem to. I have not changed the code you gave me, except enter my database url, username, password, table name ect.

The colums are called text1 and text2 and the have the id of 0. even though I put mysite/admin.php?id=0 it does not display the contents......

Can you see anything that Im doing wrong here?
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:40 PM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.