Debt Help | Babb Fest | Loans | Mortgages | Loans
I need help with some PHP scripting [Archive] - ZGeek

PDA

View Full Version : I need help with some PHP scripting


Pirate
02-03-2006, 09:13 AM
This should be a simple one. But it's got me stumped.

I've got this SMS sending script which I use at work (thanks heaps to those who helped me get this going). I've learnt a bit since then and now the script logs everything into a mysql database which has filters, search etc.. its fully sick.. *proud*

Anyway, I just found and damn bug and I am not sure how to fix it.

This is the portion of the script I use to dump the data into the database.mysql_connect("localhost", "#####", "####") or die(mysql_error());
mysql_select_db("smslog") or die(mysql_error());

mysql_query("INSERT INTO thelog (txt_Phone, txt_Ref, date_time, DTnumber, txt_Message) VALUES ('$strAddress', '$strReference', '$date_time', '$strDTReference', '$strContent' ) ");The problem lies in the $strContent. It takes normal text fine, but when someone uses a ' ie: Tom's it spits the dummy.

Anyone know the cause?

btwong
02-03-2006, 09:17 AM
the problem is your ' in the text...

you need to make a function or something that makes entries and data sql friendly. Like parse the data and any ' that it finds, it adds another ' on either side (so it ends up like Tom'''s).

Spingo
02-03-2006, 09:33 AM
Behold! The addslashes function! (http://www.php.net/manual/en/function.addslashes.php)

You might want to check stripslashes too!

btwong
02-03-2006, 09:39 AM
Behold! The addslashes function! (http://www.php.net/manual/en/function.addslashes.php)

You might want to check stripslashes too!

thats right, you have to add \'s... i was in my ASP mode, and i accidently left my PHP/Javascript brain at home today....

god damn joint last nite... forgot to put it in my bag!

Pirate
02-03-2006, 09:42 AM
I love you guys. I will go play with that function and see what I can get it to do :)

Pirate
02-03-2006, 10:10 AM
This what I did.. thanks again guys. mysql_connect("localhost", "####", "#####") or die(mysql_error());
mysql_select_db("smslog") or die(mysql_error());

$nice_content = addslashes(trim($_POST["txt_Message"]));

mysql_query("INSERT INTO thelog (txt_Phone, txt_Ref, date_time, DTnumber, txt_Message) VALUES ('$strAddress', '$strReference', '$date_time', '$strDTReference', '$nice_content' ) ")
or die(mysql_error());