Jump to content

Recommended Posts

With the following code:

 

$qryTotal=mysql_query("SELECT * FROM admin WHERE dataID='911' AND RRP=dataP ORDER BY brand,name")or
die(mysql_error());
$numrow=mysql_num_rows($qryTotal);

while($row = mysql_fetch_array( $qryTotal )) {

print $row[sku]." ".$row[brand]." ".$row[name]." <a href='".$row[dataLink]."'>Link</a><input type='text' name='updateRRP' maxlength='30' value=''><input name='updateRRP' type='submit' value='Submit' /><br />";

}code]

how can i update the RRP in database with whatever it is that i enter into the input box and submit. Does it require an entirely new script or "process" script or can it all be done in this script?

So much thanks for the help.

xxx  

That script it meant to retrieve info from your database. You need to write a script to get the info from the form and put it into the database.  Getting info from a form and putting it into a database is a very common beginner tutorial. 

I understand that is a retieval script. The reason for that is that there is only certain data entries I need to update with the input box, so that's why I'm looking to find out how to do this within the retieval script.

 

I have googled "updating mysql from input box" but cannot find anything that's relevant, WELL - simple enough to understand for me. lol

 

Any help would be apreciated, really.

$qryTotal=mysql_query("SELECT * FROM admin WHERE dataID='911' AND RRP=dataP ORDER BY brand,name")or
die(mysql_error());
$numrow=mysql_num_rows($qryTotal);

while($row = mysql_fetch_array( $qryTotal )) {

print $row[sku]." ".$row[brand]." ".$row[name]." <a href='".$row[dataLink]."'>Link</a><input type='text' name='updateRRP' maxlength='30' value=''><input name='updateRRP' type='submit' value='Submit' /><br />";

}

 

So sorry, you try to modify an entry and end up quoting it. grr!

I understand that is a retieval script. The reason for that is that there is only certain data entries I need to update with the input box, so that's why I'm looking to find out how to do this within the retieval script.

 

I have googled "updating mysql from input box" but cannot find anything that's relevant, WELL - simple enough to understand for me. lol

 

Any help would be apreciated, really.

 

it doesn't matter whether you it's one column in one row or 100 columns in 100 rows, the command for retrieving something is different from the one for updating, so you can't use that query string to update it.  Furthermore, the actual script takes the retrieved data and dumps it out. Since your goal is to put stuff in and not take it out (and then do something with it), the only code in that entire block you provided that's any kind of useful is...nothing.

 

$sql = "update tablename set column = '$somevar' where someothercolumn = '$someothervar'"
$result = mysql_query($sql);

 

that's a generic update script. 

 

well how about this...

 

$qryTotal=mysql_query("SELECT * FROM admin WHERE dataID='911' AND inStock='yes' AND RRP=dataP ORDER BY brand,name")or
die(mysql_error());
$numrow=mysql_num_rows($qryTotal);

while($row = mysql_fetch_array( $qryTotal )) {

echo '<form method="post">';
echo $row[sku]." ".$row[brand]." ".$row[name]." <a href='".$row[dataLink]."' target='_new'>Link</a>";
echo '<input name="RRP">';
echo '<input type="submit">';
echo '</form>';

$dataLink=$row[dataLink];
$sku=$row[sku];

mysql_query("UPDATE admin SET RRP_test = '$_POST[RRP]' WHERE dataLink='$dataLink' AND sku='$sku'");

}

 

the only outstanding issue now being that while it does insert the info into the database, it does so for all rows in the query. is this linked to what you were saying or can it be corrected. i've written a hundred similar scripts for updating within loops and it's been fine but this one is acting funny...

 

any ideas?

If ALL you are wanting to do is update the table, you do not need all that other script whatsoever.  The most immediate thing I see is that your update query is inside that loop so it keeps being executed with new conditions because the variables keep changing with each iteration of the loop.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.