Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: update row help

  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts

    update row help

    this displays all info based on the members id

    PHP Code:
    $connection = @mysql_connect($server$dbusername$dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $db1 = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $result = @mysql_query("SELECT username, memberid FROM authorize WHERE username = '".$_SESSION['username']."' AND memberid = 

    '"
    .$_SESSION['memberid']."'"$db1);


    $memberid $_SESSION['memberid'];

    $sql ="SELECT * FROM user_scripts WHERE memberid = '".$_SESSION['memberid']."'";
    $result = @mysql_query($sql,$connection) or die(mysql_error());
    if(
    mysql_num_rows($result)){

    while (
    $row mysql_fetch_array($result)) {

    if ((
    $row['memberid'] = "$memberid") && ($row['is_approved'] == "1")) {

    Echo 
    "title";
    Echo 
    "<table border=0>";
    Echo 
    "<tr><td>Date Submitted: </td>"
    Echo 
    "<td>". $-['row']['dated'] ."</td></tr>";
    Echo 
    "<tr><td>Email Address: </td>"
    Echo 
    "<td>". $-['row']['email_contact'] ."</td></tr>";
    Echo 
    "<tr><td>Name of foo: </td>"
    Echo 
    "<td>". $-['row']['foo_name'] ."</td></tr>";
    Echo 
    "<tr><td>Category: </td>"
    Echo 
    "<td>". $-['row']['category'] ."</td></tr>";
    Echo 
    "<tr><td>License: </td>"
    Echo 
    "<td>". $-['row']['license'] ."</td></tr>";
    Echo 
    "<tr><td>Price: </td>"
    Echo 
    "<td>". $-['row']['price'] ."</td></tr>";
    Echo 
    "<tr><td>Name of foo: </td>"
    Echo 
    "<td>". $-['row']['foo_site'] ."</td></tr>";
    Echo 
    "<tr><td>Link foo Url: </td>"
    Echo 
    "<td>". $-['row']['foo_url'] ."</td></tr>"
    Echo 
    "<tr><td>Description: </td>"
    Echo 
    "<td>". $-['row']['description'] ."</td></tr>"

    Echo 
    "</table>"
    echo 
    "<form action='/foo_update.php'>";
    echo 
    "Need to <input type='submit' name='your_foo' id='your_foo' value='Update'> your foo?";
    echo 
    "</form>"
    after button his clicked it goes here

    PHP Code:
    $connection = @mysql_connect($server$dbusername$dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $db1 = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $result = @mysql_query("SELECT username, memberid FROM authorize WHERE username = '".$_SESSION['username']."' AND memberid = 

    '"
    .$_SESSION['memberid']."'"$db1);

     
    $memberid $_SESSION['memberid'];

    $sql ="SELECT * FROM user_foo WHERE memberid = '".$_SESSION['memberid']."'";
    $result = @mysql_query($sql,$connection) or die(mysql_error());
    if(
    mysql_num_rows($result)){

    while (
    $row mysql_fetch_array($result)) {

    if ((
    $row['memberid'] = "$memberid") && ($row['is_approved'] == "1")) {

    Echo 
    "<form action='foo_updated.php' method='post' name='updated' id='updated'>";

    -----
    Change info and click update button------

    -----
    sql row info------

    echo 
    "<input type='submit' name='updated' id='updated' value='Click Here To Update'>";
    echo 
    "</form>"
    Each row has its own update button.
    If there is more then one row with the same memberid, all rows are updated with a single button. How can I assign the button to a row so it only uodates the that particular row instead of all of them. Each row has a unique id. Please help.
    Last edited by twobyfour; 06-28-2010 at 05:32 AM.

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    Los Angeles
    Posts
    545
    Thanks
    81
    Thanked 5 Times in 5 Posts
    To do what you want, you'll need to update on the unique id only. If memberid can have multiple values that are the same, then you can't use that. The only way to update just the affected row is to be able to tag on some kind of unique id number.
    RalphF
    Business Text Messaging Services
    https://www.MobileTextingService.com

  • #3
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    how can i do add the unique id to the query. the only reason why i have it displayed by memberid is because i dont want other members to see whats not theres.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Well, having it by ID is the right way to do it... but you should have a unique ID for each member. Each table should have a unique key identifier.

    In MySQL, you can set a numeric column as a key, then set it to autoinciment. It'll always generate a unique number for each row.

  • #5
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    i do have it that way. every row has a unique id. the member id is a random 10 digit number. I just need to add the row id to the query where when the button is clicked only the row with the id and the member id is updated.

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    You have a unique id for each member, plus each member having a random 10 digit number? What purpose does that serve? And if the 10 digit number isn't random, what good is it?

  • #7
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    no i have a unique id for each row and a random id for each member. the member id can appear multiple times but the row id is unique and auto increment.

    maybe i should clear this up

    Each row has its own update button.
    If there is more then one row with the same memberid, all rows with the same memberid are updated with a single button regardless of the unique row id. How can I assign the button to a row so it only uodates the that particular row instead of all of them. Each row has a unique id.
    Last edited by twobyfour; 06-28-2010 at 07:00 AM.

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Well... it seems your structure is borked.

    If each row has a unique ID, why not refer to it by that unique ID? Why are you trying to refer to by a non-unique number? It'd be like having two friends named John and storing them by first name only in your phone: you'll end up calling the wrong person a lot until you either learn their numbers or add their last names.

  • #9
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    i see what your saying and it makes since ofcourse, when a user logs in, the memberid is tied to there username

    PHP Code:
    $db1 = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $result = @mysql_query("SELECT username, memberid FROM authorize WHERE username = '".$_SESSION['username']."' AND memberid = 

    '"
    .$_SESSION['memberid']."'"$db1); 
    so only there submitted rows are shown to them. this part works. so they could have multiple submitted entries each taking up one row with a unique id.

    there submitted rows are showed like this

    PHP Code:
    $memberid $_SESSION['memberid'];

    $sql ="SELECT * FROM user_foo WHERE memberid = '".$_SESSION['memberid']."'";
    $result = @mysql_query($sql,$connection) or die(mysql_error());
    if(
    mysql_num_rows($result)){

    while (
    $row mysql_fetch_array($result)) {

    if ((
    $row['memberid'] = "$memberid") && ($row['is_approved'] == "1")) { 
    so all rows containing there memberid is displayed. this way they cant see other submittals by other members.

    each submittal has its own row with a unique id and when displayed, there is a submit button at the bottom of each displayed row. problem is if there are say two or more submitals being displayed, the button doesnt now which row to update so it updates all rows with there memberid in it.

    how can i add the unique row id with there memberid so the button know what row to update?
    Last edited by twobyfour; 06-28-2010 at 07:19 AM.

  • #10
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Can you show the code of whats being updated? In the forms you've shown, there's no actual inputs... so its hard to say how you should do it. You could do it with a hidden input, with a tag added to the inputs, etc.

  • #11
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Keleth View Post
    Can you show the code of whats being updated? In the forms you've shown, there's no actual inputs... so its hard to say how you should do it. You could do it with a hidden input, with a tag added to the inputs, etc.
    ok here we go

    page shows all rows with there memberid

    PHP Code:
    $connection = @mysql_connect($server$dbusername$dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $db1 = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $result = @mysql_query("SELECT username, memberid FROM authorize WHERE username = '".$_SESSION['username']."' AND memberid = '".$_SESSION['memberid']."'"$db1);


    $memberid $_SESSION['memberid'];

    $sql ="SELECT * FROM user_scripts WHERE memberid = '".$_SESSION['memberid']."'";
    $result = @mysql_query($sql,$connection) or die(mysql_error());
    if(
    mysql_num_rows($result)){

    while (
    $row mysql_fetch_array($result)) {

    if ((
    $row['memberid'] = "$memberid") && ($row['is_approved'] == "1")) {

    Echo 
    "Approved Scripts";
    Echo 
    "<table border=0>";
    Echo 
    "<tr><td>Date Submitted: </td>"
    Echo 
    "<td>"$GLOBALS['row']['dated'] ."</td></tr>";
    Echo 
    "<tr><td>Email Address: </td>"
    Echo 
    "<td>"$GLOBALS['row']['email_contact'] ."</td></tr>";
    Echo 
    "<tr><td>Name of Script: </td>"
    Echo 
    "<td>"$GLOBALS['row']['script_name'] ."</td></tr>";
    Echo 
    "<tr><td>Category: </td>"
    Echo 
    "<td>"$GLOBALS['row']['category'] ."</td></tr>";
    Echo 
    "<tr><td>License: </td>"
    Echo 
    "<td>"$GLOBALS['row']['license'] ."</td></tr>";
    Echo 
    "<tr><td>Price: </td>"
    Echo 
    "<td>"$GLOBALS['row']['price'] ."</td></tr>";
    Echo 
    "<tr><td>Name of Website: </td>"
    Echo 
    "<td>"$GLOBALS['row']['download_site'] ."</td></tr>";
    Echo 
    "<tr><td>Link Download Url: </td>"
    Echo 
    "<td>"$GLOBALS['row']['site_url'] ."</td></tr>"
    Echo 
    "<tr><td>Description: </td>"
    Echo 
    "<td>"$GLOBALS['row']['description'] ."</td></tr>"

    Echo 
    "</table>"
    echo 
    "<form action='/script_update.php'>";
    echo 
    "Need to <input type='submit' name='$script_id'; id='update' value='update'> your script?";
    echo 
    "</form>";
    echo 
    "<br />";

    }else echo 
    "Script <strong>"$GLOBALS['row']['script_name'] ."</strong> is waiting to be approved. Check again soon.<br />";
    }
    }else echo 
    "You have not submitted a script."
    example:

    Row 1

    Approved Scripts
    Date Submitted: 2010-06-27
    Email Address: -----
    Name of Script: MY Script
    Category: 1
    License: Free
    Price: $0.00
    Name of Website: MY Script
    Link Download Url: http://MYscript.com
    Description: This is a test. Does it work. Yes It does

    SUBMIT BUTTON

    Row 2

    Approved Scripts
    Date Submitted: 2010-06-27
    Email Address: -----
    Name of Script: Your Script
    Category: 1
    License: Free
    Price: $0.00
    Name of Website: Your Script
    Link Download Url: http://Yourscript.com
    Description: This is a test. Does it work. Yes It does

    SUBMIT BUTTON

    shows the info in the textboxs which they can change the info and submit it

    PHP Code:
    $connection = @mysql_connect($server$dbusername$dbpassword) or die(mysql_error());
    $db = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $db1 = @mysql_select_db($db_name,$connection)or die(mysql_error());
    $result = @mysql_query("SELECT username, memberid FROM authorize WHERE username = '".$_SESSION['username']."' AND memberid = '".$_SESSION['memberid']."'"$db1);

     
    $memberid $_SESSION['memberid'];

    $sql ="SELECT * FROM user_scripts WHERE memberid = '".$_SESSION['memberid']."' LIMIT 1";
    $result = @mysql_query($sql,$connection) or die(mysql_error());
    if(
    mysql_num_rows($result)){

    while (
    $row mysql_fetch_array($result)) {

    if ((
    $row['memberid'] = "$memberid") && ($row['is_approved'] == "1")) {

    Echo 
    "<form action='script_updated.php' method='post' name='updated' id='updated'>";
    Echo 
    "Please make your changes and click the update button. Your script will need to be reapproved.";
    Echo 
    "<table border=0>";
    Echo 
    "<tr><td>Date Submitted: </td>"
    Echo 
    "<td>" $GLOBALS['row']['dated'] . "</td></tr>";
    Echo 
    "<tr><td>Email Address: </td>"
    Echo 
    "<td><input type='text' size='60' name='email_contact' id='email_contact' value='"$GLOBALS['row']['email_contact'] ."'></td></tr>";
    Echo 
    "<tr><td>Name of Script: </td>"
    Echo 
    "<td><input size=60 value='"$GLOBALS['row']['script_name'] ."' id='script_name' name='script_name'></td></tr>";


    Echo 
    "<tr><td>Category: </td>"

    this is just a dropdown menu

    Echo "<tr><td>License: </td>"
    Echo 
    "<td><SELECT name='license' id='license'>";
    Echo 
    "<OPTION selected>"$GLOBALS['row']['license'] ."</OPTION>";
       Echo 
    "<OPTION>Free</OPTION>";
       Echo 
    "<OPTION>GPL</OPTION>";
       Echo 
    "<OPTION>Commercial</OPTION>";
    Echo 
    "</SELECT></td></tr>";
    Echo 
    "<tr><td>Price: </td>"
    Echo 
    "<td><input type='text' size='25' name='price' id='price' value='"$GLOBALS['row']['price'] ."'></td></tr>";
    Echo 
    "<tr><td>Name Of Website: </td>"
    Echo 
    "<td><input type='text' size='60' name='download_site' id='download_site' value='"$GLOBALS['row']['download_site'] ."'></td></tr>";
    Echo 
    "<tr><td>Link Download Url: </td>"
    Echo 
    "<td><input type='text' size='60' name='site_url' id='site_url' value='"$GLOBALS['row']['site_url'] ."'></td></tr>"
    Echo 
    "<tr><td>Description: </td>"
    Echo 
    "<td><textarea cols='60' rows='15' name='description' id='description' value=''>"$GLOBALS['row']['description'] ."</textarea>";
    echo 
    "</td></tr>";
    Echo 
    "</table>";
    echo 
    "<input type='submit' name='updated' id='updated' value='Click Here To Update'>";
    echo 
    "</form>";

    }else echo 
    "Script <strong>"$GLOBALS['row']['script_name'] ."</strong> is waiting to be approved. Check again soon.";
    }
    }else echo 
    "Your script could not be updated. Please contact us or try again later."
    Last edited by twobyfour; 06-28-2010 at 08:11 AM.

  • #12
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Select the row id, and add a hidden input with the row id... update the row id instead of searching for the memberid.

  • #13
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    can you give me an example please, i think i tried everything, it just goes through and tells me "You have not submitted a script"

  • #14
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    Thanked 259 Times in 256 Posts
    PHP Code:
    <input type="hidden" name="rowid" value="<?php echo $rowid?>">
    Just get the row id from your db pull.

  • #15
    Regular Coder
    Join Date
    May 2010
    Posts
    146
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Keleth View Post
    PHP Code:
    <input type="hidden" name="rowid" value="<?php echo $rowid?>">
    Just get the row id from your db pull.
    i am already echoing the submit button so can i do this

    PHP Code:
    <input type='hidden' name='rowid' value='<?php echo $rowid?>'>
    and does it go with the form tag
    Last edited by twobyfour; 06-28-2010 at 08:46 AM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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