Page 1 of 1

updating db with blank records?

Posted: Tue Nov 23, 2004 2:15 am
by C_Calav
hi guys,

can anyone see anything wrong with this code?

when i update, it updates everything with blank records.

i have used a pretty much simmilar script for updating stock and it works fine.

thanx guys.

Code: Select all

<?php
    $db = mysql_pconnect('**', '**', '**') or die ("Could not connect to database");

    mysql_select_db('models') or die ("Could not select database!"); 

    if ($_SERVER['REQUEST_METHOD'] == "POST") 
    {

	$ud_C_First = stripslashes($_POST["ud_C_First"]);
	$ud_C_Last = stripslashes($_POST["ud_C_Last"]);
 	$ud_C_Email = stripslashes($_POST["ud_C_Email"]);		
	$ud_C_Phone = stripslashes($_POST["ud_C_Phone"]);
	$ud_C_Address1 = stripslashes($_POST["ud_C_Address1"]);	
	$ud_C_Address2 = stripslashes($_POST["ud_C_Address2"]);
	$ud_C_City = stripslashes($_POST["ud_C_City"]);
	$ud_C_Country = stripslashes($_POST["ud_C_Country"]);
	

	$query = "UPDATE customer SET C_First='$ud_C_First',C_Last='$ud_C_Last',C_Email='$ud_C_Email',C_Phone='$ud_C_Phone',C_Address1='$ud_C_Address1',C_Address2='$ud_C_Address2',C_Country='$ud_C_Country',C_City='$ud_C_City' WHERE C_ID='$C_ID'";

        #execute SQL statement
	$result = mysql_query($query, $db) or die (mysql_error()."<br />Couldn't execute query: $query");
	
	##mysql_query($query);

	print "<br><b>details updated</b><br><br>";
	echo"$C_ID";
	echo"$ud_C_First";
	echo"$ud_C_Last";
	echo"$ud_C_Email";
	echo"$ud_C_Phone";
	}
	
?>

Posted: Tue Nov 23, 2004 2:20 am
by Steveo31
I'm guessing all the echos at the end return the correct results, and no errors show...

echo mysql_affected_rows($result);

See what that does...

Posted: Tue Nov 23, 2004 2:28 am
by C_Calav
yeah you are right Steveo31, i guess just checking, it gives the right results and no errors. but then i check the DB and all the fields are blank except for the ID which i didnt update.

will put echo mysql_affected_rows($result); in

Posted: Tue Nov 23, 2004 2:38 am
by C_Calav
hey Steveo31 what does is echo mysql_affected_rows($result); ment to tell me anyway?

i put it at the very bottm and gave me a error

Code: Select all

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /var/users/modelair/modelaircraft.co.nz/htdocs/update_details.php on line 366

Posted: Tue Nov 23, 2004 3:04 am
by phpScott
it means that $result isn't a valid resource as in mysql doesn't know what $result is so there could be something wrong with your query that isn't updateing correctly.

echo out your query and run that directly agianst you db to make sure it is working and updating correctly because you may not be getting the values that you are expecting in your query.

This is just supposed to be updating one row at a time right?

Posted: Tue Nov 23, 2004 3:14 am
by C_Calav
hi phpScott,

yip, updating just one row at a time.

i tested the sql out in MySql and it worked fine, updated the the row.

any other ideas?

Posted: Tue Nov 23, 2004 3:24 am
by phpScott
we could do something stupid like echo out $result to make sure we are getting something back from the query either true or false.
try using echo mysql_affected_rows($result); agian but right after where you submit the update. you should get something back

Posted: Tue Nov 23, 2004 3:32 am
by C_Calav
phpScott,

i have set my page up like this, just in case it helps.

--
php - select details

html

php - update
--

i put mysql_affected_rows($result); in again, same error, i added it in just after the submite button, (not sure if thats where you ment or not.

Code: Select all

<div id="buttons">
<input type="reset" value="Reset" class="btn" />
<input type="submit" value="Continue" class="btn" />
<?php mysql_affected_rows($result);?>
</div>

Posted: Tue Nov 23, 2004 3:37 am
by phpScott
this is where the mysql_affected_rows() should go.

Code: Select all

<?php
$result = mysql_query($query, $db) or die (mysql_error()."<br />Couldn't execute query: $query");
echo mysql_affected_rows();
?>
sorry got the syntax wrong. I use a db class that stores it as one of the pieces of information so I forgot the right way of calling it.

Posted: Tue Nov 23, 2004 3:45 am
by C_Calav
hey phpScott,

it gave me a 1 when i was on the update page,

then when i clicked update,

it gave me a 0 on the update page.

what does this tell you?

Posted: Tue Nov 23, 2004 3:54 am
by phpScott
It sounds to me that on the second update you are not getting the $C_ID value being passed. so it doesn't know which line to update.
Are you still getting that value when when you click on the update button or any values that you are echoing out after you click?

Posted: Tue Nov 23, 2004 4:04 am
by C_Calav
no im not getting that value after i click the submit button, i guess thats where the problem is!

so do i just put the cartID into a hidden text box again and post to next page?
----

can you check please if im doing this the right way?
cart > echo cartID in a hidden text box

details > get cartID, echo into hidden text box again

summary > get cartID, echo into hidden text box again

update_deatils > get cartID
can you see what im trying to do?
i do all this just so i know the usser's deatils and cart details.

is there any easier way of doing.. seems like im repeating alot.

thanx for you help phpScott, will check in morning off to bed, damn work!

Posted: Tue Nov 23, 2004 5:46 am
by phpScott
without see how the rest of the page looks i would have to say yes.
In the form with the update button you will have to

Code: Select all

<?php

<input type="hidden" name="cartID" id="cartID" value="<?php echo $cartID;?>" />
?>
only because the values are coming in as $_POST variables.

But if the values are being updated as the page loads the first time is this page allowing them to do more updates to their account and that is the reason for the update button?