Jump to content

Query Wont Update :(


jjmusicpro

Recommended Posts

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.