...

View Full Version : update row help



twobyfour
06-28-2010, 04:27 AM
this displays all info based on the members id


$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


$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.

rfresh
06-28-2010, 04:38 AM
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.

twobyfour
06-28-2010, 04:53 AM
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.

Keleth
06-28-2010, 05:23 AM
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.

twobyfour
06-28-2010, 05:39 AM
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.

Keleth
06-28-2010, 05:48 AM
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?

twobyfour
06-28-2010, 05:58 AM
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.

Keleth
06-28-2010, 06:04 AM
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.

twobyfour
06-28-2010, 06:17 AM
i see what your saying and it makes since ofcourse, when a user logs in, the memberid is tied to there username


$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


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

Keleth
06-28-2010, 06:38 AM
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.

twobyfour
06-28-2010, 06:47 AM
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


$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


$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.";

Keleth
06-28-2010, 07:19 AM
Select the row id, and add a hidden input with the row id... update the row id instead of searching for the memberid.

twobyfour
06-28-2010, 07:22 AM
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"

Keleth
06-28-2010, 07:25 AM
<input type="hidden" name="rowid" value="<?php echo $rowid; ?>">

Just get the row id from your db pull.

twobyfour
06-28-2010, 07:30 AM
<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


<input type='hidden' name='rowid' value='<?php echo $rowid; ?>'>

and does it go with the form tag

Keleth
06-28-2010, 07:36 AM
Yah, its the same thing.

twobyfour
06-28-2010, 07:51 AM
Yah, its the same thing.


echo "<input type='hidden' name='script_id' value='<?php echo $script_id; ?>'>";
echo "Need to <input type='submit' value='Update'> your script?";
it doesnt work, button still doesnt know which id to update

ok, i got the url to show ?script_id=3&script_id=Update but it doesnt show the correct row id info

Keleth
06-28-2010, 04:12 PM
Uh.... you don't need a <?php inside of a <?php... when I said its the same thing, I meant either method, w/e you wanted to do...

twobyfour
06-28-2010, 05:02 PM
I tryed with only '$script_id' and it didn't work.

I am recoding to look for the scipt id first and then memberid which I am stuck on

this is what i have so far


$sql ="SELECT * FROM user_scripts WHERE script_id ='{$script_id}' AND memberid = '".$_SESSION['memberid']."' AND is_approved =

1";

but it doesnt work. i am trying to search for script_id first, that i can use


"<input type='hidden' name='script_id' value='$script_id'>"

in the button.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum