TheCatapult Posted March 18, 2012 Share Posted March 18, 2012 Hi! I have this problem, please help me. Here's my code. <form action="top10.php" method="post">current dj:<input type="text" name="1" /><input type="text" name="2" /><input type="text" name="3" /><input type="text" name="4" /><input type="text" name="5" /><input type="text" name="6" /><input type="text" name="7" /><input type="text" name="8" /><input type="text" name="9" /><input type="text" name="10" /><input type="submit" /> Here's the top10.php <?$con = mysql_connect(","","");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("", $con);$1 = $_POST['1'];$2 = $_POST['2'];$3 = $_POST['3'];$4 = $_POST['4'];$6 = $_POST['6'];$6 = $_POST['7'];$7 = $_POST['7'];$8 = $_POST['8'];$9 = $_POST['9'];$10 = $_POST['10'];$res=mysql_query("UPDATE top10SET 1='$1'SET 2= '$2'SET 3= '$3'SET 4= '$4'SET 5= '$5'SET 6= '$6'SET 7= '$7'SET 8= '$8'SET 9= '$9'SET 10= '$10'WHERE id=0");if(!$res)echo mysql_error();mysql_close($con);?> Thanks! Link to comment Share on other sites More sharing options...
Ingolme Posted March 18, 2012 Share Posted March 18, 2012 Variable names must start with a non-numeric character. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 18, 2012 Author Share Posted March 18, 2012 Thanks! Here's the new code. <?$con = mysql_connect("fdb3.eu.pn","741839_test","building10");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("741839_test", $con);$n1 = $_POST['1'];$n2 = $_POST['2'];$n3 = $_POST['3'];$n4 = $_POST['4'];$n6 = $_POST['6'];$n6 = $_POST['7'];$n7 = $_POST['7'];$n8 = $_POST['8'];$n9 = $_POST['9'];$n10 = $_POST['10'];$res=mysql_query("UPDATE top10SET 1= '$n1'SET 2= '$n2'SET 3= '$n3'SET 4= '$n4'SET 5= '$n5'SET 6= '$n6'SET 7= '$n7'SET 8= '$n8'SET 9= '$n9'SET 10= '$n10'WHERE id=0");if(!$res)echo mysql_error();mysql_close($con);?> The HTML code is still the same. But I have a problem. 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 '1= 'adsaa' SET 2= '' SET 3= '' SET 4= '' SET 5= '' SET 6= '' SET 7= '' SET 8= ''' at line 2 Please help. Thanks! Link to comment Share on other sites More sharing options...
dsonesuk Posted March 19, 2012 Share Posted March 19, 2012 you only use SET once within query $res=mysql_query("UPDATE top10 SET 1='$n1', 2='$n2, 3='$n3', 4='$n4', 5='$n5', 6='$n6', 7='$n7', 8='$n8', 9='$n9', 10='$n10' WHERE id=0"); Link to comment Share on other sites More sharing options...
TheCatapult Posted March 19, 2012 Author Share Posted March 19, 2012 Thank you for your reply.I have separated every SET still it has problem. <?$con = mysql_connect("","",");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db(" ", $con);$n1 = $_POST['1'];$n2 = $_POST['2'];$n3 = $_POST['3'];$n4 = $_POST['4'];$n6 = $_POST['6'];$n6 = $_POST['7'];$n7 = $_POST['7'];$n8 = $_POST['8'];$n9 = $_POST['9'];$n10 = $_POST['10'];$res=mysql_query("UPDATE top10 SET 1= '$n1');("UPDATE top10 SET 2= '$n2');("UPDATE top10 SET 3= '$n3');("UPDATE top10 SET 4= '$n4');("UPDATE top10 SET 5= '$n5');("UPDATE top10 SET 6= '$n6');("UPDATE top10 SET 7= '$n7');("UPDATE top10 SET 8= '$n8');("UPDATE top10 SET 9= '$n9');("UPDATE top10 SET 10= '$n10');if(!$res)echo mysql_error();mysql_close($con);?> Hoping for answers. Thanks! Link to comment Share on other sites More sharing options...
birbal Posted March 19, 2012 Share Posted March 19, 2012 <? $con = mysql_connect("","",");missing closing quotes here. $res=mysql_query ("UPDATE top10 SET 1= '$n1'); ("UPDATE top10 SET 2= '$n2'); ("UPDATE top10 SET 3= '$n3'); ("UPDATE top10 SET 4= '$n4'); ("UPDATE top10 SET 5= '$n5'); ("UPDATE top10 SET 6= '$n6'); ("UPDATE top10 SET 7= '$n7'); ("UPDATE top10 SET 8= '$n8'); ("UPDATE top10 SET 9= '$n9'); ("UPDATE top10 SET 10= '$n10');it is the wrong way. you missed out dsonusk's postyou only use SET once within query $res=mysql_query("UPDATE top10 SET 1='$n1', 2='$n2, 3='$n3', 4='$n4', 5='$n5', 6='$n6', 7='$n7', 8='$n8', 9='$n9', 10='$n10' WHERE id=0"); Link to comment Share on other sites More sharing options...
TheCatapult Posted March 19, 2012 Author Share Posted March 19, 2012 Thank birbal!It has problem.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 '1='ad', 2='ad, 3='ad', 4='ad', 5='', 6='ad', 7='ad', 8='ad', 9='ad', 10='ad' WHE' at line 1The code is <?$con = mysql_connect("fdb3.eu.pn","741839_test","building10");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("741839_test", $con);$n1 = $_POST['1'];$n2 = $_POST['2'];$n3 = $_POST['3'];$n4 = $_POST['4'];$n6 = $_POST['6'];$n6 = $_POST['7'];$n7 = $_POST['7'];$n8 = $_POST['8'];$n9 = $_POST['9'];$n10 = $_POST['10'];$res=mysql_query("UPDATE top10 SET 1='$n1', 2='$n2, 3='$n3', 4='$n4', 5='$n5', 6='$n6', 7='$n7', 8='$n8', 9='$n9', 10='$n10' WHERE id=0");if(!$res)echo mysql_error();mysql_close($con);?> Thanks! Link to comment Share on other sites More sharing options...
dsonesuk Posted March 19, 2012 Share Posted March 19, 2012 I have a feeling, that it maybe down to the fact you are using a single number for field/column name, I did think it strange when i first saw it, as I've never seen it used before. Imagine adding two column records VALUES together, would it think you wanted to add column names? bit confusing as probably won't be able to distinguish from either. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2012 Share Posted March 19, 2012 From here: http://dev.mysql.com/doc/refman/5.0/en/identifiers.html Identifiers may begin with a digit but unless quoted may not consist solely of digits.You need to use the backtick to quote any identifier that only consists of digits. If it's unquoted then MySQL assumes it is a number, not an identifier, like dsonesuk mentioned. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 20, 2012 Author Share Posted March 20, 2012 Hi!This is my current new phpMyAdmin.Still what I wrote in my HTML form does not post to my database. Here's my HTML form code. <form action="top10.php" method="post">current dj:<input type="text" name="one" /><input type="text" name="two" /><input type="text" name="three" /><input type="text" name="four" /><input type="text" name="five" /><input type="text" name="six" /><input type="text" name="seven" /><input type="text" name="eight" /><input type="text" name="nine" /><input type="text" name="ten" /><input type="submit" /> PHP is this. <?$con = mysql_connect("","","");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("", $con);$n1 = $_POST['one'];$n2 = $_POST['two'];$n3 = $_POST['three'];$n4 = $_POST['four'];$n6 = $_POST['five'];$n6 = $_POST['six'];$n7 = $_POST['seven'];$n8 = $_POST['eight'];$n9 = $_POST['nine'];$n10 = $_POST['ten'];$res=mysql_query("UPDATE top10 SET one='$n1' WHERE id=0");("UPDATE top10 SET two='$n2' WHERE id=0");("UPDATE top10 SET three='$n3' WHERE id=0");("UPDATE top10 SET four='$n4' WHERE id=0");("UPDATE top10 SET five='$n5' WHERE id=0");("UPDATE top10 SET six='$n6' WHERE id=0");("UPDATE top10 SET seven='$n7' WHERE id=0");("UPDATE top10 SET eight='$n8' WHERE id=0");("UPDATE top10 SET nine='$n9' WHERE id=0");("UPDATE top10 SET ten='$n10' WHERE id=0");if(!$res)echo mysql_error();mysql_close($con);?> Please help me! Link to comment Share on other sites More sharing options...
justsomeguy Posted March 20, 2012 Share Posted March 20, 2012 Somehow you reverted to the syntax from post 5 instead of post 7. Post 7 has the correct syntax to use mysql_query to send an update query, it just had a problem with the field names in the query. Use the same syntax from that post and correct the field names. Link to comment Share on other sites More sharing options...
dsonesuk Posted March 20, 2012 Share Posted March 20, 2012 remember this ("UPDATE top10 SET 1='$n1', 2='$n2, 3='$n3', 4='$n4', 5='$n5', 6='$n6', 7='$n7', 8='$n8', 9='$n9', 10='$n10' WHERE id=0"); same rule still applies. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 20, 2012 Author Share Posted March 20, 2012 Hi! I can't follow.Please help me.What rules apply to what? Thanks and thanks for patience. Link to comment Share on other sites More sharing options...
astralaaron Posted March 20, 2012 Share Posted March 20, 2012 Hi! I can't follow.Please help me.What rules apply to what? Thanks and thanks for patience. you don't need to write UPDATE each time$res=mysql_query("UPDATE top10 SET one='$n1' WHERE id=0");("UPDATE top10 SET two='$n2' WHERE id=0");("UPDATE top10 SET three='$n3' WHERE id=0");("UPDATE top10 SET four='$n4' WHERE id=0");("UPDATE top10 SET five='$n5' WHERE id=0");("UPDATE top10 SET six='$n6' WHERE id=0");("UPDATE top10 SET seven='$n7' WHERE id=0");("UPDATE top10 SET eight='$n8' WHERE id=0");("UPDATE top10 SET nine='$n9' WHERE id=0");("UPDATE top10 SET ten='$n10' WHERE id=0"); write only one UPDATE, then the table name, then SET and then you put the fields you want to change separated by a comma like in dsonesuk's example remember this("UPDATE top10 SET 1='$n1', 2='$n2, 3='$n3', 4='$n4', 5='$n5', 6='$n6', 7='$n7', 8='$n8', 9='$n9', 10='$n10' WHERE id=0"); same rule still applies. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 20, 2012 Author Share Posted March 20, 2012 Thanks! Still, it has error. Parse error: syntax error, unexpected T_LNUMBER in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/top10.php on line 31 <?$con = mysql_connect("","","");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("", $con);$n1 = $_POST['one'];$n2 = $_POST['two'];$n3 = $_POST['three'];$n4 = $_POST['four'];$n6 = $_POST['five'];$n6 = $_POST['six'];$n7 = $_POST['seven'];$n8 = $_POST['eight'];$n9 = $_POST['nine'];$n10 = $_POST['ten'];$res=mysql_query("UPDATE top10 SET 1='$n1',top10 SET 2='$n2',top10 SET 3='$n3',top10 SET 4='$n4',top10 SET 5='$n5',top10 SET 6='$n6',top10 SET 7='$n7',top10 SET 8='$n8',top10 SET 9='$n9',top10 SET 10='$n10'WHERE id="0");if(!$res)echo mysql_error();mysql_close($con);?> Thank. Link to comment Share on other sites More sharing options...
dsonesuk Posted March 20, 2012 Share Posted March 20, 2012 Because you have gone two steps back and use numbers for column names AGAIN! and using SET multiple times within the update query AGAIN! Its not suddenly going to work by reverting back to to original problem table column naming, and update query. Use UPDATE, tablename and SET, once and only once within a update query, I repeat Use UPDATE, tablename and SET, once and only once within a update query. revert to one, two etc column names and use("UPDATE top10 SET one='$n1', two='$n2, three='$n3', four='$n4', five='$n5', six='$n6', seven='$n7', eight='$n8', nine='$n9', ten='$n10' WHERE id=0");Thats it! that ALL you had to do. Link to comment Share on other sites More sharing options...
TheCatapult Posted March 21, 2012 Author Share Posted March 21, 2012 dsoneseuk, thanks! 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 '', three='', four='', five='', six='', seven='', eight='', nine='', ten='' WHERE' at line 1 Please help! Link to comment Share on other sites More sharing options...
dsonesuk Posted March 21, 2012 Share Posted March 21, 2012 ("UPDATE top10 SET one='$n1', two='$n2', three='$n3', four='$n4', five='$n5', six='$n6', seven='$n7', eight='$n8', nine='$n9', ten='$n10' WHERE id=0"); Link to comment Share on other sites More sharing options...
TheCatapult Posted March 21, 2012 Author Share Posted March 21, 2012 But it does not write any thing in the database. I'm sad. Link to comment Share on other sites More sharing options...
dsonesuk Posted March 21, 2012 Share Posted March 21, 2012 But it does not write any thing in the database. I'm sad. This not help, are you getting any errors, i missed a single quote out in post #16, IF yes, is there a record with id value of 0 ? Also it would help if you retrieved a value for $n5, else it will fail also $n1 = $_POST['one'];$n2 = $_POST['two'];$n3 = $_POST['three'];$n4 = $_POST['four'];$n6 = $_POST['five'];$n6 = $_POST['six'];$n7 = $_POST['seven'];$n8 = $_POST['eight'];$n9 = $_POST['nine'];$n10 = $_POST['ten'];you may want set default values for variables just in case$n1 = "";$n2 = "";$n3 = "";$n4 = "";$n5 = "";$n6 = "";$n7 = "";$n8 = "";$n9 = "";$n10 = "";$n1 = $_POST['one'];$n2 = $_POST['two'];$n3 = $_POST['three'];$n4 = $_POST['four'];$n5 = $_POST['five'];$n6 = $_POST['six'];$n7 = $_POST['seven'];$n8 = $_POST['eight'];$n9 = $_POST['nine'];$n10 = $_POST['ten']; Link to comment Share on other sites More sharing options...
thescientist Posted March 21, 2012 Share Posted March 21, 2012 But it does not write any thing in the database. I'm sad. you should really start learning to debug some of this stuff on your own. the tutorials have example that show how to test for failed query's and outputting mysql_error Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.