MySQL Update Statement Syntax / PDO

I recently added PDO support to our server.  Not surprisingly, some php scripts that worked before this update are now glitching up.  I have a very simple script that updates a field in a database when a form is submitted.  This SQL statement works when I execute it in phpMyAdmin.  When the form is submitted, it does not work; however, I don't get an error message. Everything in the targeted field in the database gets erased.  Nothing gets updated.  

Here is my code.  Anyone have an idea what's going on?  I know this has to be something stupid that I'm missing.
$sqlone = "UPDATE specials SET content = '$content' WHERE label = 'specials'";
$queryone = mysql_query("$sqlone", $con);
if(!$queryone){
die(mysql_error($con));
}

Open in new window

rowdyj81Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
use

$queryone = mysql_query("$sqlone", $con);
-->
$queryone = mysql_query($sqlone, $con);
0
HainKurtSr. System AnalystCommented:
or

$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = 'specials'";
$queryone = mysql_query($sqlone, $con);
0
rowdyj81Author Commented:
Tried both solutions, neither worked.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

HainKurtSr. System AnalystCommented:
what does $content have?
post the value of $sqlone before running it...

$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = 'specials'";
echo $sqlone;
$queryone = mysql_query($sqlone, $con);
0
rowdyj81Author Commented:
This is the SQL statement that is printed:
UPDATE specials SET content = '' WHERE label = 'specials'

For whatever reason, $specials seems to have no value.  Everything looks right in my form also.  I even tried passing the variable through the url.  The file is called poster.php so I tried this:

poster.php?&specials=test

Still nothing.  I'm going to attach the full code.
<?php
require("config.php");

$specials = $_GET['specials'];
$content = nl2br("$specials");

$con = mysql_connect("$dbhost", "$dbuser", "$dbpass");
if (!con){
	die(mysql_error($con));
}

mysql_select_db("$dbname", $con);

$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = 'specials'";
echo $sqlone;
$queryone = mysql_query($sqlone, $con);
if(!$queryone){
	echo "Query failed.<br />";
	die(mysql_error($con));
}
else{
	echo "Thank you.  Your changes have been made successfully.<br /><a href=\"admin.php\">Click here</a> to go back to the admin panel.";
}
?>

Open in new window

0
HainKurtSr. System AnalystCommented:
$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = 'specials'";
-->
$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = '".$specials."'";

what is nl2br?

$content = nl2br("$specials");
-->
$content = nl2br($specials);
0
rowdyj81Author Commented:
Still no luck.  This is my SQL now:
UPDATE specials SET content = '' WHERE label = ''

nl2br adds a <br /> tag before each new line in the string.
0
HainKurtSr. System AnalystCommented:
what happens if you use this

$sqlone = "UPDATE specials SET content = '$content.' WHERE label = '$specials'";
0
HainKurtSr. System AnalystCommented:
oops, forgot to delete one .

$sqlone = "UPDATE specials SET content = '$content' WHERE label = '$specials'";

also , check the value of $content & $special at this moment...
0
rowdyj81Author Commented:
This is the output I get:
content =
specials =
UPDATE specials SET content = '' WHERE label = ''

It's weird.  I have no idea why it's behaving this way.  Another, thing it's no longer erasing the field in the database.  It's not affecting the database at all now.
0
HainKurtSr. System AnalystCommented:
thats good ;) somehow you are not passing the values to the page... code looks ok, but you need to pass the values...

so you used this

$sqlone = "UPDATE specials SET content = '$content' WHERE label = '$specials'";

and got these

content =
specials =
UPDATE specials SET content = '' WHERE label = ''

now replace these lines with

$specials = $_GET['specials'];
$content = nl2br("$specials");
-->
$specials = $_REQUEST['specials'];
$content = nl2br("$specials");

and see what you get...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rowdyj81Author Commented:
Woot, you're awesome man.  Thank you so much.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.