Jump to content

I can't believe I can't join two strings together in two hours :-(


bruceb

Recommended Posts

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
Share on other sites

$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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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! :P

 

- 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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.