shiloam Posted February 11, 2011 Share Posted February 11, 2011 I really appreciate you guys. Could you guys help me out with a little syntax trouble. <?php $id=$_POST['id']; $db="prayers"; $link = mysql_connect('localhost', 'root' , ''); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Select Error: ".mysql_error()); $rt=mysql_query($query); echo mysql_error(); while($nt=mysql_fetch_array($rt)){ $result=mysql_query( $query = "SELECT howmanyprayed from prayerwall BY ". $id ."" $new_val = $row['howmanyprayed'] + 1; "INSTERT $new_val into prayerwall ( howmanyprayed) VALUES ( '$new_val')") or die("Insert Error: ".mysql_error()); mysql_close($link); ?> It's a button that's like the facebook "like" button. It's submitting a form through a button, but I'm getting this error when I submit. Parse error: syntax error, unexpected T_VARIABLE in /Applications/XAMPP/xamppfiles/htdocs/1/church@arkprayer/dafiles/prayedreceive.php on line 18 Here's the form submit button <FORM METHOD=LINK ACTION=prayedreceive.php> <INPUT TYPE=HIDDEN NAME=clickprayed value=$nt[id]> <INPUT TYPE=submit VALUE=Prayed> #$nt[id] </FORM></br></br>"; I really appreciate any help. Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/ Share on other sites More sharing options...
kenrbnsn Posted February 11, 2011 Share Posted February 11, 2011 This chunk of code is riddled with errors: <?php while($nt=mysql_fetch_array($rt)){ $result=mysql_query( $query = "SELECT howmanyprayed from prayerwall BY ". $id ."" $new_val = $row['howmanyprayed'] + 1; "INSTERT $new_val into prayerwall ( howmanyprayed) VALUES ( '$new_val')") or die("Insert Error: ".mysql_error()); mysql_close($link); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1172968 Share on other sites More sharing options...
shiloam Posted February 11, 2011 Author Share Posted February 11, 2011 Yeah I figured haha.. I'm just now picking back up php I'm no good with syntax I'm just learning. Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1172969 Share on other sites More sharing options...
shiloam Posted February 11, 2011 Author Share Posted February 11, 2011 Yea I took a look at it I didn't see how bad it was. I cleaned it up a bit... If it's too far off then tell me I'll mark solved. Thank you. <?php $id=$_POST['id']; $db="prayers"; $link = mysql_connect('localhost', 'root' , ''); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Select Error: ".mysql_error()); echo mysql_error(); $query = "SELECT * from prayerwall BY $id"; $rt=mysql_query($query); echo mysql_error(); while($nt=mysql_fetch_array($rt)){ $new_val = $row['howmanyprayed'] + 1; "INSERT $new_val into prayerwall ( howmanyprayed) VALUES ( '$new_val')" or die("Insert Error: ".mysql_error()); mysql_close($link); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1172973 Share on other sites More sharing options...
Pikachu2000 Posted February 11, 2011 Share Posted February 11, 2011 It isn't throwing any php parse errors, but there are SQL syntax issues. $query = "SELECT * from prayerwall BY $id"; // do WHAT by $id ? ? ? // This query string is just out there in the middle of nowhere, not assigned to a variable or anything . . . "INSERT $new_val into prayerwall ( howmanyprayed) VALUES ( '$new_val')" or die("Insert Error: ".mysql_error()); // The syntax is wrong too. $example = "INSERT INTO `table` (`field1`, `field2`) VALUES ( 'string1', 'string2')"; Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1172981 Share on other sites More sharing options...
shiloam Posted February 11, 2011 Author Share Posted February 11, 2011 Maybe it would help if I explained a little.. There's a button on the other page that has the id of the post in it's form. It's invisible, and in the button. When they hit the "I prayed button". It sends a form to prayedreceive.php. Where it's selecting the one of the id. And then the main function is to add one to the field "howmanyprayed".. so.. [----] #4 prayed! They hit the button.. [----] #5 prayed! <?php $id=$_POST['id']; $db="prayers"; $link = mysql_connect('localhost', 'root' , ''); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Select Error: ".mysql_error()); echo mysql_error(); $query = "SELECT howmanyprayed from prayerwall WHERE id = $id"; //This is what I was meaning to do haha. $rt=mysql_query($query); echo mysql_error(); while($nt=mysql_fetch_array($rt)){ $new_val = $row['howmanyprayed'] + 1; $update = mysql_query( "INSERT INTO 'prayerwall' ('howmanyprayed') VALUES ('$new_val')"; } ?> Is this looking any better? I'm winging it here. Thank you I appreciate the help, also why do you hate everything? Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1173009 Share on other sites More sharing options...
Pikachu2000 Posted February 11, 2011 Share Posted February 11, 2011 This is not valid syntax for a SQL query: SELECT howmanyprayed from prayerwall BY $id; It should be along the lines of: SELECT howmanyprayed from prayerwall WHERE `some_field` = $id"; What is the significance of $id? Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1173011 Share on other sites More sharing options...
shiloam Posted February 11, 2011 Author Share Posted February 11, 2011 Ahh ok I'm getting it now. I needed $query = "SELECT howmanyprayed from prayerwall WHERE id = $id"; There's an auto-increment set on each prayer posted. Each prayer has an unique number value for the howmanyprayed in mysql, due to how many people press the button. So it is selecting the $id equeal to the id that they pressed. Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1173015 Share on other sites More sharing options...
Pikachu2000 Posted February 11, 2011 Share Posted February 11, 2011 OK, then that query is probably what you're looking for. Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1173021 Share on other sites More sharing options...
shiloam Posted February 11, 2011 Author Share Posted February 11, 2011 Yea that was part of it. For some reason I'm getting this error. Thanks for all the help man, I appreciate it. 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 '' at line 1 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/1/church@arkprayer/dafiles/prayedreceive.php on line 18 <?php $id=$_POST['id']; $db="prayers"; $link = mysql_connect('localhost', 'root' , ''); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Select Error: ".mysql_error()); echo mysql_error(); $query = "SELECT howmanyprayed from prayerwall WHERE id = $id"; $rt=mysql_query($query); echo mysql_error(); while($nt=mysql_fetch_array($rt)){ $new_val = $row['howmanyprayed'] + 1; $update = "INSERT INTO prayerwall (howmanyprayed) VALUES ('$new_val')"; } ?> Also you didn't answer the question of why you hate everything ha. Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1173023 Share on other sites More sharing options...
Pikachu2000 Posted February 11, 2011 Share Posted February 11, 2011 If all you want to do is increment the number in the `howmanyprayed` field, all you should need to do is run an UPDATE query similar to this one. UPDATE `prayerwall` SET `howmanyprayed` = `howmanyprayed` + 1 WHERE `id` = $id Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1173025 Share on other sites More sharing options...
shiloam Posted February 11, 2011 Author Share Posted February 11, 2011 Dude thanks so much, it's not updating, but it's also not giving me any errors. I'm thinking it has to do with my form or something. I'll mess around with it. Also there's hope bro. I used to be atheist and doin drugs. Religion sucks, but God is real. He's straight up real dude, I dare you to try being real with Him and talking to Him. Later Quote Link to comment https://forums.phpfreaks.com/topic/227403-a-little-syntax-help-please/#findComment-1173036 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.