PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Fri Jan 26, 2007 11:31 pm
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();
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Fri Jan 26, 2007 11:59 pm
Whre's the INSERT statement?
What are you trying to achieve?
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Sat Jan 27, 2007 12:17 am
I have changed my code superdezign to what you said. Now I am getting no id number in the url.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 27, 2007 12:23 am
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.
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Sat Jan 27, 2007 12:24 am
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.
superdezign
DevNet Master
Posts: 4135 Joined: Sat Jan 20, 2007 11:06 pm
Post
by superdezign » Sat Jan 27, 2007 12:26 am
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.
Last edited by
superdezign on Sat Jan 27, 2007 12:27 am, edited 1 time in total.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 27, 2007 12:26 am
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.
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Sat Jan 27, 2007 12:33 am
I have placed print_r($_GET); into my code and it displays Array ( [id] => 1 ).
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 27, 2007 12:36 am
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>";
}
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Sat Jan 27, 2007 12:48 am
I have my the changes to my code volka. Now I am getting Undefined index. So what does that mean?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 27, 2007 12:54 am
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>";
}
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Sat Jan 27, 2007 12:58 am
Undefined index is actually for propertyname to other11 not id. Sorry for not saying that earlier. What does undefined index mean?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sat Jan 27, 2007 1:02 am
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
cturner
Forum Contributor
Posts: 153 Joined: Sun Jul 16, 2006 3:03 am
Location: My computer
Post
by cturner » Sat Jan 27, 2007 2:29 am
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.