Re: [PHP-DB] If( Query)
Niel Archer wrote: Hi I have the following function: function add_item($item_name,$item_desc,$item_price,$item_man_id,$item_cat_id,$item_pix) { connect(); if($item_pix == "") { $sql = "INSERT INTO items (item_name,item_desc,item_price,item_man_id,item_cat_id) VALUES ('$item_name','$item_desc','$item_price','$item_man_id','$item_cat_id')"; } else { $sql = "INSERT INTO items (item_name,item_desc,item_price,item_pix,item_man_id,item_cat_id) VALUES ('$item_name','$item_desc','$item_price','$item_pix','$item_man_id','$item_cat_id')"; } mysql_query($sql); return; } I am using the if statement because i want it so that if no picture is uploaded the entry is blank and the mysql database has a default entry of na.gif which is a "picture coming soon picture". It works fine when i run in localy on MAMP, but if i run it on my web server it doesnt add the row. You should be checking the mysql_query call for success and output the error if it fails. Something like: mysql_query($sql) or die('Insert failed: ' . mysql_error()); You'll now why it's failing then. Make sure you have error reporting enabled. Is this a compatability error? or is there a better way to write this? -- Niel Archer I have fixed it now: function add_item($item_name,$item_desc,$item_price,$item_man_id,$item_cat_id,$item_pix) { connect(); if($item_pix == "") { $sql = "INSERT INTO items (item_name,item_desc,item_price,item_man_id,item_cat_id) VALUES ('$item_name','$item_desc','$item_price','$item_man_id','$item_cat_id')"; } else { $sql = "INSERT INTO items (item_name,item_desc,item_price,item_pix,item_man_id,item_cat_id) VALUES ('$item_name','$item_desc','$item_price','$item_pix','$item_man_id','$item_cat_id')"; } mysql_query($sql); return; } Thanks anyway. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] If( Query)
Hi > I have the following function: > > function > add_item($item_name,$item_desc,$item_price,$item_man_id,$item_cat_id,$item_pix) > { > connect(); > if($item_pix == "") > { > $sql = "INSERT INTO items > (item_name,item_desc,item_price,item_man_id,item_cat_id) VALUES > ('$item_name','$item_desc','$item_price','$item_man_id','$item_cat_id')"; > } > else { > $sql = "INSERT INTO items > (item_name,item_desc,item_price,item_pix,item_man_id,item_cat_id) VALUES > ('$item_name','$item_desc','$item_price','$item_pix','$item_man_id','$item_cat_id')"; > } > mysql_query($sql); > return; > } > > I am using the if statement because i want it so that if no picture is > uploaded the entry is blank and the mysql database has a default entry > of na.gif which is a "picture coming soon picture". > > It works fine when i run in localy on MAMP, but if i run it on my web > server it doesnt add the row. You should be checking the mysql_query call for success and output the error if it fails. Something like: mysql_query($sql) or die('Insert failed: ' . mysql_error()); You'll now why it's failing then. Make sure you have error reporting enabled. > Is this a compatability error? or is there a better way to write this? > -- Niel Archer -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql auto_increment
Little change - the label was not used in the right way: http://pastebin.com/m2d98e677 On Sun, Sep 7, 2008 at 11:46 PM, Evert Lammerts <[EMAIL PROTECTED]> wrote: > I guess this code was not copy pasted from your actual source? It > would generate mysql errors. > > Anyway, I think I've an idea of what you want, so here's my two cents : > > function edit_cat_radio($item_cat_id) { >connect(); >$query = mysql_query("SELECT * FROM cat"); >while ($row = mysql_fetch_assoc($query)) { >echo " for=\"{$row['cat_name']}\">{$row['cat_name']} type=\"radio\" name=\"fcat\" value=\"{$row['cat_id']}\" > id=\"{$row['cat_id']}\" " . ($item_cat_id == $row["cat_id"] ? > "checked=\"checked\"" : "") . "/>\n"; >} > } > > > > On Sun, Sep 7, 2008 at 11:16 PM, Chris Hale <[EMAIL PROTECTED]> wrote: >> I am writing a catologe application and i have a problem when it comes to >> the edit product part. I have a table with the catogories and a table with >> manufacturers. >> Each table has a id column and a name column. The id column is set up in the >> MySQL to auto_increment, which works fine normally, but i am writing this >> script: >> >> function edit_cat_radio($item_cat_id) >> { >> connect(); >> $sql = "SELECT * FROM cat DISTINGT ORDER BY cat_id"; >> $result = mysql_query($sql); >> $k = 1; >> while ($row = mysql_fetch_assoc($result)) >> { >> extract($row); >> echo '',$cat_name,'> name="fcat" value="',$cat_id,'" id="',$cat_id,'"'; >> if($k == $item_cat_id) >> { >> echo 'checked'; >> } >> echo ' />'; >> $k++; >> } >> return; } >> >> This should (in theory) automatically check the radio button of the existing >> catogory. It would work fine; but what seems to mess it up is the >> auto_increment. >> >> If i delete a catogory/manufacturer from the id's remain the same. and end >> up like this: >> cat_id cat_name >> 1 Bridlework >> 2 Clippers >> 3 Clothing >> 4 Dressage Tests >> 5 DVD/Video/Books >> 9 Footwear >> >> but if the cat_id is 9 the /while /statement doesnt repeat 9 times so the >> counter never reaches 9. >> >> I don't know if you got all that, its hard to explain. >> >> I would appreciate any help on how to sort this out. >> >> Thanks >> >> -- >> PHP Database Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql auto_increment
Pastebin is so much nicer when posting code. Find the code i've sent here: http://pastebin.com/mc5d611a -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] mysql auto_increment
I guess this code was not copy pasted from your actual source? It would generate mysql errors. Anyway, I think I've an idea of what you want, so here's my two cents : function edit_cat_radio($item_cat_id) { connect(); $query = mysql_query("SELECT * FROM cat"); while ($row = mysql_fetch_assoc($query)) { echo "{$row['cat_name']}\n"; } } On Sun, Sep 7, 2008 at 11:16 PM, Chris Hale <[EMAIL PROTECTED]> wrote: > I am writing a catologe application and i have a problem when it comes to > the edit product part. I have a table with the catogories and a table with > manufacturers. > Each table has a id column and a name column. The id column is set up in the > MySQL to auto_increment, which works fine normally, but i am writing this > script: > > function edit_cat_radio($item_cat_id) > { > connect(); > $sql = "SELECT * FROM cat DISTINGT ORDER BY cat_id"; > $result = mysql_query($sql); > $k = 1; > while ($row = mysql_fetch_assoc($result)) > { > extract($row); > echo '',$cat_name,' name="fcat" value="',$cat_id,'" id="',$cat_id,'"'; > if($k == $item_cat_id) > { > echo 'checked'; > } > echo ' />'; > $k++; > } > return; } > > This should (in theory) automatically check the radio button of the existing > catogory. It would work fine; but what seems to mess it up is the > auto_increment. > > If i delete a catogory/manufacturer from the id's remain the same. and end > up like this: > cat_id cat_name > 1 Bridlework > 2 Clippers > 3 Clothing > 4 Dressage Tests > 5 DVD/Video/Books > 9 Footwear > > but if the cat_id is 9 the /while /statement doesnt repeat 9 times so the > counter never reaches 9. > > I don't know if you got all that, its hard to explain. > > I would appreciate any help on how to sort this out. > > Thanks > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mysql auto_increment
I am writing a catologe application and i have a problem when it comes to the edit product part. I have a table with the catogories and a table with manufacturers. Each table has a id column and a name column. The id column is set up in the MySQL to auto_increment, which works fine normally, but i am writing this script: function edit_cat_radio($item_cat_id) { connect(); $sql = "SELECT * FROM cat DISTINGT ORDER BY cat_id"; $result = mysql_query($sql); $k = 1; while ($row = mysql_fetch_assoc($result)) { extract($row); echo '',$cat_name,'type="radio" name="fcat" value="',$cat_id,'" id="',$cat_id,'"'; if($k == $item_cat_id) { echo 'checked'; } echo ' />'; $k++; } return; } This should (in theory) automatically check the radio button of the existing catogory. It would work fine; but what seems to mess it up is the auto_increment. If i delete a catogory/manufacturer from the id's remain the same. and end up like this: cat_id cat_name 1 Bridlework 2 Clippers 3 Clothing 4 Dressage Tests 5 DVD/Video/Books 9 Footwear but if the cat_id is 9 the /while /statement doesnt repeat 9 times so the counter never reaches 9. I don't know if you got all that, its hard to explain. I would appreciate any help on how to sort this out. Thanks -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] If( Query)
Is your table set up in the same way on your webserver? Maybe you forgot to set the default value to na.gif in your item_pix column. If not, can you send your table definition? On Sat, Sep 6, 2008 at 9:02 PM, Chris Hale <[EMAIL PROTECTED]> wrote: > I have the following function: > > function > add_item($item_name,$item_desc,$item_price,$item_man_id,$item_cat_id,$item_pix) > { > connect(); > if($item_pix == "") > { > $sql = "INSERT INTO items > (item_name,item_desc,item_price,item_man_id,item_cat_id) VALUES > ('$item_name','$item_desc','$item_price','$item_man_id','$item_cat_id')"; > } > else { > $sql = "INSERT INTO items > (item_name,item_desc,item_price,item_pix,item_man_id,item_cat_id) VALUES > ('$item_name','$item_desc','$item_price','$item_pix','$item_man_id','$item_cat_id')"; > } > mysql_query($sql); > return; > } > > I am using the if statement because i want it so that if no picture is > uploaded the entry is blank and the mysql database has a default entry of > na.gif which is a "picture coming soon picture". > > It works fine when i run in localy on MAMP, but if i run it on my web server > it doesnt add the row. > > Is this a compatability error? or is there a better way to write this? > > Thanks > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php