Forum Moderators: coopster
INSERT INTO table (reg_id, progr_id,Something)
VALUES (%s, $progr_id, %s)",
GetSQLValueString($HTTP_POST_VARS['reg_id'], "int"),
GetSQLValueString($HTTP_POST_VARS['Status'], "text"));
-------------------------------
id ¦ reg_id ¦ progr_id ¦ Something
-------------------------------
1 ¦ 3 ¦ 1 ¦ Something
------------------
2 ¦ 1 ¦ 1 ¦ Something
------------------
3 ¦ 3 ¦ 2 ¦ Something
-----------------
4 ¦ 2 ¦ 1 ¦ Something
------------------
5 ¦ 3 ¦ 1 ¦ Something
-----------------
6 ¦ 1 ¦ 2 ¦ Something
------------------
7 ¦ 3 ¦ 3 ¦ Something
if (isset($_POST['submit'])){
$db = mysql_connect(DB_HOST, DB_USER, DB_PASS);
$value = mysql_query("SELECT MAX (progr_id) AS maxid FROM type_doc");
echo "Value: $value <br> Max ID: $maxid <br> progr_id: $progr_id <br> ";
$values = array ("Documentation"=>$_POST['doc'], "progr_id"=>$maxid);
$error = InsertQuery ("type_doc", $values);
}
if (isset($_POST['submit'])) {
$db = mysql_connect(DB_HOST, DB_USER, DB_PASS);
$rows = mysql_query("SELECT MAX (progr_id) AS maxid FROM type_doc");
$row = mysql_fetch_array [php.net]($rows);
$maxid = $row['maxid'];
echo "Max ID: $maxid <br>";
$values = array ("Documentation"=>$_POST['doc'], "progr_id"=>$maxid);
$error = InsertQuery ("type_doc", $values);
}Take a close look here at how the statement is first created (you got that part correct). Next, time to execute it with the mysql_query. But then we need to assign the result set returned to a result set identifier that we use to fetch row(s) from. Each row is returned to an array which contains the columns of the table for that particular row returned. The link to the PHP docs can explain a bit more.
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/lenders/index.php on line 13
Code:
if (isset($_POST['submit'])) {
$db = mysql_connect(DB_HOST, DB_USER, DB_PASS);
$rows = mysql_query("SELECT MAX (progr_id) AS maxid FROM type_doc");
$row = mysql_fetch_array($rows); // LINE 13 IS RHT HERE
$maxid = $row['maxid'];
$maxid++;
echo "Max ID: $maxid <br>";
$values = array ("Documentation"=>$_POST['doc'], "progr_id"=>$maxid);
$error = InsertQuery ("type_doc", $values);
}
I tried this:
if (!empty($error)){
echo "Error: $error<br>\n";
}
if (isset($_POST['submit'])) {
$db = mysql_connect(DB_HOST, DB_USER, DB_PASS);
$rows = mysql_query("SELECT MAX (progr_id) AS maxid FROM type_doc");
$row = mysql_fetch_array($rows);
$maxid = $row['maxid'];
$maxid++;
echo "Max ID: $maxid <br>";
$values = array ("Documentation"=>$_POST['doc'], "progr_id"=>$maxid);
$error = InsertQuery ("type_doc", $values);
echo "db: $db <br>"; echo "rows: $rows <br>"; echo "row: $row <br>"; echo "maxid: $maxid <br>"; echo "values: $maxid <br>"; echo "error: $error <br>";
}
And GOT this:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/mtg/index.php on line 13
Max ID: 1
db: Resource id #5
rows:
row:
maxid: 1
values: 1
error:
==============
The maxid is one because of $maxid++;