Results 11 to 14 of 14
-
16th Apr 2011, 08:03 PM #11Respected Member
If the id comes from the browser line it is
$id=intval($_GET['id']);
$id=intval($_POST['id']);
-
16th Apr 2011, 08:21 PM #12MemberWebsite's:
epicimagehost.comI think you only need to update the 'update_ac.php' file:
PHP Code:<?php
//I assume this is update_ac.php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="test_mysql"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql='UPDATE '.$tbl_name.' SET username="'.mysql_real_escape_string($_POST['username']).'", password="'.mysql_real_escape_string($_POST['password']).'", email="'.mysql_real_escape_string($_POST['password']).'" WHERE id='.intval($_POST['id']);
/*
this query might work aswell ( note the different type of quotes used ) but use the one above
$sql="UPDATE $tbl_name SET username='mysql_real_escape_string($_POST['username'])', password='mysql_real_escape_string($_POST['password'])', email='mysql_real_escape_string($_POST['password'])' WHERE id=intval($_POST['id'])";
*/
/*
In php these are thesame:
$cool = "awesome";
echo "lol this is $cool"; <- this shows : lol this is awesome
echo 'lol this is '. $cool; <- this shows : lol this is awesome
*/
/*
the dot ( . ) acts as glue.
For example:
$this = 'Hi';
$still = ', how';
$works = ' are you';
echo $this . $still . $works . 'doing?'; <- This shows : Hi, how are you doing?
so does this btw:
echo $this.$still.$works.'doing?'; ( the space doesn't matter )
*/
/*
Now about the $_POST[''] variable I used in your query ( line 14 )
Whenever you submit a form [ remember the <form method="post".. u used in your HTML ? ] to a script, the data you send
gets stored in the $_POST array.
For example:
<input type="text" name="KWWHunction" /> ( let's assume you entered sucks and pressed submit )
it will be handled in the script with:
$_POST['KWWHunction']
So if you do this in your script:
echo $_POST['KWWHunction'];
That will show the word sucks
*/
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
Added a bit of info as it seems you are quite new with this.
Not sure if what I said is correct, i'm really tired atm
-
16th Apr 2011, 09:30 PM #13Member
I started writing this for my site.
Just adapt it for you DB, it seems odd to use three files.
PHP Code:<?
$query = "SELECT * FROM site WHERE active=1";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
echo "<form action='' method='POST'>"
."<table cellpadding=2 cellspacing=1 border=1 bgcolor=white align=center width=850>"
."<tr style='background:lightblue'><th>Project ID</th><th>Project Name</th><th>Total Hits Paid</th><th>Hits Sent</th><th>Site URL</th><th>Active</th><th>Select</th></tr>";
while($row = mysql_fetch_assoc($result))
{
extract($row);
echo "<tr><td>$id</td><td>$sitename</td><td>$maxhits</td><td>$totalhits</td><td>$siteurl</td><td>$active</td><td><input type='checkbox' name='id' value='$id'></input></td></tr>";
}
echo"<tr><td colspan='7' align='right'><input type='submit' name='edit' value='Edit'/></td></tr>";
if (isset($_POST['edit']))
{
$editid = $_POST['id'];
$query = "SELECT * FROM site WHERE id=$editid";
$result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR);
while($row = mysql_fetch_assoc($result))
{
extract($row);
echo "<tr><td>$id</td><td><input type='hidden' name='id' value='$id'><input type=text name=sitename value='$sitename'/></td><td><input type='text' name='maxhits' value='$maxhits'/></td><td><input type=text name='totalhits' value='$totalhits'/></td><td><input type=text name='siteurl' value='$siteurl'/></td><td><input size='2' type=text name='active' value='$active'></td><td></input></td></tr>";
}
echo "<tr><td colspan='7' align='right'><input type='submit' name='update' value='Update'/></td></tr>";
}
if (isset($_POST['update']))
{
$id = $_POST['id'];
$sitename = $_POST['sitename'];
$maxhits = $_POST['maxhits'];
$totalhits = $_POST['totalhits'];
$siteurl = $_POST['siteurl'];
$active = $_POST['active'];
mysql_query("UPDATE site SET sitename='$sitename', maxhits='$maxhits', totalhits='$totalhits', siteurl='$siteurl', active='$active' WHERE id='$id'");
echo "<meta http-equiv='refresh' content='0;url=''/>";
}
echo "</table>";
?>
-
17th Apr 2011, 01:36 PM #14OPMemberWebsite's:
itleech.com fixdownloads.com downtoolz.com itcoder.usThx guys i will try and let u now what happens
Signature too big, removed by Staff
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
themaLeecher - leech and manage...
Version 5.05 released. Open older version (or...