Hello everyone 🙂
I’m a php/mysql newbie who’s stuck in a simple problem:
I have a mysql database with several tables:
bloggers
languages
etc..
bloggers table has fields like blogTitle, blogURL, language, etc…
language table has fiels like langID (which maps to language in the bloggers table), langCount, etc..
The user fills in a form and selects the language of his blog. I want to increment the value of langCount by 1 for the language that the user selected.
Here is part of code I use. For some reason it doesn't incrementthe value of langCount as expected:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "submityourblog")) {
$insertSQL = sprintf("INSERT INTO bloggers (name, email, province, city, country, bloggingSince, blogTitle, blogDescription, blogUrl, blogFeed, blogCategory, blogawards, `language`, imagefile) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['name'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['province'], "text"),
GetSQLValueString($_POST['city'], "int"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['bloggingSince'], "date"),
GetSQLValueString($_POST['blogTitle'], "text"),
GetSQLValueString($_POST['blogDescription'], "text"),
GetSQLValueString($_POST['blogUrl'], "text"),
GetSQLValueString($_POST['blogFeed'], "text"),
GetSQLValueString($_POST['blogCategory'], "text"),
GetSQLValueString($_POST['blogawards'], "text"),
GetSQLValueString($_POST['language'], "text"),
GetSQLValueString($_POST['imagefile'], "text"));
mysql_select_db($database_obc, $obc);
$Result1 = mysql_query($insertSQL, $obc) or die(mysql_error());
// UPDATE langCount Starts here
mysql_select_db($database_obc, $obc);
$query_rsLang = sprintf("SELECT langID, langCount FROM languages WHERE langID = %s", GetSQLValueString($_POST['language'], "text"));
$rsLang = mysql_query($query_rsLang, $obc) or die(mysql_error());
$row_rsLang = mysql_fetch_assoc($rsLang);
$totalRows_rsLang = mysql_num_rows($rsLang);
$varLangCounter = ($row_rsLang['langCount'] + 1);
$updateSQL = sprintf("UPDATE languages SET langCount=%s WHERE langID=%s",
GetSQLValueString($varLangCounter, "text"),
GetSQLValueString($_POST['language'], "text"));
mysql_select_db($database_obc, $obc);
$Result2 = mysql_query($updateSQL, $obc) or die(mysql_error());
// Update langCount ends here
$insertGoTo = "thankyou.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
Hope someone can help. Thanks 🙂