hello guys i have a problem with this code
when id add a comment and comment insert in database
and when i make refresh on the same page i get this warning :
One of the fields are still empty,
i think the problem in the first code
<?php
if ($_POST['add'] and $_POST['add']=='comm'){
$comm_name =strip_tags($_POST['comm_name']);
$comm_country =strip_tags(mysql_real_escape_string($_POST['comm_country']));
$c =strip_tags(mysql_real_escape_string($_POST['comm']));
$comm_thread =strip_tags(mysql_real_escape_string($_POST['comm_thread']));
$status =$_POST['status'];
$getidtopic=$_GET['id_topic'];
$post_code=$_POST['post_code'];
if ($comm_name=='' or $comm_country=='' or $c=='' or $post_code=='' ){
echo "<script>alert(\"One of the fields are still empty
\");</script>";
}else if ($_POST['post_code']==$_SESSION['code']) {
$insertcomm=mysql_query("insert into comments values('','$comm_name','$comm_country','$comm','$comm_thread','$status') ")or die (mysql_error);
echo "<script>alert(\"your comment has been adding\");</script>";
}
}
?>
and this is the comment's form
<form action='' method='post' >
<table class='rightcol' width='100%' cellpadding='0' cellspacing='5'>
<tr>
<td colspan='3' id='addcomm'>add comm</td>
</tr>
<tr>
<td width='15%' ><div id='title_comm' value=''>name : </div></td>
<td ><input type='text' name='comm_name' value='<?if (!$insertcomm){
echo $comm_name;
}?>'/></td>
</tr>
<tr>
<td width='15%' ><div id='title_comm'>country </div></td>
<td ><input type='text' name='comm_country'
value='<?if (!$insertcomm){echo $comm_country;}?>'/>
</td>
</tr>
<tr>
<td valign='top' width='15%'><div id='title_comm'>comment : </div></td>
<td width='50%'>
<textarea cols='55' rows='12' name='comm'>
<?if (!$insertcomm){echo $c;}?>
</textarea></td>
<td valign='top' ><div id='note_comm'>
your comment will not insert if you try to use some thing bad
</div></td>
</tr>
<tr>
<td width='15%' ><div id='title_comm'><span style='color:red'>code : <br/>write these codes </span></div></td>
<td ><input type='text' name='post_code'/></td>
</tr>
<tr>
<td ><div id='code'>
<?php
$text=rand(400,80000);
echo $_SESSION['code']=$text;
?>
</div></td>
</tr>
<td colspan='4' ><input type='submit' name='addcomm' id='add' value='add comm'/></td>
</table>
<input type='hidden' name='comm_thread' value='<?php echo $getidtopic;?>' />
<input type='hidden' name='add' value='comm'/>
<input type='hidden' name='status' value='2'/>
</form>
that is because, when you refresh the page, the $_POST fields are reset, and the fields get empty, so when the page executes its PHP line if ($comm_name=='' or $comm_country=='' or $c=='' or $post_code=='' or $post_code=='' ){ it will find them to be empty.
You need to show us the table definition to better figure out what the issue is exactly. My guess is that your SQL statement is not properly prepared.
Related
just trying to make a little calculator for myself in php and i wonder if its possible to make the answer instant update after i type in the values?
Thank you.
<?php
if (isset($_POST['valuea'])) $valuea = $_POST['valuea'];
if (isset($_POST['valueb'])) $valueb = $_POST['valueb'];
if (isset($_POST['check1'])) {
$answer = (($valuea * $valueb) * 10)*2;
} else {
$answer = ($valuea * $valueb) * 10;
}
echo <<<_END
<form method='post' action=''>
<table border='0' width='500px' cellpadding='3' cellspacing='1' class="table">
<tr class="calcrow">
<td>Lenght:</td>
<td align="center"><input type='text' name='valuea' value="$valuea"/></td>
</tr>
<tr class="calcrow2">
<td>Width:</td>
<td align="center"><input type='text' name='valueb' value="$valueb"/></td>
</tr>
<tr class="calcrow2">
<td>2x test</td>
<td align="center"><input type="checkbox" name="check1"></td>
</tr>
<tr class="submit"><td colspan="2"><input type='submit' value='Calculate'/></td></tr>
_END;
?>
<tr class="calcrow">
<td><i>Answer</td>
<td align="center"><input type="text" value="<?php echo round($answer)?>"></td></i>
</tr>
</table>
</form>
You are looking for a thing called Jquery.
Which can fetch current Values of your form inputs or any other elements from your webpage. Then you can then send that data to your php file where you can perform the calculation and return the result which can again be displayed wherever you want .
All of this happens in real time.
This is the way you could do it if you wanted to do it in php
Else you could always go for plain JavaScript or a mixture of jquery + javascript, to avoid using php and ajax.
I have a html form which i want to check some items in the form and then update the form.
(actually there is no order in which checkbox is going to be mark, it's totally random)
my problem is when i mark some of the checkboxes and press update my code will mark the top checkboxes in order.
This is what i mean :
before submiting :
after submiting :
this is my form code :
$row_counter=0;
if ($_SESSION['user_row_num']=="1")
{
?>
<form method="POST" action="" name="frm1">
<table class='styled-table' cellspacing='0' border='1'>
<tr>
<th scope='col' style='font-size:13px;'>number</th>
<th scope='col' style='font-size:13px;'>view</th>
<th scope='col' style='font-size:13px;'>edit</th>
<th scope='col' style='font-size:13px;'></th>
</tr>
<?php while($row_form = mysqli_fetch_assoc($query_formsearch))
{
//fetching from profile previous valuse of form access
$query_profile_check = mysqli_query($con,"SELECT * FROM `profile` WHERE `id`='{$_SESSION['user_id']}' ");
$row_profile = mysqli_fetch_assoc($query_profile_check);
//creating form name from forms table for profile table
$profile_form_name="form_".$row_form['num'];
$profile_frm_name=$row_profile[$profile_form_name];
$a_form_aces=explode("-", $profile_frm_name);
$frm_view=$a_form_aces[0];
$frm_edit=$a_form_aces[1];?>
<tr>
<td align='center'><input class='styled-input' type='hidden' name='form_num[]' id='form_num' value="<?php echo $row_form['num']; ?>"/></td>
<td align='center'><input class='styled-input' type='text' name='form_name[]' id='form_name' value="<?php echo $row_form['name']; ?>"/></td>
<td align='center'><input class='styled-input' type='checkbox' name='view[]' id='view' <?php if($frm_view=="1")echo "checked"; ?> /></td>
<td align='center'><input class='styled-input' type='checkbox' name='edit[]' id='edit' <?php if($frm_edit=="1")echo "checked"; ?> /></td>
<td align='center'><input type='hidden' name='row_counter' id='row_counter' value="<?php echo $row_counter++; ?>"/></td>
</tr>
<?php } ?>
</table>
<input class='styled-input_2' style='padding: 5px; width: 140px;' type='submit' name='save_setting' id='save_setting' value="update" >
<div class='cleaner h30'></div>
</form>
this is my update code :
<?php
} // end of if($_SESSION['user_row_num']=="1")
// Check if button name "edit-msb" is active, do this
if(isset($_POST['save_setting']) && $_POST['save_setting'] == 'update')
{
for($i=0;$i<=$_SESSION['user_count'];$i++)
{
$row_no = ($_REQUEST['row_counter'][$i]);
$form_numb = $_REQUEST['form_num'][$row_no];
if(isset($_REQUEST['view'][$row_no])){$_REQUEST['view'][$row_no]="1";}else{$_REQUEST['view'][$row_no]="0";}
if(isset($_REQUEST['edit'][$row_no])){$_REQUEST['edit'][$row_no]="1";}else{$_REQUEST['edit'][$row_no]="0";}
$form_access=$_REQUEST['view'][$row_no]. "-" .$_REQUEST['edit'][$row_no];
$profile_form_num="form_". $form_numb;
$access_query=mysqli_query($con,"UPDATE `profile` SET `{$profile_form_num}`='{$form_access}' WHERE `id`='{$_SESSION['user_id']}'");
}
if($access_query!='')
{
echo "<div class='cleaner h30'></div>";
echo "<b style='color:green;margin-left:10px;font-size:15px;'>the form successfully updated.</b>";
}
}
?>
I want each check box shows it's updated value after i submiting the form and in the order that i marking them but i don't know where is my mistake.
I've changed your code from checkbox into select option and it's working see if it'll work for you
form code :
<form method="POST" action="" name="frm1">
<table class='styled-table' cellspacing='0' border='1'>
<tr>
<th scope='col' style='font-size:13px;'>form number</th>
<th scope='col' style='font-size:13px;'>form name</th>
<th scope='col' style='font-size:13px;'>view</th>
<th scope='col' style='font-size:13px;'>edit</th>
<th scope='col' style='font-size:13px;'></th>
</tr>
<?php while($row_form = mysqli_fetch_assoc($query_formsearch))
{
//fetching from profile previous valuse of form access
$query_profile_check = mysqli_query($con,"SELECT * FROM `profile` WHERE `id`='{$_SESSION['user_id']}' ");
$row_profile = mysqli_fetch_assoc($query_profile_check);
//creating form name from forms table for profile table
$profile_form_name="form_".$row_form['num'];
$profile_frm_name=$row_profile[$profile_form_name];
$a_form_aces=explode("-", $profile_frm_name);
$frm_view=$a_form_aces[0];
$frm_edit=$a_form_aces[1];?>
<tr>
<td align='center'><input class='styled-input' type='text' name='form_num[]' id='form_num' value="<?php echo $row_form['num']; ?>"/></td>
<td align='center'><input class='styled-input' type='text' name='form_name[]' id='form_name' value="<?php echo $row_form['name']; ?>"/></td>
<td align='center'>
<select class='styled-input' name='view[]' id='view' />
<option value="<?php echo $frm_view; ?>"><?php if($frm_view=="1"){echo "yes";}else{echo "no";} ?></option>
<option></option>
<option value="1" style="color:#1A75FF;">yes</option>
<option value="0" style="color:red;">no</option>
</select>
</td>
<td align='center'>
<select class='styled-input' name='edit[]' id='edit' />
<option value="<?php echo $frm_edit; ?>" ><?php if($frm_edit=="1"){echo "yes";}else{echo "no";} ?></option>
<option></option>
<option value="1" style="color:#1A75FF;">yes</option>
<option value="0" style="color:red;">no</option>
</select>
</td>
<td align='center'><input type='hidden' name='row_counter' id='row_counter' value="<?php echo $row_counter++; ?>"/></td>
</tr>
<?php } ?>
</table>
update code :
<?php
// Check if button name "edit-msb" is active, do this
if(isset($_POST['save_setting']) && $_POST['save_setting'] == 'update')
{
for($i=0;$i<$_SESSION['user_count'];$i++)
{
//$row_no = ($_REQUEST['row_counter'][$i]);
$form_access=$_POST['view'][$i]. "-" .$_POST['edit'][$i];
echo $profile_form_num="form_". $_POST['form_num'][$i];echo"<br>";
echo $form_access;echo"<br>";
$access_query=mysqli_query($con,"UPDATE `profile` SET `{$profile_form_num}`='{$form_access}' WHERE `id`='{$_SESSION['user_id']}'");
}
if($access_query!='')
{
echo "<div class='cleaner h30'></div>";
echo "<b style='color:green;margin-left:10px;font-size:15px;'>form successfully updated.</b>";
}
}
?>
i've made a website, and i made a control panel for it for admin
now iwant to make admin able to add more users to be admins from the control panel
its worked
but i want to make him able to edit them also ( like the usernames and passwords )
i wrote the code but it didnt work and i think the problem maybe with the $editget = $_GET['euid']; it dosent give the number in the url that should be www.example.com/admin/index.php?adpa=users&euid=4 , so it should get me the number 4
i did the same thing with delectation it works and the GET gave me the number after deluid=
so where im going wrong
here is the code :
$eusername = $_POST['eusername'];
$epassword = $_POST['epassword'];
#===========================================================#
if (isset($_POST['edit']) and $_POST['edit'] == 'user') {
$editget = $_GET['euid'];
$edituserinfo = $db->query("update user set username='$eusername', password='$epassword' where user_id='$editget'");
if (isset($edituserinfo)) {
die ("
<center>
<div class='head'>تــــــــم</div>
<div class='bodypanel'>
<br>
تــــعديل بيـــانات الـــمدير بنـــجاح
<br>
<br>
</div>
</center>
<meta http-equiv='refresh' content='4; url=?cpages=users' />
");
}
}
and here is the edit form code :
if ($_REQUEST['euid']) {
$edituid = $db->query("select * from user where user_id='$editu'");
$redit = $edituid->fetch(PDO::FETCH_OBJ);
echo "
<form action='?cpages=users' method='post'>
<table width='100%' align='center' cellpadding='10' cellspacing='0'>
<tr>
<td class='tbl' colspan='2'>تعديل بيانات مدير</td>
</tr>
<tr>
<td class='tblrl' align='left'>اسم المدير : </td>
<td class='tblrl' align='right'><input type='text' name='eusername' value='".$redit->username."'></td>
</tr>
<tr>
<td class='tblrl' align='left'>كلمة سر المدير : </td>
<td class='tblrl' align='right'><input type='text' name='epassword' value='".$redit->password."'></td>
</tr>
<tr>
<td class='tblb' colspan='2' align='center'><input class='buttons' type='submit' value='تعديل'/></td>
</tr>
</table>
<input type='hidden' name='edit' value='user' />
</form>";
}
You are not passing the userId in the form
change
<form action='?cpages=users' method='post'>
to
<form action='?cpages=users&euid=" . $_GET['euid'] . "' method='post'>
your problem is here in the form in this line
<form action='?cpages=users' method='post'>
your taking it to users page but there is no euid in there so just add
&euid=" . $_GET['euid'] . " to get it to work fine
I have following tables and following is the query I have used all possible checks to solve this issue. The problem is the insert works with phpMyAdmin but not with PHP. I tried everything but still have the same problem.
Here is my table code:
CREATE TABLE IF NOT EXISTS `cle` (
`id` int(40) NOT NULL AUTO_INCREMENT,
`title` varchar(444) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'Article',
`content` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(222) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`status` int(11) DEFAULT '0',
`alt` varchar(400) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `url` (`url`,`status`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Here is the insert code:
INSERT INTO cle (content,url,alt) VALUES (' <br> <span name=KonaFilter style=\"width:100%;\"><center><font size=\"4\"><b>Rate? Part 1</b> by<b> </b></font></center></span> <span> <br> <center> <br><td><img src=\"http://a1.abc.com/a/spacer.gif\" height=\"0\" width=\"1\"></td></tr> <tr><td>Article Posted: 04/04/2005</td></tr> </table> </td> </tr> </table> <table cellspacing=\"0\" cellpadding=\"1\" width=\"100%\" border=0> <tr> <td><h1 style=\"color:02679D; font-size:16\"><b><span name=KonaFilter>Howe? Part 1</span></b></h1></td> <td align=\"right\"> <table border=0 cellpadding=4> <tr> <td valign=\"top\"> <img name=\"btn36\" src=\"http://a4.abc.com/a/js_feed_article.gif\" width=48 height=38 onclick=\"ClipBoard(input36);\" onmouseover=\"this.style.cursor = \'hand\';\"> <input type=\"hidden\" name=\"input36\" value=\'</td> <td valign=\"top\"> <img src=\"http://a4.abc.com/a/email_me.gif\" width=38 height=33 border=0> </td> </tr> </table> </td> </tr> <tr> <td colspan=2> </td> </tr> <tr><td><br> <br></td></tr> <tr> <td valign=\"bottom\" colspan=2> <form name=\"formx\" action=\"/article_detail.cfm?articleid=36\" method=\"post\"> <input type=\"hidden\" name=\"flagged\" value=1> <input type=\"image\" src=\"http://a1.abc.com/a/categorize.gif\" alt=\"Is gory?\" onclick=\"flag();\"> </form> </td></tr> </tr> <tr><td colspan=2><img src=\"http://a1.abc.com/a/spacer.gif\" height=\"5\" width=\"1\"></td></tr> <tr><td colspan=2> <div align=left style=\"width:370; height:315;\">s we’ll sues. <br> Question 1:? Do on such as “read more here” or? <br> What bsite. “Read More Here” us ASP vendors, rates, why itrates. <br> <p><br<!-- --> <table cellspacing=1 cellpadding=\"1\" border=0 width=\"130\" bgcolor=\"5A5A5A\"> <tr> <td valign=\"middle\" align=\"right\" height=\"10\" style=\"background-repeat:no-repeat;\" bgcolor=\"ffffff\" background=\"http://a15.abc.com/a/catbox.gif\"> <font face=\"arial\" style=\'font-size:12\'><b><font style=\'font-family:verdana; font-size:9\'>Rate This Article</font> <img onclick=\'closeWindow();\' src=\'/a/close.gif\'> </b></font></td> </tr> <tr><td bgcolor=\"dddcdd\"> <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"> <tr> <td align=\"center\"> <table border=0> <form name=\"form2\" action=\"\" method=\"post\"> <tr><td colspan=5><input type=\"text\" name=\"xDesc\" value=\"\" style=\"border:0 px; font-size:10;background-color:dddcdd\" contenteditable=\"false\"></td> </form> <tr> <td width=\"20%\"> </td> <td width=\"20%\"> <form name=\"rateform2\" action=\"/feedback.cfm/36?articleid=36&title=2C1\" method=\"post\"> <input type=\"hidden\" name=\"rating\" value=2> <img src=\"http://a2.abc.com/a/empty_star.gif\" name=\"imagetwo\" alt=\"Minimal useful information.\" style=\"border:0px\" onclick=\"rate(2);\" onmouseover=\"starDesc(2);\" onmouseout=\"starDesc(0);emptyStar(2);\"> </form> </td> <td width=\"20%\"> <form name=\"rateform3\" action=\"/f.cfm/36?articleid=36C1\" method=\"post\"> <input type=\"hidden\" name=\"rating\" value=3> <img src=\"http://a3.abc.c.gif\" name=\"imagethree\" alt=\"Decent and informative.\" style=\"border:0px\" onclick=\"rate(3);\" onmouseover=\"starDesc(3);\" onmouseout=\"starDesc(0);emptyStar(3);\"> </form> </td> <td width=\"20%\"> <form name=\"rateform4\" action=\"/feedback.cfm/36?articleid=36&title=C1\" method=\"post\"> <input type=\"hidden\" name=\"rating\" value=4> <img src=\"http://a4.abc.com/a/emptyr.gif\" name=\"imagefour\" alt=\"Gre.\" style=\"border:0px\" onclick=\"rate(4);\" onmouseover=\"starDesc(4);\" onmouseout=\"starDesc(0);emptyStar(4);\"> </form> </td> <td width=\"20%\"> <form name=\"rateform5\" action=\"/fem/36?articleid=36&title=C1\" method=\"post\"> <input type=\"hidden\" name=\"rating\" value=5> <img src=\"http://a5.abc.com/a/empty_star.gif\" name=\"imagefive\" alt=\"A \'Must Read\'.\" style=\"border:0px\" onclick=\"rate(5);\" onmouseover=\"starDesc(5);\" onmouseout=\"starDesc(0);emptyStar(5);\"> </form> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr><td bgcolor=\"5A5A5A\"><img src=\"http://a1.aer.gif\" height=\"8\" width=\"100%\"></td></tr> </table> </div> <script type=\"text/javascript\"> //Enter \"frombottom\" or \"fromtop\" var verticalpos=\"frombottom\" function JSFX_FloatTopDiv() { var tmpcookie = new Date(); chkcookie = (tmpcookie.getTime() + \'\'); document.cookie = \"chkcookie=\" + chkcookie + \"; path=/\"; if (document.cookie.indexOf(chkcookie,0) < 0) { divStayTopLeft.style.left=-1000; } else { starDesc(0); var startX = 0, startY = 100; var ns = (navigator.appName.indexOf(\"Netscape\") != -1); var d = document; function ml(id) { var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id]; if(d.layers)el.style=el; el.sP=function(x,y){this.style.left=x;this.style.top=y;}; el.x = startX; if (verticalpos==\"fromtop\") el.y = startY; else{ el.y = ns ? page
<p> </td> </tr> <tr><td align=\"center\" > <p> <p> <font size=3 color=990000>Doe? Have a Comment? POST IT!</font><p> <table cellspacing=1 cellpadding=\"4\" border=0 width=\"100%\" bgcolor=\"4D4D4D\" align=\"center\"> <tr> <td align=\"right\" height=\"23\" style=\"background-repeat:no-repeat;\" bgcolor=\"ffffff\" background=\"\"> <font face=\"arial\" style=\'font-size:12\'><b>Re</b></font> </td> </tr> <tr><td bgcolor=\"dddddd\"> <form action=\"/post_.cfm\" method=\"post\"> <table width=\"100%\" cellpadding=3 border=0 cellspacing=1> </table> <table width=\"100%\" cellpadding=5 border=0> <tr><td colspan=2><font size=2><strong>Sue.</strong></font></td></tr> <tr> <td colspan=2 align=\"center\">Make this comment <input type=radio selected name=PublicPrivate value=\"Public\" label=\"Public\"> <label for=\"Public\">Public</label> or <input type=radio name=PublicPrivate value=\"Private\" label=\"Private\"> <label for=\"Private\">Private</label> to th:</td> </tr> <tr> <td align=\"right\">Name:</td> <td> <input type=\"text\" name=\"name\" value=\"\" size=50> </td> </tr> <tr> <td align=\"right\" valign=\"top\">Email:</td> <td><input type=\"text\" name=\"Emss\" value=\"\" size=50><br> <font size=1 color=\"ff0000\">*Youy.</font></td> </tr> <tr> <td align=\"right\" valign=\"top\">Comments:</td> <td><font size=1 color=\"ff0000\">*Yongly.</font><br> <textarea cols=45 rows=10 name=\"Comments\"></textarea></td> </tr> <tr> <td> </td> <td><img src=\"http://a6.abc.com/f.jpg\"></td> </tr> <tr> <td align=\"right\" valign=\"top\">Pge:</td> <td align=\"left\"><input type=\"text\" maxlength=6 name=\"ImageCode\" value=\"\" size=10></td> </tr> <tr> <td colspan=2 align=\"center\"> <input type=\"hidden\" name=\"ArticleID\" value=\"36\"> <input type=\"hidden\" name=\"x\" value=\"gwSIMR\"> <input type=\"hidden\" name=\"Author
ID\" value=\"\"> <input type=\"hidden\" name=\"ReturnTo\" value=\"/article_detail.cfm?articleid=36\"> <input type=\"Submit\" value=\"Sut\" name=\"PostComment\"> </td> </tr> </table> </form> </td> </tr> <tr><td bgcolor=\"4D4D4D\"><img src=\"http://a1.abc.com/er.gif\" height=\"8\" width=\"100%\"></td></tr> </table> </td></tr> </table> </span> <br>','http://www.a.com/article_detail.cfm?articleid=36','-')
Here is a sqlfiddle.
Where am I making a mistake?
You'll need to escape things twice if you throw them in literal from PHP to MySQL. The first backslash will be interpreted by PHP, NOT by MySQL.
If you have a function called as follows (for example):
function_called("this\' quote");
The function will actually receive "this' quote", not the backslashed version.
To go around this, two solutions:
Rely on parametrization of queries provided by PDO or MySQLi (safer as well in the long run)
Double-escape stuff. This\' quote then becomes This\\\' quote. On first pass, \ is interpreted as \, \' turns into '. On second pass (MySQL), what remains is \'.
i think your insert query in wrong
you can use name=\"KonaFilter\" instead of name=KonaFilter
i think problem is at this line -
"s we’ll sues. Question 1:?"
try to replace this line to
"s we\’ll sues. Question 1:?"
I am working on a web based contact list for a friend. I have the html portion all done and working on the PHP scripts and such. I have the main page as a table in a while loop enclosed in form tags. I need two things to happen but not sure how to get this accomplished.
First, each row has to have two submit buttons, which one goes to edit and the other to details, and carries over the values in the global $_POST.
Second, the list will be about 300 rows, so i am using a while loop to create the table.
I have the form working and passing the data but it is always passing the last row of the table. Here is my main page with the table:
<?php
if
(!isset ($_SESSION['username']))
{
session_start();
}
?>
<html>
<head>
<title>Client Contact List</title>
</head>
<?php
$user1 = implode(',',$_SESSION);
//DB information
require_once('/includes/db.php');
//Declaring edit and details
$edit = "<INPUT type='image' src='/addressbook/images/edit.png' onclick='\addressbook\edit.php'>";
$details = "<INPUT type='image' src='/addressbook/images/contact.gif' name='details' onclick='f1.action='\addressbook\contact_details.php'>";
//Table declarations and such
mysql_connect("$host", "$username", "$password") or die(mysql_error());
mysql_select_db("$db_name")or die("cannot select DB");
$result = mysql_query("SELECT * FROM contacts") or die(mysql_error());
$num=mysql_numrows($result);
$user1 = implode(',',$_SESSION);
$userresults = "SELECT first FROM i_user where userid IN $user1";
$user = mysql_query($userresults);
// print_r ($_SESSION);
// print_r ($_POST);
?>
<body style="background-image: url('Images/background_login.jpg');">
<br><br><br><br><br><br>
<table>
<br><br>
<tr><td width="500">Welcome Back, <?php echo $user; ?></td><td width="500"></td><td width="300"><form name="search" method="post" id="searchform" action="<?php echo $_SERVER['PHP_SELF'];?>"><label for="searchtext">Search: </label><input type="text" name="name" /> <input type="submit" name="submit" value="Search" /></form>
</td></tr>
</table>
<br>
<form name="f1" method="post" action="/addressbook/edit.php">
<table border="1">
<tr>
<?php
echo "<table border='1'>";
echo "<tr>
<th>First</th>
<th>Last</th>
<th>Company</th>
<th>Primary Email</th>
<th>Secondary Email</th>
<th>Primary Phone</th>
<th>Second Phone</th>
<th>Action</th>
</tr>";
$i=0;
while ($i<$num) {
$id = mysql_result($result,$i,"id");
$first = mysql_result($result, $i, "first");
$last = mysql_result($result,$i, "last");
$company = mysql_result($result, $i, "company");
$email1 = mysql_result($result,$i, "email1");
$email2 = mysql_result($result,$i, "email2");
$phone = mysql_result($result,$i, "phone");
$mobile = mysql_result($result,$i, "mobile");
// Print out the contents of each row into a table
echo "<tr><td width = '100'><center><input type='hidden' value='$first' name='first'>";
echo $first;
echo "</center></td><td width = '100'><center><input type='hidden' value='$last' name='last'>";
echo $last;
echo "</center></td><td width = '100'><center><input type='hidden' value='$company' name='company'>";
echo $company;
echo "</center></td><td width = '100'><center><input type='hidden' value='$email1' name='email1'>";
echo $email1;
echo "</center></td><td width = '100'><center><input type='hidden' value='$email2' name='email2'>";
echo $email2;
echo "</center></td><td width = '100'><center><input type='hidden' value='$phone' name='phone'>";
echo $phone;
echo "</center></td><td width = '100'><center><input type='hidden' value='$mobile name='mobile'>";
echo $mobile;
echo "</center></td><td width = '100'><center>";
echo $edit;
echo "    ";
echo $details;
echo "</td></center></tr>";
echo "<input type='hidden' value='$id name='id'></td>";
$i++;
}
?>
</tr>
</table>
</form>
</body>
</html>
This get directed to either the details or edit page. Below is the edit page....
<?php
if
(!isset ($_SESSION['username']))
{
session_start();
}
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Contact Information</title>
</head>
<?php
//DB information
require_once('/includes/db.php');
mysql_connect("$host", "$username", "$password") or die(mysql_error());
mysql_select_db("$db_name")or die("cannot select DB");
$id = $_POST['id'];
$first = $_POST['first'];
$last = $_POST['last'];
$company = $_POST['company'];
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$phone = $_POST['phone'];
$mobile = $_POST['mobile'];
//pulling the record id from the main login page.
$first=$_POST['first'];
$query="SELECT * FROM contacts where last=$last";
$result=mysql_query($query);
print_r($_POST);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body style="background-image: url('Images/background_login.jpg');">
<br><br><br><br><br>
<!-- First Table with the back and search option but disabled for now -->
<table>
<br>
<tr>
<td width="500">
<input type='button' value='Back' onClick='history.go(-1)'>
</td>
<td width="500"></td>
<td width="300">
<!-- <form name="search" method="post" id="searchform" action="<?php echo $_SERVER['PHP_SELF'];?>">
<label for="searchtext">Search: </label>
<input type="text" name="name" /> <input type="submit" name="submit" value="Search" />
</form> -->
</td>
</tr>
</table>
<br><br>
<center>
<!-- Second Table with form data pulled out for Identify -->
<table>
<tr>
<th>
<table>
<tr>
<td bgcolor="silver" colspan="4"><center>Identify</center></td>
</tr>
<tr>
<td width="100"><center><b>Title</b></center></td>
<td width="100"></td>
<td width="150"><center><b>Company Name</b></center></td>
</tr>
<tr>
<td width="100"><input value="Title"></td>
<td width="100"></td>
<td width="100"><? echo $company ?></td>
</tr>
<tr><td colspan="4"></td></tr>
<tr>
<td width="100"><center><b>First Name</b></center></td>
<td width="100"></td>
<td width="100"><center><b>Last Name</b></center></td>
</tr>
<tr>
<td width="100"><input value="Test"></td>
<td width="100"></td>
<td width="100"><input value="Test"></td>
</tr>
</table>
</th> <!-- Space between the contact info and Indenty -->
<td width="100">
</td>
<th>
<td> <!-- Third Table with form data pulled out -->
<table>
<tr>
<td bgcolor="silver" colspan="4"><center>Contact Information</center></td>
</tr>
<tr>
<td width="100"><center><b>Office Phone</b></center></td>
<td width="100"></td>
<td width="150"><center><b>Mobile Name</b></center></td>
</tr>
<tr>
<td width="100"><input value="Test"></td>
<td width="100"></td>
<td width="100"><input value="Test"></td>
</tr>
<tr>
<td colspan="4"></td>
</tr>
<tr>
<td width="100"><b>Primary Email</b></td>
<td width="100"></td>
<td width="150"><b>Secondary Email</b></td>
</tr>
<tr>
<td width="100"><input value="Test"></td>
<td width="100"></td>
<td width="100"><input value="Test"></td>
</tr>
</table>
</td>
</th>
<tr height="100"> <td colspan="9"></td> </tr>
<th class="style2">
<table>
<tr width="400"></tr>
<tr>
<td bgcolor="silver" colspan="4"><center>Applications Used</center></td>
</tr>
<tr>
<td width="100"></td>
</tr>
<tr>
<td colspan="4"></td>
</tr>
<tr>
<td width="100"></td>
</tr>
<tr>
<td width="100"></td>
<td width="100"></td>
<td width="100"></td>
<td width="100"></td>
</tr>
</table>
</th>
<td width="200"></td>
<td>
<th class="style2">
<table>
<tr>
<td bgcolor="silver" colspan="4"><center>Internal Information</center></td>
</tr>
<tr>
<td width="100"><center><b>Account Mgr</b></center></td>
<td width="100"></td>
<td width="150"><center><b>Client Relations</b></center></td>
</tr>
<tr>
<td width="100"><input value="Test"></td>
<td width="100"></td>
<td width="100"><input value="Test"></td>
</tr>
<tr><td colspan="4"></td></tr>
<tr>
<td width="200"><center><b>Acct Development</b></center></td>
<td width="100"></td>
<td width="100"><center><b>Project Mgr</b></center></td>
</tr>
<tr>
<td width="100"><input value="Test"></td>
<td width="100"></td>
<td width="100"><input value="Test"></td>
</tr>
</table>
</th>
</td>
</table>
</center>
</body>
</html>
Any thoughts on how to get this done?
Put the form tag inside the loop. And place the submit button inside the form tag.
It sounds like you need a lot of form, instead of a form with a lot of field.
Yet another suggestion.. jqgrid may be a good thing to use here. look it up if you got a chance.
The problem is you are creating a ton of elements that have the same name... Every row has a input by the name of email1, email2, phone, mobile, etc.
when you submit the form it just takes the value of the last html element with the given name. So it will alwyas give you the last row.
What you can do is only have 1 hidden input for each attribute. Then when you select a row, you can set the values for the hidden inputs using javascript.
HOWEVER, to make it more simple... You are already storing all of the users data in a database so you don't need to pass it all to the next page. Just pass the id to the next page, then when you get to the next page perform a select query to get all of that user's data.
This way you can have 1 hidden input for the id. When the user selects the row they want to edit use Javascript to set the value of that input.
Each button should look something like this:
echo "<input type=\"button\" onclick=\"document.form.id=$id\">";
The input should look something like this:
echo "<input type=\"hidden\" name=\"id\"/>";
Then on the edit page use :
$id = $_POST['id'];
$query = "SELECT id, first, last, company, email1, email2, phone, mobile
FROM contacts WHERE ID=$id"
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
$id = $row['id'];
$first = $row['first'];
etc...