Log in

View Full Version : Some PHP and MySQL Help (2)



Tristan S.S.
02-14-2007, 02:22 AM
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

blm126
02-14-2007, 03:01 AM
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.

mechatama25
02-14-2007, 03:47 AM
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

Tristan S.S.
02-16-2007, 04:33 PM
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.

TheBigT
02-17-2007, 01:55 AM
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.

Tristan S.S.
02-17-2007, 07:41 PM
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.

thetestingsite
02-17-2007, 08:13 PM
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:



<?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:



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.

Tristan S.S.
02-17-2007, 10:19 PM
Thankyou!

I will play around with the scripts and see what I come up with, again THANKYOU!

thetestingsite
02-18-2007, 02:02 AM
No problem, let me know if you need any further help.

Tristan S.S.
02-18-2007, 02:06 AM
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?

thetestingsite
02-18-2007, 02:09 AM
In your database table, you also need the field 'id' (or something similar) to identify which row you are editing. You could probably go into your database using a web-based administration tool such as PHPmyAdmin (or similar) and add this field in there.

Other than that, the script will not function properly (the snippet I posted above).

Hope this helps.

Tristan S.S.
02-18-2007, 02:12 AM
Yes I have this field allready and it has a value of zero........?