e1seix Posted May 31, 2008 Share Posted May 31, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/108075-how-would-i-add-this-input-box-to-update-mysql/ Share on other sites More sharing options...
.josh Posted May 31, 2008 Share Posted May 31, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/108075-how-would-i-add-this-input-box-to-update-mysql/#findComment-553939 Share on other sites More sharing options...
e1seix Posted May 31, 2008 Author Share Posted May 31, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/108075-how-would-i-add-this-input-box-to-update-mysql/#findComment-553943 Share on other sites More sharing options...
e1seix Posted May 31, 2008 Author Share Posted May 31, 2008 $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! Quote Link to comment https://forums.phpfreaks.com/topic/108075-how-would-i-add-this-input-box-to-update-mysql/#findComment-553952 Share on other sites More sharing options...
.josh Posted May 31, 2008 Share Posted May 31, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/108075-how-would-i-add-this-input-box-to-update-mysql/#findComment-553959 Share on other sites More sharing options...
e1seix Posted May 31, 2008 Author Share Posted May 31, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/108075-how-would-i-add-this-input-box-to-update-mysql/#findComment-553967 Share on other sites More sharing options...
.josh Posted May 31, 2008 Share Posted May 31, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/108075-how-would-i-add-this-input-box-to-update-mysql/#findComment-553970 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.