helpmeplease2 Posted August 26, 2006 Share Posted August 26, 2006 I made this form to insert data into a mysql database but its not working. Its not giving me any error messages either.[code]<form action="?p=newfile" method="post" style="margin:0px"><strong>File Details:</strong><br><table border="0" cellspacing="1" cellpadding="0"><tr><td>Title/Name </td><td><input type="text" name="name" size="30"></td></tr><tr><td colspan="2">Description </td></tr><tr><td colspan="2"><textarea name="desc" rows="7" cols="35"></textarea></td></tr><tr><td>Type </td><td><select name="type" size="1"><option value="1">type1</option><option value="2">type2</option></select></td></tr><tr><td>Link </td><td><input type="text" name="link" size="30" value="downloads/"></td></tr><tr><td>Format </td><td><input type="text" name="format" size="30"></td></tr><tr><td>Size </td><td><input type="text" name="size" size="30"></td></tr><tr><td>Picture </td><td><input type="text" name="pic" size="30" value="images/"></td></tr><tr><td></td><td><button type="submit">Add file!</button></td></tr></table>[/code]newfile.php:[code]<?php$name=$_POST['name'];$pic=$_POST['pic'];$format=$_POST['format'];$size=$_POST['size'];$type=$_POST['type'];$link=$_POST['link'];$desc=$_POST['desc'];mysql_query("INSERT INTO downloads (name, desc, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')");?>[/code]Whats wrong with my code? Help is appreciated. :) Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 26, 2006 Share Posted August 26, 2006 DESC is a MySQL reserved word and definitely should NOT be used as a column name. I'd suggest you change it to descr.And if you're not getting any error messages, 'someone' has turned them off because that query would definitely generate an error. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 26, 2006 Share Posted August 26, 2006 Add or die(mysql_error(); to the end of this:[code]mysql_query("INSERT INTO downloads (name, desc, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')");[/code]So its now this:[code]mysql_query("INSERT INTO downloads (name, desc, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')") or die(mysql_errot());[/code]However I think its becuase you have a coloumn name called desc and desc is a reserver MySQL keyword. use backticks around the desc so its this:`desc`[code]mysql_query("INSERT INTO downloads (name, `desc`, pic, type, link) VALUES ('$name','$desc/n/n$format/n$size','$pic','$type','$link')") or die(mysql_errot());[/code] Quote Link to comment Share on other sites More sharing options...
helpmeplease2 Posted August 26, 2006 Author Share Posted August 26, 2006 I changed desc to descr everywhere and its doing the same thing as before. I added the mysql_error code and I'm getting this:Parse error: parse error, unexpected T_LOGICAL_OR in /home/www/includes/newfile.php on line 25 Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 26, 2006 Share Posted August 26, 2006 [quote author=helpmeplease2 link=topic=105725.msg422458#msg422458 date=1156612267]Parse error: parse error, unexpected T_LOGICAL_OR in /home/www/includes/newfile.php on line 25[/quote]Line 25? How strange. The newfile.php you posted has less than a dozen lines. Is there more of it we're not seeing? Quote Link to comment Share on other sites More sharing options...
helpmeplease2 Posted August 26, 2006 Author Share Posted August 26, 2006 Thats the full newfile.php file. The only stuff I'm not showing you at the moment is in index.php which just contains html layout and the mysql connection. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 26, 2006 Share Posted August 26, 2006 OK, which of the eight lines of newfile.php is line 25? Quote Link to comment Share on other sites More sharing options...
helpmeplease2 Posted August 26, 2006 Author Share Posted August 26, 2006 YTM, notepad says "line number out of range".Edit: I opened newfile.php in wordpad instead of notepad and there were extra blank lines, I removed them and the error says its on line 10 now. Here are my updated files.[code]<br>All fields must be filled.<br><br><form action="?p=newfile" method="post" style="margin:0px"><strong>File Details:</strong><br><table border="0" cellspacing="1" cellpadding="0"><tr><td>Title/Name </td><td><input type="text" name="name" size="30"></td></tr><tr><td colspan="2">Description </td></tr><tr><td colspan="2"><textarea name="descr" rows="7" cols="35"></textarea></td></tr><tr><td>Type </td><td><select name="type" size="1"><option value="1">type1</option><option value="2">type2</option><option value="3">type3</option><option value="4">type4</option><option value="5">type5</option><option value="6">type6</option></select></td></tr><tr><td>Link </td><td><input type="text" name="link" size="30" value="downloads/"></td></tr><tr><td>Format </td><td><input type="text" name="format" size="30"></td></tr><tr><td>Size </td><td><input type="text" name="size" size="30"></td></tr><tr><td>Picture </td><td><input type="text" name="pic" size="30" value="images/"></td></tr><tr><td></td><td><button type="submit">Add file!</button></td></tr></table></form>[/code]newfile.php:[code]<?php$name=$_POST['name'];$pic=$_POST['pic'];$format=$_POST['format'];$size=$_POST['size'];$type=$_POST['type'];$link=$_POST['link'];$descr=$_POST['descr'];mysql_query("INSERT INTO downloads (name, descr, pic, type, link) VALUES ('$name','$descr/n/n$format/n$size','$pic','$type','$link')");or die(mysql_error());?>[/code] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted August 26, 2006 Share Posted August 26, 2006 This:[code]mysql_query("INSERT INTO downloads (name, descr, pic, type, link) VALUES ('$name','$descr/n/n$format/n$size','$pic','$type','$link')");or die(mysql_error());[/code]Should be this:[code]mysql_query("INSERT INTO downloads (name, descr, pic, type, link) VALUES ('$name','$descr/n/n$format/n$size','$pic','$type','$link')") or die(mysql_error());[/code] Quote Link to comment Share on other sites More sharing options...
helpmeplease2 Posted August 27, 2006 Author Share Posted August 27, 2006 Ok thanks, after I changed that code I received an error saying it couldn't find the column named 'type', it should have been 'cat'. Well its working now, thanks for everything wildteen88 and AndyB! 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.