ethan6 Posted July 29, 2009 Share Posted July 29, 2009 Hi, I'm having problem with updating the SQL database from php and html form. I know it's a bit of code, but if you have any suggestions, I'd be so very grateful, I'm funning out of ideas.. (ps. I know that it doesn't correctly insert values into the html form either, and i'd like to fix that too, but i just need to find out first how to make the update work.) <form action="ADMIN-database-updates.php" method="post"> <table><tr><td width="250"> <b>User Info:</b><br> First Name:<br> <input type="text" name="fname" value="<? echo $row['fname'] ?>" maxlength="40" size="25"><br> Last Name:<br> <input type="text" name="lname" value="<? echo $row['lname'] ?>" maxlength="40" size="25"><br> <b>Address:</b><br> Address1:<br> <input type="text" name="address1" value="<? echo $row['address1'] ?>" maxlength="40" size="25"><br> Address2:<br> <input type="text" name="address2" value="<? echo $row['address2'] ?>" maxlength="40" size="25"><br> City:<br> <input type="text" name="city" value="<? echo $row['city'] ?>" maxlength="40" size="25"><br> State:<br> <input type="text" name="state" value="<? echo $row['state'] ?>" maxlength="40" size="25"><br> Zip:<br> <input type="text" name="zip" value="<? echo $row['zip'] ?>" maxlength="40" size="25"><br> <b>Contact Info:</b><br> Email:<br> <input type="text" name="sendemail" value="<? echo $row['sendemail'] ?>" maxlength="40" size="25"><br> Phone:<br> <input type="text" name="phone" value="<? echo $row['phone'] ?>" maxlength="40" size="25"><br> <b>Other User Info:</b><br> Reference:<br> <input type="text" name="refer" value="<? echo $row['refer'] ?>" maxlength="40" size="25"><br> Reference Other:<br> <input type="text" name="refer2" value="<? echo $row['refer2'] ?>" maxlength="40" size="25"><br> Generation:<br> <input type="text" name="generation" value="<? echo $row['generation'] ?>" maxlength="40" size="25"><br> Promo Code:<br> <input type="text" name="promo" value="<? echo $row['promo'] ?>" maxlength="40" size="25"><br> Problems:<br> <textarea name="problems" readonly="readonly" rows="5" cols="25"><? echo $row['problems'] ?></textarea><br> </td> <td width="20"></td> <td width="250"> <b>Record Info:</b><br> iPod Received On:<br> <input type="text" name="received" value="<? echo $row['received'] ?>" maxlength="40" size="25"><br> Return Shipping Paid?<br> <input type="text" name="shipping" value="<? echo $row['shipping'] ?>" maxlength="40" size="25"><br> iPod Returned On:<br> <input type="text" name="returned" value="<? echo $row['returned'] ?>" maxlength="40" size="25"><br> <b>iPod Info:</b><br> Type:<br> <input type="text" name="ipod-type" value="<? echo $row['ipod-type'] ?>" maxlength="40" size="25"><br> Generation:<br> <input type="text" name="ipod-gen" value="<? echo $row['ipod-gen'] ?>" maxlength="40" size="25"><br> HD:<br> <input type="text" name="ipod-hd" value="<? echo $row['ipod-hd'] ?>" maxlength="40" size="25"><br> Color:<br> <input type="text" name="ipod-color" value="<? echo $row['ipod-color'] ?>" maxlength="40" size="25"><br> S/N:<br> <input type="text" name="ipod-sn" value="<? echo $row['ipod-sn'] ?>" maxlength="40" size="25"><br> Condition:<br> <input type="text" name="ipod-condition" value="<? echo $row['ipod-condition'] ?>" maxlength="40" size="25"><br> Other Descriptions:<br> <input type="text" name="ipod-other" value="<? echo $row['ipod-other'] ?>" maxlength="40" size="25"><br> Accessories etc. included?<br> <input type="text" name="ipod-included" value="<? echo $row['ipod-included'] ?>" maxlength="40" size="25"><br> <b>Diagnosis:</b><br> <textarea name="diagnosis" rows="5" cols="25"><? echo $row['diagnosis'] ?></textarea><br> <b>Other Notes:</b><br> <textarea name="notes" rows="5" cols="25"><? echo $row['notes'] ?></textarea><br> </td></tr></table> <input type="hidden" name="searchid" value="<?php echo $_POST['searchid']; ?>"> <input type="hidden" name="ud" value="true"> <input type="submit" value="Update Database"> </form> <?php $searchid = $_POST['searchid']; $username = "username"; $password = "password"; $hostname = "localhost"; $database = "myipodbr_ipodusers"; $con = mysql_connect($hostname, $username, $password) or die("Unable to connect to database."); mysql_select_db($database, $con) or die("Could not select myipodbr_ipodusers"); echo $_POST['searchid']; echo $_POST['ud']; echo $_POST['ipod-type']; if ($_POST['ud'] == "true") { $query = "UPDATE ipodusers SET fname='".$_POST['fname']."', lname='".$_POST['lname']."', address1='".$_POST['address1']."', address2='".$_POST['address2']."', city='".$_POST['city']."', state='".$_POST['state']."', zip='".$_POST['zip']."', sendemail='".$_POST['sendemail']."', phone='".$_POST['phone']."', refer='".$_POST['refer']."', refer2='".$_POST['refer2']."', generation='".$_POST['generation']."', promo='".$_POST['promo']."', problems='".$_POST['problems']."', received='".$_POST['received']."', shipping='".$_POST['shipping']."', returned='".$_POST['returned']."', ipod-type='".$_POST['ipod-type']."', ipod-gen='".$_POST['ipod-gen']."', ipod-hd='".$_POST['ipod-hd']."', ipod-color='".$_POST['ipod-color']."', ipod-sn='".$_POST['ipod-sn']."', ipod-condition='".$_POST['ipod-condition']."', ipod-other='".$_POST['ipod-other']."', ipod-included='".$_POST['ipod-included']."', diagnosis='".$_POST['diagnosis']."', notes='".$_POST['notes']."', repair1='".$_POST['repair1']."', repair2='".$_POST['repair2']."', repair3='".$_POST['repair3']."', cost1='".$_POST['cost1']."', cost2='".$_POST['cost2']."', cost3='".$_POST['cost3']."' WHERE id='".$_POST['searchid']."'"; mysql_query($query,$con); } $query="SELECT * FROM ipodusers WHERE id='$searchid'"; $result=mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { echo "<b>{$row['id']}</b><br> <b>{$row['fname']} {$row['lname']}</b><br><br> <u>Address:</u><br> {$row['address1']}<br>"; if ($row['address2'] != '') { echo "{$row['address2']}<br>"; } echo "{$row['city']}, {$row['state']} {$row['zip']}<br><br> <u>Contact Info:</u><br> Email: {$row['sendemail']}<br> Phone: {$row['phone']}<br><br> <u>Other User Info:</u><br> Reference: {$row['refer']}<br> Ref Other: {$row['refer2']}<br> Generation: {$row['generation']}<br> Promo Code: {$row['promo']}<br> Problems: {$row['problems']}<br><br> <hr> <u>Record Info:</u><br> iPod Received On: {$row['received']}<br> Return Shipping Paid? {$row['shipping']}<br> iPod Returned On: {$row['returned']}<br> <br> <u>iPod Info:</u><br> iPod Type: {$row['ipod-type']}<br> iPod Generation: {$row['ipod-gen']}<br> iPod HD: {$row['ipod-hd']}<br> iPod Color: {$row['ipod-color']}<br> iPod S/N: {$row['ipod-sn']}<br> iPod Condition: {$row['ipod-condition']}<br> iPod Other Descriptions: {$row['ipod-other']}<br> iPod Accessories etc. Included? {$row['ipod-included']}<br><br> <u>Diagnosis:</u><br> {$row['diagnosis']}<br><br> <u>Other Notes:</u><br> {$row['notes']}<br><br> <u>Repair/Costs:</u><br> Repair1: {$row['repair1']}<br> Repair2: {$row['repair2']}<br> Repair3: {$row['repair3']}<br> Cost1: {$row['cost1']}<br> Cost2: {$row['cost2']}<br> Cost3: {$row['cost3']}<br> "; } mysql_close($con); ?> THANKS! Quote Link to comment https://forums.phpfreaks.com/topic/168044-solved-updating-database-wont-update/ Share on other sites More sharing options...
BLaZuRE Posted July 30, 2009 Share Posted July 30, 2009 What exactly IS your problem? Is everything not updating, is something updating? Are you getting any errors? What troubleshooting have you tried? Have you tried a simple query to see if it works, or even connected? You have a lot of code yet you're not really helping us help you. Also, I'm assuming the form is on the same page as the result page (the form is on ADMIN-db-updates.php and so is the page you want it to go to after it posts the data, just that it prints stuff below the form too). If not, that's probably your problem. post and get variables are transferred when you press the Submit button TO the page you're going to. Have you tried using print_r to print your array after your mysql query, to see its contents? Quote Link to comment https://forums.phpfreaks.com/topic/168044-solved-updating-database-wont-update/#findComment-886508 Share on other sites More sharing options...
ethan6 Posted July 30, 2009 Author Share Posted July 30, 2009 hi, yes sorry.. the form and database access are all on same page. i cut everything down to just the variable fname, and it worked fine, so i'm thinking it's something with just one of the variables, i just don't know what. Quote Link to comment https://forums.phpfreaks.com/topic/168044-solved-updating-database-wont-update/#findComment-886564 Share on other sites More sharing options...
BLaZuRE Posted July 30, 2009 Share Posted July 30, 2009 It could be possible that PHP is incorrectly inputting variables when they're not set/empty, possibly trashing your query. You could try doing isset() for your variables. You could also try rebuilding your page 2 lines at a time (one line HTML with its corresponding query line) and seeing where it stops working. Quote Link to comment https://forums.phpfreaks.com/topic/168044-solved-updating-database-wont-update/#findComment-886573 Share on other sites More sharing options...
ethan6 Posted July 30, 2009 Author Share Posted July 30, 2009 hey thanks for the help.. i figured out what was wrong (for some reason, it didn't like variable names with dashes(-) so i just got rid of them.. changed ipod-type to ipodtype, and now it works thanks again Quote Link to comment https://forums.phpfreaks.com/topic/168044-solved-updating-database-wont-update/#findComment-886596 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.