PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mariel_e4
Forum Newbie
Posts: 2 Joined: Sat Apr 07, 2012 8:35 am
Post
by mariel_e4 » Sat Apr 07, 2012 8:47 am
I cannot update my sql when i press the save button and make some changes nothing is happening about the data of my rows.What is missing or whats wrong with this i really dont know ive been fixing it for 1 day.and still nothing happened.
Code: Select all
<?php
include("connect.php");
$code =$_GET['Code'];
$result = mysql_query("SELECT * FROM books WHERE Code = '$code'");
$row = mysql_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$code =$row['Code'];
$Title=$row['Title'] ;
$Price= $row['Price'] ;
$Stock=$row['Stock'] ;
if(isset($_GET['editsave']))
{
$title_save = $_GET['title'];
$price_save = $_GET['price'];
$stock_save =$_GET['stock'];
mysql_query("UPDATE books SET Title ='$title_save', Price ='$price_save',
Stock='$stock_save' WHERE Code= '$code'")
or die(mysql_error());
echo "Saved!";
header("Location: home_admin.php");
}
?>
<body>
<form method="get">
<table>
<tr>
<td>Title:</td>
<td><input type="text" name="title" value="<?php echo $Title ?>"/></td>
</tr>
<tr>
<td>Price</td>
<td><input type="text" name="price" value="<?php echo $Price ?>"/></td>
</tr>
<tr>
<td>Stock</td>
<td><input type="text" name="stock" value="<?php echo $Stock ?>"/></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="editsave" value="save" /></td>
</tr>
</table>
</body>
</html>
azycraze
Forum Commoner
Posts: 56 Joined: Mon Oct 24, 2011 12:08 pm
Location: India
Post
by azycraze » Sat Apr 07, 2012 10:59 am
put action for the form
<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
mariel_e4
Forum Newbie
Posts: 2 Joined: Sat Apr 07, 2012 8:35 am
Post
by mariel_e4 » Sat Apr 07, 2012 11:18 am
what will I put in action? I dont no what to put and why do i NEEd .I already have a header right? sorry i'm a beginner sorry for stupid questions..
azycraze
Forum Commoner
Posts: 56 Joined: Mon Oct 24, 2011 12:08 pm
Location: India
Post
by azycraze » Sat Apr 07, 2012 3:08 pm
You have to mention what action have to be taken when a submit button in a form is clicked.
Do you get any warnings,notices,errors ?
php_rockzz
Forum Newbie
Posts: 3 Joined: Wed Apr 04, 2012 6:20 am
Post
by php_rockzz » Tue Apr 10, 2012 8:57 am
use something like this (untested):
Code: Select all
<?php
include("connect.php");
if(_SERVER['REQUEST_METHOD']=='POST')
{
$code =$_GET['Code'];
$result = mysql_query("SELECT * FROM books WHERE Code = '$code'");
$row = mysql_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$code =$row['Code'];
$Title=$row['Title'] ;
$Price= $row['Price'] ;
$Stock=$row['Stock'] ;
if(isset($_GET['editsave']))
{
$title_save = $_GET['title'];
$price_save = $_GET['price'];
$stock_save =$_GET['stock'];
mysql_query("UPDATE books SET Title ='$title_save', Price ='$price_save',
Stock='$stock_save' WHERE Code= '$code'")
or die(mysql_error());
echo "Saved!";
header("Location: home_admin.php");
}
}
?>
and the modify the form syntax as:
phphelpme
Forum Contributor
Posts: 261 Joined: Sun Nov 21, 2010 3:32 pm
Post
by phphelpme » Tue Apr 10, 2012 12:08 pm
Where does this variable come from?
I can not see on your script where this value is coming from and how the value is being passed when you click your button.
You are also missing your closing </form> tag after your ending </table> tag.
Also this:
Seems pointless considering you already have checked to see if this code exists in your database and you already have the value saved as a string variable, but then you grab the exact same code and save again to the exact same string variable name from the database.
Best wishes
phphelpme
Forum Contributor
Posts: 261 Joined: Sun Nov 21, 2010 3:32 pm
Post
by phphelpme » Tue Apr 10, 2012 12:43 pm
checkout:
mysql_real_escape_string()
htmlspecialchars()
Best wishes
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Tue Apr 10, 2012 12:45 pm
Better still, check out
PDO .