Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Some PHP and MySQL Help (2)

  1. #1
    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

  2. #2
    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.

  3. #3
    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

  4. #4
    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.

  5. #5
    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.

  6. #6
    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.

  7. #7
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 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:

    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.

  8. #8
    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!

  9. #9
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    No problem, let me know if you need any further help.

  10. #10
    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •