Forum



19:11

09/11/2010

I'm using php to pull from a mysql table. Everything is working except for the adding new data and editing data part. I have the options available, I just don't know what the someurl.php page is supposed to look like in order to add the new or edited data to my table.
Does anyone have a .php page they've created that they can share with me?
04:45

08/06/2010

Here is an example:
<?php
... create your database connection here...
include_once('functions.php');
if (isset($_POST["oper"])) {
if ($_POST["oper"] == "add") {
$insertSQL = sprintf("INSERT INTO users (login, pword, fname, lname,
email, wphone, hphone, mphone, idlocations, idaccess, idorgunits,
status, last_update_id, last_update_dt, expiration_dt)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, ifnull(%s,1000),
current_timestamp(), DATE_ADD(current_timestamp(), INTERVAL 90 DAY))",
GetSQLValueString($_POST['login'], "text"),
GetSQLValueString($_POST['pword'], "password"),
GetSQLValueString($_POST['fname'], "text"),
GetSQLValueString($_POST['lname'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['wphone'], "text"),
GetSQLValueString($_POST['hphone'], "text"),
GetSQLValueString($_POST['mphone'], "text"),
GetSQLValueString($_POST['idlocations'], "int"),
GetSQLValueString($_POST['idaccess'], "int"),
GetSQLValueString($_POST['idorgunits'], "int"),
GetSQLValueString($_POST['status'], "text"),
GetSQLValueString($_SESSION['MM_UserID'], "int"));
$Result = mysql_query($insertSQL, $metrics) or die(mysql_error());
} elseif ($_POST["oper"] == "edit") {
$editSQL = sprintf("update users set login = %s, pword = %s, fname = %s,
lname = %s, email = %s, wphone = %s, hphone = %s, mphone = %s,
idlocations = %s, idaccess = %s, idorgunits = %s, status = %s,
last_update_id = %s, last_update_dt = current_timestamp(),
expiration_dt = DATE_ADD(current_timestamp(), INTERVAL 90 DAY)
where idusers = %s",
GetSQLValueString($_POST['login'], "text"),
GetSQLValueString($_POST['pword'], "password"),
GetSQLValueString($_POST['fname'], "text"),
GetSQLValueString($_POST['lname'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString($_POST['wphone'], "text"),
GetSQLValueString($_POST['hphone'], "text"),
GetSQLValueString($_POST['mphone'], "text"),
GetSQLValueString($_POST['idlocations'], "int"),
GetSQLValueString($_POST['idaccess'], "int"),
GetSQLValueString($_POST['idorgunits'], "int"),
GetSQLValueString($_POST['status'], "text"),
GetSQLValueString($_SESSION['MM_UserID'], "int"),
GetSQLValueString($_POST['id'], "int"));
$Result = mysql_query($editSQL, $metrics) or die(mysql_error());
} elseif ($_POST["oper"] == "del") {
$deleteSQL = sprintf("delete from users where idusers = %s",
GetSQLValueString($_POST['id'], "int"));
$Result = mysql_query($deleteSQL, $metrics) or die(mysql_error());
}
}
mysql_close($metrics);
?>
The function.php file has the getsqlvaluestring function to return data in the format needed for sql. If you want this file, send me a PM.
Regards,
Ben
17:04

Moderators
30/10/2007

Well
It is very easy to say not work -
Please specify example code, browser, OS
This way you will save your and our time
Please do this into the future – if not – no help
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
64 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66