[Question] PHP, MySQL Insert...

5 posts Page 1 of 1
Contributors
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

[Question] PHP, MySQL Insert...
Scottie1972
here is my question.

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
        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)

after submitting this is all that is returned.
notice all the "&" are missing
Code: Select all
        Dim encoding As New ASCIIEncoding
        Dim  postData  = \" block=\"   snipBlock.Replace(\" \", \" \").ToString
api.php looks like this
only the (case "1") is being used.
Code: Select all
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;
}
any ideas on what is going wrong?
apache2.2
php v5.2.17
MySQL v5.1
Image
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: [Question] PHP, MySQL Insert...
Filip
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 :D
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

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.
Image
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

here are some visuals to help you.
Image

Image
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.
Image
User avatar
Scottie1972
Codenstuff Elite
Codenstuff Elite
Posts: 953
Joined: Thu Jan 14, 2010 5:48 am

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
Image
5 posts Page 1 of 1
Return to “Help & Support”