jack_wetson Posted February 11, 2008 Share Posted February 11, 2008 This may sound like a totally 'noobish' question, but hey i only started php and mysql today, is it possible to pull data from a table and put it in a form to be editied and post it back to the server??? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 11, 2008 Share Posted February 11, 2008 Yes it is. We could supply you all the code, but then you wouldn't learn anything and you would just have even more questions. So I suggest you go to one of the following websites and start reading the tutorials: www.tizag.com www.w3schools.com Quote Link to comment Share on other sites More sharing options...
jack_wetson Posted February 13, 2008 Author Share Posted February 13, 2008 yes i have tried with tutorials but consistantly get error messages, and cannot see anything wrong with the code Quote Link to comment Share on other sites More sharing options...
jack_wetson Posted February 13, 2008 Author Share Posted February 13, 2008 this is my code if anyone can help <html> <head><title>Test</title></head> <body> <?php $link = mysql_pconnect("localhost","silersi_admin",""); $db = mysql_select_db("ebay"); //determine what to do depending on the ?action= string in the url caused by the post in the form switch($_GET['action']) { case "save": Save(); break; //removing the break would allow the form to reload the modified data for further edit if necessary default: loadForm($_POST['id']); break; } function loadForm($record_id) { //might need adjustment $sql = "SELECT `transID`, `ebayID`, `itemID`, `itemDes`, `email`, `Telephone`, `Status` FROM `ebay` WHERE `transID` = '"$record_id."'"; $result = mysql_query($sql) or die("sql error"); $row = mysql_fetch_array($result); $strHTML = "<form method="post" action="".$PHP_SELF."?action=save">n" ."Item Description: <input type="text" name="desc" id="desc" value="".$row['itemDes']."" /><br />n" ."Status: <input type="text" name="status" id="status" value="".$row['Status']."" /><br />n" ."<input type="hidden" name="record_id" id="record_id" value="".$record_id."" />n" ."<input type="submit" value="Save" />n" ."</form>n"; /*this is just somethign i do out of habit, since sometimes you end up with many echo, instead I build a string and echo it all at once*/ echo $strHTML; } function Save() { $sql = "UPDATE `silversi_orders` SET `itemDes`='".$_POST['desc']."', `Status`='".$_POST['status']."' " "WHERE `transID`='".$_POST['record_id']."'"; mysql_query($sql) or die("Couldn't save data"); } ?> </body></html> Quote Link to comment Share on other sites More sharing options...
aschk Posted February 13, 2008 Share Posted February 13, 2008 Post the error message too please. Taking a quick glance this line looks wrong: $strHTML = "<form method="post" action="".$PHP_SELF."?action=save">n" It should be $strHTML = "<form method="post" action=\"".$PHP_SELF."?action=save\">n" Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 13, 2008 Share Posted February 13, 2008 Post the error message too please. Taking a quick glance this line looks wrong: $strHTML = "<form method="post" action="".$PHP_SELF."?action=save">n" It should be $strHTML = "<form method="post" action=\"".$PHP_SELF."?action=save\">n" Thats still going to return an error, it should be this: <?php $strHTML = "<form method='post' action='".$PHP_SELF."?action=save'>n" ."Item Description: <input type='text' name='desc' id='desc' value='".$row['itemDes']."' /><br />n" ."Status: <input type='text' name='status' id='status' value='".$row['Status']."' /><br />n" ."<input type='hidden' name='record_id' id='record_id' value='".$record_id."' />n" ."<input type='submit' value='Save' />n" ."</form>n"; ?> Quote Link to comment Share on other sites More sharing options...
Xeoncross Posted February 13, 2008 Share Posted February 13, 2008 Thats still going to return an error, it should be this: <?php $strHTML = "<form method='post' action='".$PHP_SELF."?action=save'>n" ."Item Description: <input type='text' name='desc' id='desc' value='".$row['itemDes']."' /><br />n" ."Status: <input type='text' name='status' id='status' value='".$row['Status']."' /><br />n" ."<input type='hidden' name='record_id' id='record_id' value='".$record_id."' />n" ."<input type='submit' value='Save' />n" ."</form>n"; ?> That is wrong too NEVER, EVER, EVER, use double quotes when working with values that DON'T have to be evaluated - It wastes way too much CPU time. <?php $strHTML = '<form method="post" action="'. $PHP_SELF .'?action=save">'. "\n". .'Item Description: <input type="text" name="desc" id="desc" value="'. $row["itemDes"]. '" /><br />'. "\n". .'Status: <input type="text" name="status" id="status" value="'. $row["Status"]. '" /><br />'. "\n". .'<input type="hidden" name="record_id" id="record_id" value="'. $record_id. '" />'. "\n". .'<input type="submit" value="Save" />'. "\n". .'</form>'. "\n"; ?> Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 13, 2008 Share Posted February 13, 2008 NEVER, EVER, EVER, use double quotes when working with values that DON'T have to be evaluated - It wastes way too much CPU time. Not enough to even matter or notice, so it really doesn't matter. Quote Link to comment Share on other sites More sharing options...
Xeoncross Posted February 14, 2008 Share Posted February 14, 2008 You should really do some research before you speak. You didn't specify "concatenation" or "putting variables within double quotes" so just saying what you said will confuse newbies into thinking there is no difference. 100,000 literation's of a string: (variables in quotes) Double: 0.234696 Time Single: 0.035352 Time (concatenation) Double: 0.238109 Time Single: 0.227169 Time Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted February 14, 2008 Share Posted February 14, 2008 100,000 literation's of a string Exactly, it takes 100,000 iterations for that small change in time. That would be one large program, but yes, if you are making a program that big then using single quotes wouldn't be a bad idea. Otherwise if you have a relatively small script it really isn't a big deal. Quote Link to comment Share on other sites More sharing options...
jack_wetson Posted February 15, 2008 Author Share Posted February 15, 2008 right this is what i have now got id.php5 <? // Connect database. $host="localhost"; // Host name. $db_user="silversi_admin"; // MySQL username. $db_password=""; // MySQL password. $database="silversi_orders"; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); // Select all data records in table "name_list" and put them into $result. $result=mysql_query("select * from ebay order by transID asc"); ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="update.php5"> <table border="1" cellpadding="3" cellspacing="0"> <tr> <td align="center" bgcolor="#FFCC00"><strong>TransID</strong></td> <td align="center" bgcolor="#FFCC00"><strong>EbayID</strong></td> <td align="center" bgcolor="#FFCC00"><strong>ItemID</strong></td> <td align="center" bgcolor="#FFCC00"><strong>ItemDes</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Email</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Telephone</strong></td> <td align="center" bgcolor="#FFCC00"><strong>Status</strong></td> </tr> <? // Fetch record rows in $result by while loop and put them into $row. while($row=mysql_fetch_assoc($result)){ ?> <tr> <td bgcolor="#FFFFCC"><? echo $row['transID']; // Show record's ID ?></td> <td bgcolor="#FFFFCC"><input name="name_<? echo $row['transID']; ?>" type="text" id="name_<? echo $row['transID']; ?>" value="<? echo $row['ebayID']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="name_<? echo $row['transID']; ?>" type="text" id="name_<? echo $row['transID']; ?>" value="<? echo $row['itemID']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="name_<? echo $row['transID']; ?>" type="text" id="name_<? echo $row['transID']; ?>" value="<? echo $row['itemDes']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="name_<? echo $row['transID']; ?>" type="text" id="name_<? echo $row['transID']; ?>" value="<? echo $row['email']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="name_<? echo $row['transID']; ?>" type="text" id="name_<? echo $row['transID']; ?>" value="<? echo $row['Telephone']; ?>" /></td> <td bgcolor="#FFFFCC"><input name="name_<? echo $row['transID']; ?>" type="text" id="name_<? echo $row['transID']; ?>" value="<? echo $row['Status']; ?>" /></td> </tr> <? } // End while loop. ?> </table> <input type="submit" name="Submit" value="Update" /> </form> </body> </html> update.php5 <? if($_POST['Submit']){ // If receive Submit button variable. // Connect database. $host="localhost"; // Host name. $db_user="silversi_admin"; // MySQL username. $db_password=""; // MySQL password. $database="silversi_orders"; // Database name. mysql_connect($host,$db_user,$db_password); mysql_select_db($database); // Select all data records in table "name_list" and put them into $result. $result=mysql_query("select transid from ebay order by transID asc"); // Fetch record rows in $result by while loop and put them into $row. while($row=mysql_fetch_assoc($result)){ // Get the posted value "name_ID value" from form.php5. This variable change it's value by while loop. $name=$_POST["name_".$row[transID]]; // Update field "name", matching with "id" value by while loop. mysql_query("update name_list set name='$name' where id='$row[transID]'"); } echo "--- Update Complete ---"; } ?> yet it does not update the data, if anyone can help please e-mail me at jack_wetson@hotmail.co.uk, as this site is banned at work, (filters) Quote Link to comment 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.