[Question] PHP, MySQL Insert...
5 posts
Page 1 of 1
here is my question.
I have a project that inserts encoded string data via a PHP script.
TextBox5.Text
Button_Click()
NOTE: 'Replace("&", "+").ToString = without the Replace() function the code just returns (\") and errors out.
notice all the "&" are missing
only the (case "1") is being used.
apache2.2
php v5.2.17
MySQL v5.1
I have a project that inserts encoded string data via a PHP script.
TextBox5.Text
Code: Select all
Dim encoding As New ASCIIEncoding
Dim postData = "&block=" & snipBlock.ToString
Button_Click()
NOTE: 'Replace("&", "+").ToString = without the Replace() function the code just returns (\") and errors out.
Code: Select all
after submitting this is all that is returned. Dim snipBlock As String = TextBox5.Text.Replace("&", "+")
Dim encoding As New ASCIIEncoding
Dim postData += "&block=" & snipBlock.Replace("&", "+").ToString
Dim data As Byte() = encoding.GetBytes(postData.ToString)
' Prepare web request...
Dim myRequest As HttpWebRequest = DirectCast(WebRequest.Create("http://www.website.com/api.php?opt=" & opts.ToString), HttpWebRequest)
myRequest.Method = "POST"
myRequest.ContentType = "application/x-www-form-urlencoded"
myRequest.ContentLength = data.Length
Dim newStream As Stream = myRequest.GetRequestStream()
' Send the data.
newStream.Write(data, 0, data.Length)
newStream.Close()
'' Get the response.
Dim response As WebResponse = myRequest.GetResponse()
Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
newStream = response.GetResponseStream()
Dim reader As New StreamReader(newStream)
Dim responseFromServer As String = reader.ReadToEnd()
Console.WriteLine(responseFromServer)
notice all the "&" are missing
Code: Select all
api.php looks like this Dim encoding As New ASCIIEncoding
Dim postData = \" block=\" snipBlock.Replace(\" \", \" \").ToString
only the (case "1") is being used.
Code: Select all
any ideas on what is going wrong?switch($_GET['opt']) {
case "0":
break;
case "1":
$snip_block = addslashes($_POST['block']); //mysql_real_escape_string($_POST['block']);
mysql_query("INSERT INTO test (block_code) VALUES ('".$snip_block."')") or die(mysql_error());
echo $snip_block;
break;
}
apache2.2
php v5.2.17
MySQL v5.1
Do you get any errors or data isn't inserted into db?
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo
visioncr0 wrote:Do you get any errors or data isn't inserted into db?no errors at all.
the data does get inserted. just the "&" character is missing from the data after insertion.
here are some visuals to help you.
not only are all the " & " missing, but it seemed to have replaced all the " & " with " " empty spaces.
and I did not code in a replace() function to replace any character with a blank space.
not only are all the " & " missing, but it seemed to have replaced all the " & " with " " empty spaces.
and I did not code in a replace() function to replace any character with a blank space.
ok this issue has been resolved!
Changed from Framework 4.5 to Framework 4,
Reference System.Web,
Imports System.Web
changed:
Dim snipBlock As String = HttpUtility.UrlEncode(TextBox5.Text)
fixed!
thanks #CodenStuff
Changed from Framework 4.5 to Framework 4,
Reference System.Web,
Imports System.Web
changed:
Dim snipBlock As String = HttpUtility.UrlEncode(TextBox5.Text)
fixed!
thanks #CodenStuff
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023