Jump to content

Simple update question... please help


Scottyy

Recommended Posts

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..

[i][b]bloggers [/b] [/i] table has fields like [i]blogTitle[/i], [i]blogURL[/i], [i]language[/i], etc…
[i][b]language [/b] [/i] table has fiels like [i]langID [/i] (which maps to language in the bloggers table), [i]langCount[/i], etc..

The user fills in a form and selects the language of his blog.[b] I want to increment the value of langCount by 1 for the language that the user selected[/b].

Here is part of code I use. For some reason it doesn't increment the value of langCount as expected:


[code]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));
}
[/code]


Hope someone can help. Thanks
Link to comment
https://forums.phpfreaks.com/topic/19605-simple-update-question-please-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.