rowdyj81
asked on
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.
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));
}
or
$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = 'specials'";
$queryone = mysql_query($sqlone, $con);
$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = 'specials'";
$queryone = mysql_query($sqlone, $con);
ASKER
Tried both solutions, neither worked.
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);
post the value of $sqlone before running it...
$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = 'specials'";
echo $sqlone;
$queryone = mysql_query($sqlone, $con);
ASKER
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.
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.";
}
?>
$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);
-->
$sqlone = "UPDATE specials SET content = '".$content."' WHERE label = '".$specials."'";
what is nl2br?
$content = nl2br("$specials");
-->
$content = nl2br($specials);
ASKER
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.
UPDATE specials SET content = '' WHERE label = ''
nl2br adds a <br /> tag before each new line in the string.
what happens if you use this
$sqlone = "UPDATE specials SET content = '$content.' WHERE label = '$specials'";
$sqlone = "UPDATE specials SET content = '$content.' WHERE label = '$specials'";
oops, forgot to delete one .
$sqlone = "UPDATE specials SET content = '$content' WHERE label = '$specials'";
also , check the value of $content & $special at this moment...
$sqlone = "UPDATE specials SET content = '$content' WHERE label = '$specials'";
also , check the value of $content & $special at this moment...
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Woot, you're awesome man. Thank you so much.
$queryone = mysql_query("$sqlone", $con);
-->
$queryone = mysql_query($sqlone, $con);