jjmusicpro Posted October 3, 2007 Share Posted October 3, 2007 I try to run an update after i post the data, but for some reason, the data wont update, it stays the same. any ideas? <?php if($_SERVER['REQUEST_METHOD'] == "POST"){ require_once ('connect.php'); require_once ('opendb.php'); $groupid_sent = $_GET['actname']; $query = "SELECT * FROM zipcodes WHERE account_name='$groupid_sent' group by account_name"; $result = @mysql_query ($query); $count = mysql_num_rows($result); //number of results while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $groupid_sent= $row['account_name'] ; $account_name= $row['company_name'] ; $zip_id = $row['search_id'] ; } }else{ require_once ('connect.php'); require_once ('opendb.php'); $groupid_sent = $_GET['groupid']; $query = "SELECT * FROM zipcodes WHERE account_name='$groupid_sent' group by account_name"; $result = @mysql_query ($query); $count = mysql_num_rows($result); //number of results while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $groupid_sent= $row['account_name'] ; $account_name= $row['company_name'] ; $zip_id = $row['search_id'] ; }}?> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>TEST EDITOR</title> </head> <body> <?php echo "<h3>$groupid_sent - $account_name </h3>"; ?> <fieldset> <a href="index.php">Home</a> || <a href="editaccount.php?groupid=<?php echo $groupid_sent; ?>">Account</a> || <a href="viewzips.php?groupid=<?php echo $groupid_sent; ?>">Active Zips</a> - <a href="pausedzips.php?groupid=<?php echo $groupid_sent; ?>">Paused Zips</a> || <a href="pause.php?groupid=<?php echo $groupid_sent; ?>">Pause Account</a> || <a href="testzips.php?groupid=<?php echo $groupid_sent; ?>">Test Zips</a> </fieldset> <p> <?php if (isset($_POST['submit'])) { //define all your post variables here $phone_number = mysql_real_escape_string($_POST['phonenumber1']); $redirect_url = mysql_real_escape_string($_POST['redirecturl1']); $account_name = mysql_real_escape_string($_POST['groupid_sent']); //Run Update Function $query = "UPDATE zipcodes SET redirect_url='$redirect_url', phone_number='$phone_number', account_name='$account_name' WHERE account_name='$account_name'"; $result = mysql_query($query)or die(mysql_error()); // Confirmation that updated worked echo "Client Updated Successfully Updated <br> phonenumber $phone_number <br> group name $account_name<br> accountname $groupid_sent <br> Redirect URL $redirect_url "; } else { require_once('connect.php'); require_once('opendb.php'); $groupid_sent = $_GET['groupid']; $query = "SELECT * FROM zipcodes WHERE search_id='$zip_id'"; $result = @mysql_query($query); $count = mysql_num_rows($result); //number of results while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // Database Values $groupid_sent= $row['account_name'] ; $account_name= $row['company_name'] ; $zip_id = $row['search_id'] ; $zipcode = $row['zipcode']; $city = $row['city']; $rank = $row['rank']; $redirect_url = $row['redirect_url']; $notes_1 = $row['notes_1']; $phone_number = $row['phone_number']; $groupe_name = $row['groupe_name']; $on_off = $row['on_off']; $test_zip = $row['test_zip']; echo "<form action='editaccount.php?actname=$groupid_sent' method='post'>"; echo "<input type=hidden name=zipid1 value='$zip_id>"; // Hidden Field echo "<input type=hidden name=groupid value='$groupid_sent'>"; // Hidden Field echo "Account Name: $groupid_sent <br>"; echo "Company Name: <input type=text name=company_name1 size=75 value='$account_name' > <br>"; echo "Redirect URL: <input type=text name=redirecturl1 size=75 value='$redirect_url' > <br>"; echo "Phone Number: <input type=text name=phonenumber1 value='$phone_number' ><br>"; echo "Group Name: <input type=text name=groupname1 value='$groupe_name' ><br>"; echo "<input type=submit name=submit value=update>"; echo "</form>"; } } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/71691-query-wont-update/ Share on other sites More sharing options...
shocker-z Posted October 3, 2007 Share Posted October 3, 2007 your updating account name as well as searching for it that could be an issue as if you change account name then it cant change it as it's searching for the new account name not the old one. $query = "UPDATE zipcodes SET redirect_url='$redirect_url', phone_number='$phone_number' WHERE account_name='$account_name'"; try that without updating account name.. hope that made sence, you should really be updating based on a primary/unique key Liam Quote Link to comment https://forums.phpfreaks.com/topic/71691-query-wont-update/#findComment-360902 Share on other sites More sharing options...
jjmusicpro Posted October 3, 2007 Author Share Posted October 3, 2007 well right now, i have a database of zipcodes, and each zipcode has a account_name field added in, so each zip might have the same account name listed in the database 20 times or so. my table is setup like this search_id zipcode redirect_url phone_number account_name etc.... so an example of data might be 1,98888,someplace.com,555-555-5555,my_account 2,98777,someplace2.com,555-555-5555,my_account 3,411411,somplace3.com,444-444-4444,my_account2 i wanted to be able to make the page display there account details, then hit "update" and it will update the database with the whats entered into the fields. but update all zipcodes that have the same account_name, that way it changes allt he phone numbers, redirect urls etc. maybe i am doing this wrong lol thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/71691-query-wont-update/#findComment-360914 Share on other sites More sharing options...
shocker-z Posted October 3, 2007 Share Posted October 3, 2007 have you tried the query i posted? I get what your doing, i didnt read your whole code, if i did i would have realised.. Quote Link to comment https://forums.phpfreaks.com/topic/71691-query-wont-update/#findComment-360916 Share on other sites More sharing options...
jjmusicpro Posted October 3, 2007 Author Share Posted October 3, 2007 Yes, i ran it but still nothing updates in DB. Quote Link to comment https://forums.phpfreaks.com/topic/71691-query-wont-update/#findComment-360922 Share on other sites More sharing options...
jjmusicpro Posted October 3, 2007 Author Share Posted October 3, 2007 I echo out all the values after the query to double check, and it looks ok,but not working Client Updated Successfully Updated phonenumber 2222-2222-2222 group name accountname my_test_account Redirect URL REDDDDDDD Quote Link to comment https://forums.phpfreaks.com/topic/71691-query-wont-update/#findComment-360924 Share on other sites More sharing options...
jjmusicpro Posted October 3, 2007 Author Share Posted October 3, 2007 anyone :'( Quote Link to comment https://forums.phpfreaks.com/topic/71691-query-wont-update/#findComment-360955 Share on other sites More sharing options...
jjmusicpro Posted October 3, 2007 Author Share Posted October 3, 2007 ? Quote Link to comment https://forums.phpfreaks.com/topic/71691-query-wont-update/#findComment-361088 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.