Jump to content

sir_amin

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sir_amin's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. NO these are NOT to be editable,but all that i want is if user tried to insert a row that is in the database alert user and say: YOU CAN NOT ADD THESE INFORMATION TWICE. my table primary keys are: PRIMARY KEY (`lid`,`tid`,`termid`,`gradeid`), i want a select query with where clause for return this if exist with inserted data in form. note: this is a INSERT page and is not intended to edit data. very grateful for your fast replies
  2. another question: how can i avoid from inserting duplicated data ? i changed my TERM_LESSON table to: CREATE TABLE IF NOT EXISTS `term_lesson` ( `lid` int(5) NOT NULL, `tid` int(5) NOT NULL, `termid` int(3) NOT NULL, `gradeid` int(1) NOT NULL, `display` int(1) NOT NULL, PRIMARY KEY (`lid`,`tid`,`termid`,`gradeid`) ) ENGINE=MyISAM ; and this code worked for me : if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $lid = GetSQLValueString($_POST['lid'], "int"); $tid =GetSQLValueString($_POST['tid'], "int"); $termid =GetSQLValueString($_POST['termid'], "int"); $display =GetSQLValueString($_POST['display'], "int"); $insertValues = array(); foreach ($_POST['gradeid'] as $gradeid) { $insertValues[] = sprintf("(%s, %s, %s, %s, %s )", $lid,$tid,$termid,$display,GetSQLValueString($gradeid, "int")); } mysql_select_db($database_register, $register); //Create ONE query to insert all the records $insertSQL = "INSERT INTO term_lesson (lid, tid, termid, display, gradeid) VALUES " . implode(', ', $insertValues); $Result1 = mysql_query($insertSQL, $register) or die(mysql_error()); i was avoiding duplicate data in database by (redirecting user to a page to show a message for duplicating data inserted) : // *** Redirect if row(s) exists $MM_flag="MM_insert"; if (isset($_POST[$MM_flag])) { $MM_dupKeyRedirect="lesson_term_exist.php"; $loginUsername = $_POST['lid']; $lesson_tid = $_POST['tid']; $lesson_term = $_POST['termid']; $lesson_grade = $_POST['gradeid']; $LoginRS__query = sprintf("SELECT lid FROM term_lesson WHERE lid=%s AND tid=%s AND termid=%s ", GetSQLValueString($loginUsername, "int"), GetSQLValueString($lesson_tid, "int"), GetSQLValueString($lesson_term, "int")); mysql_select_db($database_register, $register); $LoginRS=mysql_query($LoginRS__query, $register) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); //if there is a row in the database, can not add the requested data if($loginFoundUser && $lesson_tid && $lesson_term && $lesson_grade ){ $MM_qsChar = "?"; //append the data to the redirect page if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&"; $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername; header ("Location: $MM_dupKeyRedirect"); exit; } } is there any way for this code to check this ROWS OF DATA that is inserted?
  3. dear mjdamato your code worked too and even faster thank you too very much.
  4. it solved my problem.i really appreciate your attention to my problem, thank you very very much:X
  5. sorry i putted them in code block but.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" method="post" id="form1"> <table align="center"> <tr valign="baseline"> <td align="right">LID</td> <td"> <input name="lid[]" type="text" id="lid[]" value="<?php echo $row_rslesson['lid']; ?>" size="32" readonly="readonly" /> </td> </tr> <td >GRADE</td> <td > <?php do { ?> <input name="gradeid[]" type="checkbox" id="gradeid[]" value="<?php echo $row_rstotalgrade['gradeid']; ?>" /> <label for="gradeid[]"></label> <?php echo $row_rstotalgrade['gname']; ?><br /> <?php } while ($row_rstotalgrade = mysql_fetch_assoc($rstotalgrade)); ?></td> <tr valign="baseline"> <td style="text-align: center"></td> <td align="right"><input type="submit" value="submit" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> </body> </html> ?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { foreach ($_POST['gradeid'] as $i) { $insertSQL = sprintf("INSERT INTO term_lesson (lid, gradeid) VALUES (%s, %s)", GetSQLValueString($_POST['lid'], "int"), GetSQLValueString($i, "int")); mysql_select_db($database_register, $register); $Result1 = mysql_query($insertSQL, $register) or die(mysql_error()); } $insertGoTo = "lesson_term_added.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_register, $register); $query_rstotalgrade = "SELECT * FROM grade"; $rstotalgrade = mysql_query($query_rstotalgrade, $register) or die(mysql_error()); $row_rstotalgrade = mysql_fetch_assoc($rstotalgrade); $totalRows_rstotalgrade = mysql_num_rows($rstotalgrade); ?> help me plz
  6. hello there i have a form for submiting data into mysql table with the name of TERM_LESSON table in this form i have a sets of checkboxes that came from a table with the name GRADE these are my two tables: TERM_LESSON CREATE TABLE IF NOT EXISTS `term_lesson` ( `lid` int(5) NOT NULL, `gradeid` int(1) NOT NULL, PRIMARY KEY (`lid`,`gradeid`) ) ENGINE=MyISAM ; GRADE CREATE TABLE IF NOT EXISTS `grade` ( `gradeid` int(11) NOT NULL AUTO_INCREMENT, `gname` varchar(40) NOT NULL, PRIMARY KEY (`gradeid`) ) ENGINE=MyISAM AUTO_INCREMENT=0 ; and this is my form: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form action="<?php echo $editFormAction; ?>" method="post" id="form1"> <table align="center"> <tr valign="baseline"> <td align="right">LID</td> <td"> <input name="lid[]" type="text" id="lid[]" value="<?php echo $row_rslesson['lid']; ?>" size="32" readonly="readonly" /> </td> </tr> <td >GRADE</td> <td > <?php do { ?> <input name="gradeid[]" type="checkbox" id="gradeid[]" value="<?php echo $row_rstotalgrade['gradeid']; ?>" /> <label for="gradeid[]"></label> <?php echo $row_rstotalgrade['gname']; ?><br /> <?php } while ($row_rstotalgrade = mysql_fetch_assoc($rstotalgrade)); ?></td> <tr valign="baseline"> <td style="text-align: center"></td> <td align="right"><input type="submit" value="submit" /></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1" /> </form> </body> </html> i want to make a TABLE ROW in TERM_LESSON for every checkboxes that is selected by user with same LID in form like: (for 2 chekbox seledted) lid gradeid 11 , 1 11 , 2 and this is my php code for doing that: <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { foreach ($_POST['gradeid'] as $i) { $insertSQL = sprintf("INSERT INTO term_lesson (lid, gradeid) VALUES (%s, %s)", GetSQLValueString($_POST['lid'], "int"), GetSQLValueString($i, "int")); mysql_select_db($database_register, $register); $Result1 = mysql_query($insertSQL, $register) or die(mysql_error()); } $insertGoTo = "lesson_term_added.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_register, $register); $query_rstotalgrade = "SELECT * FROM grade"; $rstotalgrade = mysql_query($query_rstotalgrade, $register) or die(mysql_error()); $row_rstotalgrade = mysql_fetch_assoc($rstotalgrade); $totalRows_rstotalgrade = mysql_num_rows($rstotalgrade); ?> but when i submit the form i face to this error : Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11 Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11 Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11 Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11 Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11 Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11 Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11 Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\wamp\www\register\admin\add_lesson_term.php on line 11 Column 'lid' cannot be null i appreciate any idea. with prior thanks
  7. hello there i want to update multiple rows which comes from a dynamic table in Dreamweaver CS5 (a loop in php) here is my Mysql table : CREATE TABLE `register`.`s_lessons` ( `lid` int( 5 ) NOT NULL , `sid` int( 9 ) NOT NULL , `term` int( 5 ) NOT NULL , `tid` int( 5 ) NOT NULL , `point` double NOT NULL DEFAULT '0', PRIMARY KEY ( `lid` , `sid` , `term` ) , KEY `tid` ( `tid` ) , KEY `point` ( `point` ) ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_persian_ci; and this is my page source code: <?php require_once('../Connections/register.php'); ?> <?php session_start(); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $colname1_rs1 = "-1"; if (isset($_GET['term'])) { $colname1_rs1 = $_GET['term']; } $colname_rs1 = "-1"; if (isset($_GET['lid'])) { $colname_rs1 = $_GET['lid']; } $colname2_rs1 = "-1"; if (isset($_SESSION['tid'])) { $colname2_rs1 = $_SESSION['tid']; } mysql_select_db($database_register, $register); $query_rs1 = sprintf("SELECT s_lessons.sid, s_lessons.lid, s_lessons.term, s_lessons.tid, s_lessons.point FROM s_lessons WHERE s_lessons.lid = %s AND s_lessons.term = %s AND s_lessons.tid = %s", GetSQLValueString($colname_rs1, "int"),GetSQLValueString($colname1_rs1, "int"),GetSQLValueString($colname2_rs1, "int")); $rs1 = mysql_query($query_rs1, $register) or die(mysql_error()); $row_rs1 = mysql_fetch_assoc($rs1); $totalRows_rs1 = mysql_num_rows($rs1); $count=mysql_num_rows($rs1); $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } for ($j = 0, $len = count($_POST['lid']); $j < $len; $j++) { if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE s_lessons SET point=%s WHERE tid=%s, lid=%s, sid=%s, term=%s", GetSQLValueString($_POST['point'] [$j], "double"), GetSQLValueString($_SESSION['tid'] [$j], "int"), GetSQLValueString($_POST['lid'] [$j], "int"), GetSQLValueString($_POST['sid'] [$j], "int"), GetSQLValueString($_POST['term'] [$j], "int")); mysql_select_db($database_register, $register); $Result1 = mysql_query($updateSQL, $register) or die(mysql_error()); } $updateGoTo = "student_lists.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="keywords" content="" /> <meta name="description" content="" /> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>سیستم پیش انتخاب واحد</title> <link href="styles/style.css" rel="stylesheet" type="text/css" media="screen" /> <link href="styles/in_styles.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="wrapper"> <div id="header-wrapper"> </div> <!-- end #header --> <div id="page"> <div id="page-bgtop"> <div id="page-bgbtm"> <div id="content"> <div class="post"> <div style="clear: both;"> <form name="form1" id="form1" method="post" action="<?php echo $editFormAction; ?>"> <table border="1" align="center"> <tr> <th>Student ID</th> <th>Lesson ID</th> <th>Semester</th> <th>Point</th> </tr> <?php do { ?> <tr> <td class="data"><label for="sid[]"></label> <input name="sid[]" type="text" id="sid[]" value="<?php echo $row_rs1['sid']; ?>" size="9" readonly="readonly" /></td> <td class="data"><label for="lid[]"></label> <input name="lid[]" type="text" id="lid[]" value="<?php echo $row_rs1['lid']; ?>" size="5" readonly="readonly" /></td> <td class="data"><label for="term[]"></label> <input name="term[]" type="text" id="term[]" value="<?php echo $row_rs1['term']; ?>" size="4" readonly="readonly" /></td> <td><label for="point[]"></label> <input name="point[]" type="text" id="point[]" value="<?php echo $row_rs1['point']; ?>" size="4" /> </tr> <?php } while ($row_rs1 = mysql_fetch_assoc($rs1)); ?> </table> <p> <input type="submit" name="Submit" id="Submit" value="Submit" /> <input type="hidden" name="MM_update" value="form1" /> </p> </form> </div> </div> <div style="clear: both;"> </div> </div> <!-- end #content --> <!-- end #sidebar --> <div style="clear: both;"> </div> </div> </div> </div> <!-- end #page --> </div> <!-- end #footer --> </body> </html> <?php mysql_free_result($rs1); ?> All i want is that when users click on SUBMIT button values of point column in s_lessons(database table) be updated by new entries from user. i did my best and result with that code is : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' lid=888, sid=860935422, term=902' at line 1 I would appreciate any idea. with prior thanks
×
×
  • 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.