bruceb Posted July 10, 2010 Share Posted July 10, 2010 Hi Everyone, I have a POST form which collects data in text input fields and sends them to php file for string joining. Then, the complete is to be inserted into MySQL. If I equate $grplist to only one of the $npaa, $nxxa, or $blocka then it wall works fine. However, the moment I try to join all three below with .= or + or . Mysql just gives me errors that it's wrong syntax for MySQL. I can't believe I can't joing two strings together. I even tried to change these variables to strings first using (string) but it was no use. Can someone please tell me what is wrong with $grplist variable? $npaa = "('$_POST[anpa]')"; $nxxa = "('$_POST[anxx]')"; $blocka = "('$_POST[ablock]')"; $grplist = $npaa; $grplist .= $nxxa; $grplist .= $blocka; $sql="REPLACE INTO findmefollow (grpnum, strategy, grptime, grppre, grplist, annmsg_id, postdest, dring, needsconf, remotealert_id, toolate_id, ringing, pre_ring) VALUES ('$_POST[grpnum]','ringall','$_POST[grptime]','$_POST[grppre]',$grplist,'0','$_POST[postdest]','','','0','0','Ring','$_POST[pre_ring]')"; Thanks a lot Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/ Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2010 Share Posted July 10, 2010 Paste the error in here. It's probably telling you exactly where the problem is. Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1083953 Share on other sites More sharing options...
unidox Posted July 10, 2010 Share Posted July 10, 2010 $sql="REPLACE INTO `findmefollow` ('grpnum', 'strategy', 'grptime', 'grppre', 'grplist', 'annmsg_id', 'postdest', 'dring', 'needsconf', 'remotealert_id', 'toolate_id', 'ringing', 'pre_ring') VALUES ('$_POST[grpnum]','ringall','$_POST[grptime]','$_POST[grppre]',$grplist,'0','$_POST[postdest]','','','0','0','Ring','$_POST[pre_ring]')"; Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1083962 Share on other sites More sharing options...
bruceb Posted July 10, 2010 Author Share Posted July 10, 2010 In the three fields of $anpa, $anxx, and $ablock of the php/html form, I put 444, 555, and 666. The error comes as: Error: 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 '('555')('6666'),'0','ext-local,vmb2000,1','','','0','0','Ring','0')' at line 3 Thanks Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084053 Share on other sites More sharing options...
BizLab Posted July 10, 2010 Share Posted July 10, 2010 is there a reason you aren't using PHP to join the strings with a simple concatenation action?: $final string = $_POST['new_string'] . $existing_string_var; // the existing string is pulled from the DB prior to this... Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084059 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2010 Share Posted July 10, 2010 Why are you putting parentheses around the values: <?php $npaa = "('$_POST[anpa]')"; $nxxa = "('$_POST[anxx]')"; $blocka = "('$_POST[ablock]')"; ?> Just use: <?php $npaa = $_POST[anpa]; $nxxa = $_POST[anxx]; $blocka = $_POST[ablock]; ?> Ken Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084061 Share on other sites More sharing options...
bruceb Posted July 10, 2010 Author Share Posted July 10, 2010 Thanks for the help but this fixed it: $npaa = "$_POST[anpa]"; $nxxa = "$_POST[anxx]"; $blocka = "$_POST[ablock]"; $grplist = "'".$npaa.$nxxa.$blocka."'"; However, now once the form is submitted I want to come back to my form page. Do I have to put some code in the php file to go back to form.php or in the form.php html file? Thanks Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084075 Share on other sites More sharing options...
BizLab Posted July 10, 2010 Share Posted July 10, 2010 Thanks for the help but this fixed it: $npaa = "$_POST[anpa]"; $nxxa = "$_POST[anxx]"; $blocka = "$_POST[ablock]"; $grplist = "'".$npaa.$nxxa.$blocka."'"; However, now once the form is submitted I want to come back to my form page. Do I have to put some code in the php file to go back to form.php or in the form.php html file? Thanks Take the extra quotes off the variable there -> change "'" to ' or " If you want to return to the same page (stay on it) you will have to include the form and it's processors on the page in which you are trying to remain. In the form action attribute place: action="<?php $_SERVER['PHP_SELF']; ?>" which will submit the form to the same page it was coded on. Be sure to put all processing code on that page with a condition like: if(isset($_POST['form_var'])){ // process the form } NOTE: don't use the isset($_POST['submit']) method, as IE is unreliable with the submission of the actual "submit" parameter. Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084079 Share on other sites More sharing options...
BizLab Posted July 10, 2010 Share Posted July 10, 2010 Also.. take off the leading and trailing . on your variable it should be $grplist = "$npaa.$nxxa.$blocka'"; Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084081 Share on other sites More sharing options...
bruceb Posted July 10, 2010 Author Share Posted July 10, 2010 Thanks for the tips. I don't have the php file in the php/html files as it will expose MySQL password. This is what I have currently: <form name="myform" action="follow_ins.php" method="POST"> Anyway to get to stay on this page? Maybe I do an include for the follow follow_ins.php up above in the html file before the form starts? Thanks Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084083 Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2010 Share Posted July 10, 2010 NOTE: don't use the isset($_POST['submit']) method, as IE is unreliable with the submission of the actual "submit" parameter. There, I fixed that up for ya! Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084090 Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2010 Share Posted July 10, 2010 What is the expected data type (string, integer, etc.) for each of those three form fields, and why are you trying to store them in one database field? Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084091 Share on other sites More sharing options...
bruceb Posted July 10, 2010 Author Share Posted July 10, 2010 Expected data type is varchar(255) so it's string. I am still stuck as to how to submit form and stay on the same page or refresh the page. Can you please explain? Thanks Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084160 Share on other sites More sharing options...
bruceb Posted July 10, 2010 Author Share Posted July 10, 2010 This is how I call my php file currently: <form name="myform" action="follow_ins.php" method="POST"> How can I change action part so that after submit I refresh the same html or php page rather than going to another page? I want to stay on the same page and at the same time I don't want to expose my php code so the code resides on follow_ins.php. Thanks Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084178 Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2010 Share Posted July 10, 2010 Just change it to action="" and it will submit to itself. What do you mean "expose your php code"? It doesn't show up in the page source, you know. Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084190 Share on other sites More sharing options...
bruceb Posted July 10, 2010 Author Share Posted July 10, 2010 I am calling another file so I am not submitting to itself. I want to keep the files clean and organised so I am calling follow_ins.php file to accept the submission. Is there something I can put in the follow_ins.php to go back to my initial file? Thanks Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084196 Share on other sites More sharing options...
Pikachu2000 Posted July 10, 2010 Share Posted July 10, 2010 I don't know exactly what you're trying to accomplish, so I can't really make a recommendation with any confidence. Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084198 Share on other sites More sharing options...
myrddinwylt Posted July 10, 2010 Share Posted July 10, 2010 If you are doing what I do sometimes: Posting to another page then forwarding the user off that page to another page on completion Then you can use the following code for a redirect in PHP header('location: /index.php'); This can only be used if nothing has been printed to the page. If something has been printed to the page, simple echo out some javascript for the redirect. $script = '<script type="text/javascript">location.replace(\'/index.php\');</script>'; echo $script; Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084202 Share on other sites More sharing options...
bruceb Posted July 10, 2010 Author Share Posted July 10, 2010 Where is the: header('location: /index.php'); supposed to be in the .php file? Thanks Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084217 Share on other sites More sharing options...
bruceb Posted July 10, 2010 Author Share Posted July 10, 2010 Thanks guys. This did the trick: header('location: /index.php'); Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084218 Share on other sites More sharing options...
BizLab Posted July 11, 2010 Share Posted July 11, 2010 your form's "action" attribute can be set to <?php $_SERVER['PHP_SELF']; ?>, and place the form processing code above the form. This will keep you on the same page after submitting. ALSO: i had a typo in my other post: $grplist = "$npaa.$nxxa.$blocka'"; should be $grplist = "$npaa.$nxxa.$blocka"; NOTE: don't use the isset($_POST['submit']) method, as IE is unreliable with the submission of the actual "submit" parameter. There, I fixed that up for ya! - WORD. lol But just to clarify, i was talking about checking to see if the submit event had been fired with: if($_POST['submit']){ // do stuff becuase they submitted the form } Doesn't work well. i use a form variable that is REQUIRED for submission (through validation) to check for successful submission. Link to comment https://forums.phpfreaks.com/topic/207324-i-cant-believe-i-cant-join-two-strings-together-in-two-hours/#findComment-1084410 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.