SoireeExtreme Posted November 24, 2006 Share Posted November 24, 2006 I'm still very new at mysql let alone php. And I've tried everything I know how to do and I searched for answers but I couldn't turn up anything that I could understand to help me. With that said.I am creating and admin section to a game. And as most games do it contains items. And I want to be able to edit items that are already store in the database from the admin section. As I've said I've tried and tried. I've been working on this for I know has to be very simple script because I've worked on scripts similar to it. And they all work fine. I even tried converting those to work with editing items. But had no luck.Here is my code for the two pages. Here is the List Items Script.[code]<? echo "<center>"; echo "<table>"; global $start; if(!isset($start)) { $start=0; } $itemselect="SELECT * from ac_items order by name ASC limit $start, 50 "; $itemselect2=mysql_query($itemselect) or die("Could not select items"); print "<tr>"; print "<TD BGCOLOR='#505050' CLASS=white>Name</td><TD BGCOLOR='#505050' CLASS=white>ID</td><TD BGCOLOR='#505050' CLASS=white>Type</td><TD BGCOLOR='#505050' CLASS=white>Buy Cost</td><TD BGCOLOR='#505050' CLASS=white>Attribute</td><TD BGCOLOR='#505050' CLASS=white>Attribute</td><TD BGCOLOR='#505050' CLASS=white>Require</td><TD BGCOLOR='#505050' CLASS=white>Delete</td>"; while($itemselect3=mysql_fetch_array($itemselect2)) { print"<tr><form action='edititems.php' method='post'><TD BGCOLOR='#D4C0A1'><input type='text' name='name' value='$itemselect3[name]' size='15'></td><TD BGCOLOR='#D4C0A1'><input type='text' name='ID' value='$itemselect3[ID]' size='2'></td><TD BGCOLOR='#D4C0A1'><input type='text' name='type' value='$itemselect3[type]' size='6'></td><TD BGCOLOR='#D4C0A1'><input type='text' name='buycost' value='$itemselect3[buycost]' size='5'></td><TD BGCOLOR='#D4C0A1'><input type='text' name='attribute' value='$itemselect3[attribute]' size='10'></td><TD BGCOLOR='#D4C0A1'><input type='text' name='attribute2' value='$itemselect3[attribute2]' size='10'></td><TD BGCOLOR='#D4C0A1'><input type='text' name='require' value='$itemselect3[require]' size='10'></td><TD BGCOLOR='#D4C0A1'><A href='delitems.php?ID=$itemselect3[ID]'>Delete</a><br><input type='submit' name='submit' value='Edit'></form></tr></td></tr>"; } $order="SELECT * from ac_items";$order2=mysql_query($order);$d=0;$f=0;$g=1;print "Page: ";while($order3=mysql_fetch_array($order2)){if($f%20==0) { print "<A href='edititems.php?start=$d'>$g</a> "; $g++; }$d=$d+1;$f++;} print "</td></tr></table>"; print "</center>";?>[/code]Here is the Code for entering the information into the database[code]<?php print "<center>"; print "<table>"; print "<tr class='mainrow'><td>";$name=$_POST['name'];$name=strip_tags($name);$ID=$_POST['ID'];$ID=strip_tags($ID);$type=$_POST['type']; $type=strip_tags($type);$buycost=$_POST['buycost'];$buycost=strip_tags($buycost);$attribute=$_POST['attribute'];$attribute=strip_tags($attribute);$attribute2=$_POST['attribute2'];$attribute2=strip_tags($attribute2);$require=$_POST['require'];$require=strip_tags($require); $SQL = "update ac_items (name, ID, type, buycost, attribute, attirbute2, require) VALUES ('$name','$ID', '$type','$buycost','$attribute','$attribute2','$require')"; mysql_query($SQL) or die("Could not register: ". mysql_error());echo "<P>Item(s) Updated<P>"; print "</td></tr></table>"; ?>[/code]Now on this script. I've done it this way before, but its always saying user this user equals and if this or if that. And I have other scripts are just like this that work just fine without the user this or user that stuff. And when I do hit submit... I get this error/message.... Which I've tried looking up too and found nothing helpful...[quote]Could not register: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(name, ID, type, buycost, attribute, attirbute2, require) VALUES ('$name','$ID',' at line 1[/quote]So could anyone please for the love of god help me out? I've been beating my head on my desk trying to figure this out and learn it. Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 24, 2006 Share Posted November 24, 2006 two things:[b]require[/b] is a MySQL reserved word and you cannot use it as a database table field name.Is the field name really att[b]ir[/b]bute2 or is it att[b]ri[/b]bute2? Your code is inconsistent. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 24, 2006 Author Share Posted November 24, 2006 [quote author=AndyB link=topic=116138.msg473017#msg473017 date=1164356951][b]require[/b] is a MySQL reserved word and you cannot use it as a database table field name.Is the field name really att[b]ir[/b]bute2 or is it att[b]ri[/b]bute2? Your code is inconsistent.[/quote]I didn't know it was a reserved word. And its attribute2. Just a misspelling.But I changed require to needed instead. And I still get the same message meantiond above. About need to check the manuel. So bascially I'm still sitting in the same place banging my head. Quote Link to comment Share on other sites More sharing options...
joshi_v Posted November 24, 2006 Share Posted November 24, 2006 Hey are you trying to update or insert?If it is insert then then change your query from 'Update ac_items' to 'Insert ac_items'If you are trying to update then do like this$SQL = "update ac_items SET name='$name', ID='$ID', type='$type', buycost='$buycost', attribute='$attribute', attirbute2='$attribute2', needed='needed' WHERE 'blah blah'RegardsJoshi Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 24, 2006 Author Share Posted November 24, 2006 I'm trying to update. But I've tried doing both ways. And lord knows changing this or that. But I'll try your way (again). And I'll be back I'm sure. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 24, 2006 Author Share Posted November 24, 2006 Ok well I guess that did work a bit. Now I have a different message/error then before. Which is....[quote]Could not register: Out of range value adjusted for column 'attribute' at row 1[/quote]What does that mean exactly? And how do I manage to fix that? Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 24, 2006 Author Share Posted November 24, 2006 Never mind my last post. I figured it out on my own. And thank you joshi_v. Even those i tried what you said before. It works now. I must of screwed something up when I was doing it. Unless others find this thread useful. I no longer require help on this one. Thanks to all who helped and tried to help. Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 25, 2006 Author Share Posted November 25, 2006 Alright I'm having this same problem again, but this time I'm not updating I'm inserting. And I've used this script before but now its not working for some reason could someone please tell me why? [code]<?phpif(isset($_POST['submit'])) {$name=$_POST['name'];$name=strip_tags($name);$type=$_POST['type']; $type=strip_tags($type);$buycost=$_POST['buycost'];$buycost=strip_tags($buycost);$upgrade=$_POST['upgrade'];$upgrade=strip_tags($upgrade);$upgrade2=$_POST['upgrade2'];$upgrade2=strip_tags($upgrade2);$needed=$_POST['needed'];$needed=strip_tags($needed);$SQL = "INSERT into ac_mods (name,type,buycost,upgrade,upgrade2,needed) values('$name','$type','$buycost','$upgrade','$upgrade2','$needed')";mysql_query($SQL) or die(mysql_error());echo "<P>New Item Added<P>";}?>[/code] Quote Link to comment Share on other sites More sharing options...
fenway Posted November 26, 2006 Share Posted November 26, 2006 And no error from the DB? Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 26, 2006 Author Share Posted November 26, 2006 Just the same error I had to begin with when I was trying to update. And to make sure I'm clear. I'm trying to do an insert now... But the error is....[quote]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'upgrade,upgrade2,needed) values('Ship Bumper','Bumper','100','x','x','x')' at line 1[/quote]I really don't understand why this wouldn't work when I've haven't found any misspellings and the database is set up right. Because I've used this exact same code to insert before with other things. Except this time I changed the names. Like before it was attribute but now its upgarde. Why doesn't it want to work now? Quote Link to comment Share on other sites More sharing options...
AndyB Posted November 26, 2006 Share Posted November 26, 2006 Improve the error messages and probably all will become clear. Change this (or similar):[code]$SQL = "INSERT into ac_mods (name,type,buycost,upgrade,upgrade2,needed) values('$name','$type','$buycost','$upgrade','$upgrade2','$needed')";mysql_query($SQL) or die(mysql_error());[/code]to this:[code]$SQL = " ... whatever your query is ...";$result = mysql_query($SQL) or die("Error: ". mysql_error(). " with query ". $SQL);[/code]And post exactly what's output.If you happen to be using MySQL 5, then the problem is that [b]UPGRADE[/b] is a reserved word with MySQL 5. Don't use reserved words for table or field names.http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Quote Link to comment Share on other sites More sharing options...
SoireeExtreme Posted November 26, 2006 Author Share Posted November 26, 2006 Grrr mysql and its silly reserved words. Thats twice now lol. Thank you for the reference to the reserved works I'm sure its going to come in handy.As for my problem it is now fixed. As I was using a reserved word. Thank you for pointing my error out. Everything works like a charm like it should be. ;D ;D ;D Very much appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.