Page 1 of 2
Id number displays 0 and not 1
Posted: Fri Jan 26, 2007 11:31 pm
by cturner
When I test the following code it displays 0 in the url and not 1. Can someone please have a look at my code and tell me how I can solve this problem? Thanks in advance.
Code: Select all
// variables defined before this
require "config.php";
$update = "UPDATE clearingsales SET propertyname = '$propertyname', time = '$time', accountname = '$accountname', comments = '$comments', select1 = '$select1', txt1 = '$txt1', select2 = '$select2', txt2 = '$txt2', select3 = '$select3', txt3 = '$txt3', select4 = '$select4', txt4 = '$txt4', select5 = '$select5', txt5 = '$txt5', select6 = '$select6', txt6 = '$txt6', select7 = '$select7', txt7 = '$txt7', select8 = '$select8', txt8 = '$txt8', select9 = '$select9', txt9 = '$txt9', select10 = '$select10', txt10 = '$txt10', select11 = '$select11', txt11 = '$txt11' WHERE propertyname = '$propertyname'";
if (mysql_query ($update)) {
$query = mysql_query("SELECT id, propertyname FROM `clearingsales` WHERE `propertyname` = '$propertyname'") or die ("Could not query because: ".mysql_error());
$row = mysql_fetch_assoc($query);
$insertID = mysql_insert_id();
header ("Location: clearing_sale_edited.php?id=".$insertID);
} else {
print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>";
}
mysql_close();
Posted: Fri Jan 26, 2007 11:59 pm
by volka
Whre's the INSERT statement?
What are you trying to achieve?
Posted: Sat Jan 27, 2007 12:00 am
by superdezign
Posted: Sat Jan 27, 2007 12:17 am
by cturner
I have changed my code superdezign to what you said. Now I am getting no id number in the url.
Posted: Sat Jan 27, 2007 12:23 am
by volka
Use
mysql_affected_rows to check wether UPDATE really changed a record.
use
false!==$row to test wether the SELECT statement actually fetched a record.
Posted: Sat Jan 27, 2007 12:24 am
by cturner
I have now changed my code to:
Code: Select all
$update = "UPDATE clearingsales SET propertyname = '$propertyname', time = '$time', accountname = '$accountname', comments = '$comments', select1 = '$select1', txt1 = '$txt1', select2 = '$select2', txt2 = '$txt2', select3 = '$select3', txt3 = '$txt3', select4 = '$select4', txt4 = '$txt4', select5 = '$select5', txt5 = '$txt5', select6 = '$select6', txt6 = '$txt6', select7 = '$select7', txt7 = '$txt7', select8 = '$select8', txt8 = '$txt8', select9 = '$select9', txt9 = '$txt9', select10 = '$select10', txt10 = '$txt10', select11 = '$select11', txt11 = '$txt11' WHERE propertyname = '$propertyname'";
if (mysql_query ($update)) {
$id = mysql_real_escape_string($_GET['id']);
header ("Location: clearing_sale_edited.php?id=".$id);
} else {
print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>";
}
I am still getting no id number in the url.
Posted: Sat Jan 27, 2007 12:26 am
by superdezign
Really? That's odd. In that case, I'm stumped. Something in your code must not be happening correctly. Either your table update isn't happeneing, or your select isn't happening.
Or your table column "id" is empty. I doubt it's that bad though.
Edit: I think volka's leading ou the right way, I'm going to sleep now.
Posted: Sat Jan 27, 2007 12:26 am
by volka
a) why mysql_real_escape_string when you want to use the result in an url (not mysql) ?
b) is there a _GET['id']? Use print_r($_GET); to check that.
Posted: Sat Jan 27, 2007 12:33 am
by cturner
I have placed print_r($_GET); into my code and it displays Array ( [id] => 1 ).
Posted: Sat Jan 27, 2007 12:36 am
by volka
try
Code: Select all
error_reporting(E_ALL); ini_set('display_errors', true);
$update = "UPDATE clearingsales SET propertyname = '$propertyname', time = '$time', accountname = '$accountname', comments = '$comments', select1 = '$select1', txt1 = '$txt1', select2 = '$select2', txt2 = '$txt2', select3 = '$select3', txt3 = '$txt3', select4 = '$select4', txt4 = '$txt4', select5 = '$select5', txt5 = '$txt5', select6 = '$select6', txt6 = '$txt6', select7 = '$select7', txt7 = '$txt7', select8 = '$select8', txt8 = '$txt8', select9 = '$select9', txt9 = '$txt9', select10 = '$select10', txt10 = '$txt10', select11 = '$select11', txt11 = '$txt11' WHERE propertyname = '$propertyname'";
if (mysql_query ($update)) {
$header="Location: clearing_sale_edited.php?id=".$_GET['id'];
echo $header;
// header($header);
}
else {
print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>";
}
Posted: Sat Jan 27, 2007 12:48 am
by cturner
I have my the changes to my code volka. Now I am getting Undefined index. So what does that mean?
Posted: Sat Jan 27, 2007 12:54 am
by volka
undefined index 'id'?
Then I do not know how this fits
cturner wrote:I have placed print_r($_GET); into my code and it displays Array ( [id] => 1 ).
try
Code: Select all
error_reporting(E_ALL); ini_set('display_errors', true);
$update = "UPDATE clearingsales SET propertyname = '$propertyname', time = '$time', accountname = '$accountname', comments = '$comments', select1 = '$select1', txt1 = '$txt1', select2 = '$select2', txt2 = '$txt2', select3 = '$select3', txt3 = '$txt3', select4 = '$select4', txt4 = '$txt4', select5 = '$select5', txt5 = '$txt5', select6 = '$select6', txt6 = '$txt6', select7 = '$select7', txt7 = '$txt7', select8 = '$select8', txt8 = '$txt8', select9 = '$select9', txt9 = '$txt9', select10 = '$select10', txt10 = '$txt10', select11 = '$select11', txt11 = '$txt11' WHERE propertyname = '$propertyname'";
if (mysql_query ($update)) {
echo '<pre>'; var_export($_GET); echo "</pre>\n";
$header="Location: clearing_sale_edited.php?id=".$_GET['id'];
echo $header;
// header($header);
}
else {
print "<p>Could not update the entry because: <b>" . mysql_error() . "</b>. The query was $update.</p>";
}
Posted: Sat Jan 27, 2007 12:58 am
by cturner
Undefined index is actually for propertyname to other11 not id. Sorry for not saying that earlier. What does undefined index mean?
Posted: Sat Jan 27, 2007 1:02 am
by volka
Code: Select all
$arr = array(
'abc' => '123'
);
$e = $arr['abc']; // no problem, there is an index 'abc' in $arr
$e = $arr['xyz']; // undefined index: xyz
Posted: Sat Jan 27, 2007 2:29 am
by cturner
Okay I understand that now. But I can't find a reason why code is displaying those errors. Could I please post my code here and someone find the problems? I am about to tear my hair if I don't fix those errors soon. This is bugging me.