PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
andrade1
Forum Newbie
Posts: 14 Joined: Fri Apr 18, 2008 9:16 am
Post
by andrade1 » Tue Jun 03, 2008 4:31 pm
Hi
I am trying to use the serialize function but I think I have something incorrect because I am getting a blank page when I submit my form.
Code: Select all
//request:
$request = serialize($_POST['request']);
$query=INSERT INTO request VALUES('$request');
mysql_query($query) or die (mysql_error());
$query = "SELECT * from Request";
$result = mysql_query($query);
while (mysql_fetch_array($result, MYSQL_ASSOC))
{
$request = unserialize($row['request']);
foreach ($request as $value)
{
echo "$value -";
}
echo "<br/>\n";
}
mysql_query($query) or die (mysql_error());
//Run Insert Query
$query = "INSERT INTO Log (DateRcvd, OrigDept, OrigContact, RespOffice, Request, contents, refer, deadline, GivenTo, stats, outcome, notes, complete)
VALUES ('$drcvd', '$ODT', '$ocont', '$RSP', '$contents', '$REF', '$deadline', '$request', '$givento', '$status', '$outcome', '$notes', '$completed')";
$result = mysql_query($query);
Last edited by
Weirdan on Tue Jun 03, 2008 4:37 pm, edited 1 time in total.
Reason: php tags
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Tue Jun 03, 2008 4:38 pm
yeah, you forgot to quote your query - pretty easy to spot with syntax highlighting turned on, eh?
andrade1
Forum Newbie
Posts: 14 Joined: Fri Apr 18, 2008 9:16 am
Post
by andrade1 » Tue Jun 03, 2008 6:09 pm
Hi
I added the missing parenthesis in and I am receiving:
Column count doesn't match value count at row 1
Code: Select all
//request:
$request = serialize($_POST['request']);
$query="INSERT INTO Log VALUES('$Request')";
mysql_query($query) or die (mysql_error());
$query = "SELECT Request from Log";
$result = mysql_query($query);
while (mysql_fetch_array($result, MYSQL_ASSOC))
{
$request = unserialize($row['request']);
foreach ($request as $value)
{
echo "$value -";
}
echo "<br/>\n";
}
mysql_query($query) or die (mysql_error());
my database is Log, the array is request, and the name of the field the data is going to in the database is Request
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Wed Jun 04, 2008 1:26 am
You need to escape the serialized data with mysql_real_escape_string() function.
andrade1
Forum Newbie
Posts: 14 Joined: Fri Apr 18, 2008 9:16 am
Post
by andrade1 » Wed Jun 04, 2008 7:49 am
how would I use the escape string function? Currently with the code I have below I am receiving null (default value) in the Request field instead of the values of the checkboxes.
Code: Select all
//Checkbox array: request
$request = serialize($_POST['request']);
$query= "INSERT INTO Log (Request) VALUES('$request')";
mysql_query($query) or die (mysql_error());
$query = "SELECT Request from Log";
$result = mysql_query($query);
while (mysql_fetch_array($result, MYSQL_ASSOC))
{
$request = unserialize($row['request']);
foreach ($request as $value)
{
echo "$value -";
}
echo "<br/>\n";
}
mysql_query($query) or die (mysql_error());
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Wed Jun 04, 2008 7:53 am
can you echo the serialized string for us?
andrade1
Forum Newbie
Posts: 14 Joined: Fri Apr 18, 2008 9:16 am
Post
by andrade1 » Wed Jun 04, 2008 8:13 am
the echo of the serialize function is:
N;