I am trying to build a page for my boss, so he can update our mysql database. He requires it to look very similar to excel or an access page, with all the stock listed on one page, and you can change any value by just changing the text then clicking save (at which point the page should not change).
I have managed to pull my data out of mysql, and put it into one page (in a form, one product per line) with a submit (save) button that works, BUT I can't work out how to make it stay on that page. I have attempted to do it with a jquery script, but I cant get my head around it enough to even make a basic jquery page work.
Any suggestions?
MYSQL edit inline
Moderator: General Moderators
Re: MYSQL edit inline
Ajax does that. It does require using Javascript, though. I always get nervous when someone insists they want a relational database to behave like a spreadsheet. The two concepts are utterly different. But if he's the boss, of course, ... 
-
sillybgoat
- Forum Newbie
- Posts: 3
- Joined: Thu Jul 02, 2009 10:33 pm
Re: MYSQL edit inline
Well so far this is what I have. I am using the persons database in place of my complicated product database to try and get it working.
Database is:
persons-----FirstName
|---LastName
|---Age
|__ID (unique key, auto increment)
listpersons.php (initial page)
learn.php (called page)
Its messy at the moment, but I have edited this so many times.....
So currently if I change the price and press submit, it opens up learn.php and shows "1 records added"
I tried to replace some of the code with some javascript to do an AJAX call, but it always came up and said it worked but I don't think it was accessing the learn page at all....
Database is:
persons-----FirstName
|---LastName
|---Age
|__ID (unique key, auto increment)
listpersons.php (initial page)
Code: Select all
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$con = mysql_connect($dbhost, $dbuser);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM Persons");
while($row = mysql_fetch_array($result))
{
?>
<form name="Person<?php echo $row['ID']?>"action=learn.php method=post>
<input name="FirstName" type="text" maxlength="45" size=15" value="<?php echo $row['FirstName'] ?>" />
<input name="LastName" type="text"minlength="5"maxlength="15"size=15" value="<?php echo $row['LastName'] ?>"/>
<input name="Age" type="integer"maxlength="3"size=3" value="<?php echo $row['Age'] ?>" />
<input name="ID" type="integer"maxlength="15"size=15" value="<?php echo $row['ID'] ?>" />
<input type="submit" name="submit" value="submit"/>
</form></BR>
<?
}
?>Code: Select all
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$con = mysql_connect($dbhost, $dbuser);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$create = "CREATE TABLE IF NOT EXISTS Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
ID int INDEX(ID)
)";
$sql="UPDATE Persons SET FirstName = '$_POST[FirstName]',LastName = '$_POST[LastName]', Age = '$_POST[Age]'
WHERE ID = '$_POST[ID]'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record changed";
mysql_close($con)
?>So currently if I change the price and press submit, it opens up learn.php and shows "1 records added"
I tried to replace some of the code with some javascript to do an AJAX call, but it always came up and said it worked but I don't think it was accessing the learn page at all....