PHP - View/update Data Already In The Database
I have a page that lists the available records in the database and has links that allow one to view details, edit existing details and delete the data. when i click the view details link, i dont get the correct details for the person but for another person in the database . the link to edit existing details is also not working. following is my code. help!!!!
//list available records <? $CONTENT=" <form name=\"form1\" method=\"post\" action=\"\"> <table width=\"100%\" border=\"0\"> <tr> <td width=\"19%\" align=\"right\"><font size='-1px'>Search for : </font></td> <td width=\"61%\" colspan=\"2\"><label> <select name=\"select\" id=\"select\"> <option value=\"std\">Student Name</option> <option value=\"class\">Class Name</option> <option value=\"std_id\">Student ID</option> </select> </label> <label> <input type=\"text\" name=\"textfield\" id=\"textfield\"> <input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\"> </label></td> <td width=\"10%\"> </td> </tr> </table> <table width=\"100%\" border=\"0\"> <tr bgcolor=\"#666666\"> <td align=\"center\"> </td> <td align=\"center\"> </td> <td colspan=\"2\" align=\"center\"><font size='-1px'>Pages x of xn</font></td> <td align=\"center\"> </td> <td align=\"center\"> </td> <td align=\"center\"> </td> <td colspan=\"3\" align=\"center\"> </td> </tr> <tr bgcolor=\"#999999\"> <td align=\"center\" width='2%'> </td> <td align=\"center\" width='2%'><font size='-1px'>#</font></td> <td align=\"center\" width='11%'><font size='-1px'>Class</font></td> <td align=\"center\" width='23%'><font size='-1px'>Names</font></td> <td align=\"center\" width='13%'><font size='-1px'>Fees Status</font></td> <td align=\"center\" width='21%'><font size='-1px'>Guardian</font></td> <td align=\"center\" width='18%'><font size='-1px'>Teacher</font></td> <td colspan=\"3\" align=\"center\"> </td> </tr>"; /*$query = "SELECT * FROM `student`, `payment`, `class`, `parent_details`, `teacher` WHERE `payment`.`student_id`=`student`.`student_id` and `student`.`class_id` = `class`.`class_id` and `student`.`guardian_id`=`parent_details`.`parent_id` and `teacher`.`class_id` = `class`.`class_id`";*/ //$student_id = $_GET['std_id']; /* $query= "SELECT `student`.`student_id` FROM `student` FULL JOIN `payment` ON `student`.`student_id` = `payment`.`student_id` ORDER BY `student`.`student_id`";*/ $query = "select * from `student`, `payment`, `class`, `parent_details`, `teacher` where payment.student_id = student.student_id and student.class_id = class.class_id and student.guardian_id = parent_details.parent_id"; $result = mysql_query($query); //$numstudents = mysql_num_rows($result); $count=1; //if($count = 0; $count<=$num_students; $count++) //{ while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $CONTENT.="<tr bgcolor=\"#CCFFFF\"> <td><label> <input type=\"checkbox\" name=\"checkbox\" id=\"checkbox\"> </label></td> <td><font size='-1px'>".$count."</font></td> <td><font size='-1px'>".$row["class_name"]."</font></td> <td><font size='-1px'>".$row["first_name"]." ".$row["last_name"]."</font></td> <td><font size='-1px'>".$row["amount"]."</font></td> <td><font size='-1px'>".$row["fname"]."</font></td> <td><font size='-1px'>".$row["tr_name"]."</font></td> <td width=\"2%\"><a href=\"student_details.php?std_id=".$row["student_id"]."\"><img src=\"images/b_browse.png\" height=\"12\" alt=\"Details\"></a></td> <td width=\"2%\"><a href=\"student_edit.php?action=edit&std_id=".$row["student_id"]."\"><img src=\"images/b_edit.png\" height=\"12\" alt=\"Edit\"></a></td> <td width=\"2%\"><a href=\"student_edit.php?action=del&std_id=".$row["student_id"]."\"><img src=\"images/b_drop.png\" height=\"12\" alt=\"Delete\"></a></td> </tr> "; $count++; } $CONTENT.="</table> </form>"; ?> //view details <? $query = "SELECT * FROM `student`, `academic_background`, `class` WHERE `academic_background`.`student_id`=`student`.`student_id` "; //and `student`.`class_id` = `class`.`class_id`"; //`academic_background`.`student_id`=`student`.`student_id` and `student`.`class_id` = `class`.`class_id`"; $result = mysql_query($query); //$count = 0; //$num_students = mysql_num_rows($result); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { //$student_id = $_GET['std_id']; //$bg_id = $_GET['bg_id']; $CONTENT=" <form> <table width=\"100%\" border=\"0\"> <tr> <td width=\"38%\"><img src=\"images/images1.jpg\" /></td> <td width=\"62%\"></td> </tr> <tr> <td><font size='+2px'>Student ID:</font></td> <td><font size='+2px'>".$row["student_id"]."</font></td> </tr> <tr> <td><font size='+2px'>Student Name:</font></td> <td><font size='+2px'>".$row["first_name"]." ".$row["last_name"]."</font></td> </tr> <tr> <td><font size='+2px'>Date of Birth:</font></td> <td><font size='+2px'>".$row["dob"]."</font></td> </tr> <tr> <td><font size='+2px'>Current Class:</font></td> <td><font size='+2px'>".$row["class_name"]."</font></td> </tr> <tr> <td><font size='+2px'>Primary School:</font></td> <td><font size='+2px'>".$row["pschool"]."</font></td> </tr> <tr> <td><font size='+2px'>K.C.P.E Marks:</font></td> <td><font size='+2px'>".$row["total_marks"]."</font></td> </tr> </table> </form> "; // $count += 1; } ?> edit details <? if($_GET['action']=="edit") { $std_id = $_GET['std_id']; $query= "SELECT * FROM `mackenzie`.`student` WHERE std_id = '$student_id'"; $result= mysql_query($query); //assign student info to variablea list($student_id, $first_name,$last_name,$date_of_birth,$class_id,$picture,$home,$guardian_id) = mysql_fetch_array($result, MYSQL_ASSOC); include("/modify.php"); } ?> Similar TutorialsI am caught between a rock and a hard place here... My update page (to update an existing entity in the database) is a normal selection page, which then directs you to the page where you can update or change the data (1st srcipt snippet below), up to here everything works well, but on submit the page must be directed to a page that verifies the data (2nd script snippet below) and if correct, update the database or redirect to the 2nd page to correct the faulty data entry - easy right (well I have been struggling to get this working for 2 days straight. Pleeaaaaase Help. After the selection page, this is the input page-script:- Code: [Select] $labels = array("company_descr" => "Description:"); include("../includes/xxxxxxxxx.inc"); // database login details $cxn = mysqli_connect($host,$user,$password,$dbname) or die ("Couldn't connect to server."); $query = "SELECT * FROM `company` WHERE `company_id`=\"{$_POST['comp']}\""; $result = mysqli_query($cxn,$query) or die ("Cannot execute query."); $row = mysqli_fetch_assoc($result); ?> <html> <head> <title>Update Location</title> <style type='text/css'> <!-- form { margin: 1.5em 0 0 0; padding: 0; } .field { padding-top: .5em; } label { font-weight: bold; float: left; margin-right: 1em; text-align: right; } #submit { margin-left: 20%; padding-top: 1em; } --> </style> <body> <?php echo "<div style='text-align: centre'> <h3>Update Company - \"{$_POST['comp']}\"</h3>\n"; echo "<p style='font-color: #FF0000; font-size: 12; font-align: center'> Please change the field(s) that you want to update below.</p> <hr /></div>\n"; echo "<form action='../update/updateCompany.php' method='POST'>"; foreach($labels as $field => $label) { echo "<div class='field'> <label for='$field'>$label</label> <input type='text' name='$field' id='$field' value='$row[$field]' size='35' maxlength='35' /></div>\n"; } echo "<div id='submit'><input type='submit' value='Update' />\n"; echo "</div>\n</form>\n</body>\n</html>"; ?> This is the script that is supposed to verify the data and then send you back to the input page or update the database if the data is correct Code: [Select] foreach($_POST as $field => $value) { if(empty($value)) { $blanks[] = $field; } else { $good_data[$field] = strip_tags(trim($value)); } } if(isset($blanks)) { $message_2 = "The following fields are blank. Please enter the required information: "; foreach($blanks as $value) { $message_2 .="$value, "; } extract($good_data); include("../updateInput/updateInputCompanyTest.php"); exit(); } /* validate data */ foreach($_POST as $field => $value) { if(empty($value)) { if(preg_match("/descr/i",$field)) { if(!preg_match("/^[A-Za-z0-9.,' -]{1,50}$/",$value)) { $errors[] = "$value is not a valid address or city."; } } } // end if not empty } foreach($_POST as $field => $value) { $$field = strip_tags(trim($value)); } if(@is_array($errors)) { $message_2 = ""; foreach($errors as $value) { $message_2 .= $value." Please try again<br />"; } include("../updateInput/updateInputCompanyTest.php"); exit(); } // end if errors are found else // add new member to database { include("../includes/xxxxxxxx.inc"); // database login details $cxn = mysqli_connect($host,$user,$password,$dbname) or die ("Couldn't connect to server."); $query = "INSERT INTO `company` (`company_descr`) VALUES ('$company_descr') WHERE `company_id`=\"{$_POST['comp']}\""; $result = mysqli_query($cxn,$query) or die ("Couldn't execute query."); header("Location: ../backtomainpage.php"); } include("../updateInputCompanyTest.php"); ?> Hi guys, I have a trouble of updating the data in the database by input the data at the end of the url. It have not been added in the table. Here it is updated: <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'myusername'); define('DB_PASSWORD', 'mypassword'); define('DB_DATABASE', 'mydatabasename'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $login = clean($_GET['user']); $password = clean($_GET['pass']); $firstname = clean($_GET['firstname']); if($login == '') { $errmsg_arr[] = 'Login ID missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'PASSWORD ID missing'; $errflag = true; } if($value == '') { $errmsg_arr[] = 'THE first name IS missing'; $errflag = true; } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE login='$login' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result) > 0) { $row = mysql_fetch_row($result); echo $row[0]; } else { echo 'Username, Password or first name is not found.'; close; $sql="INSERT INTO members (firstname, lastname) VALUES ('$_POST[firstname]','$_POST[lastname]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "first name have been updated"; } ?> It have only login in the database but did not doing any update when I have input the data at the end of the url to get the database update. Do you know why I can't update the data in the database by input the data in the url like this? http://www.mysite.com/updatemysql.php?user=test&pass=test&firstname=shitorwhateveriwanttoinputandgetitupdate Do you have any idea and maybe if I have miss something? HI, according to my knowledge session_destroy() function would destroy all session variables and mysql_close() would close connection with the database. i make a simply logoff.php file and close myssql connection and destroy session. but i still get values from the database and session variables. and doesnt work properly here is the code Code: [Select] <?php session_start(); /* * To change this template, choose Tools | Templates * and open the template in the editor. */ require_once '../database/db_connecting.php'; $dbname="sahansevena";//set database name $con= setConnections();//make connections use implemented methode in db_connectiong.php mysql_select_db($dbname, $con); //update the time and date of the admin table $update_time="update admin set last_logged_date =CURDATE(), last_log_time=CURTIME() where username='$uname'limit 3,4"; //my admin table contain 5 colums they are id, username,password, last_logged_date, last_log_time $link= mysql_query($update_time); // mysql_select_db($dbname, $link); //$con=mysql_connect('localhost', 'root','ijts'); $result="select * from admin where username='a'"; $result=mysql_query($result); mysql_close($con); //here i just check after closing data baseconnection whether i do get reselts but i do, why? echo "after the cnnection was closed"; echo "<html>"; echo "<table border='1' cellspacing='1' cellpadding='2' align='center'>"; echo "<thead>"; echo"<tr>"; echo "<th>"; echo ID; echo"</th>"; echo" <th>";echo Username; echo"</th>"; echo"<th>";echo Password; echo"</th>"; echo"<th>";echo Last_logged_date; echo "</th>"; echo "<th>";echo Last_logged_time; echo "</th>"; echo" </tr>"; echo" </thead>"; echo" <tbody>"; while($row= mysql_fetch_array($result,MYSQL_BOTH)){ echo "<tr>"; echo "<td>"; echo $row[0]; echo "</td>"; echo "<td>"; echo $row[1]; echo "</td>"; echo "<td>"; echo $row[2]; echo "</td>"; echo "<td>"; echo $row[3]; echo "</td>"; echo "<td>"; echo $row[4]; echo "</td>"; echo "</tr>"; } echo" </tbody>"; echo "</table>"; echo "</html>"; session_destroy(); session_commit(); echo "session and database are closed but i still get values".$_SESSION['admin']; ?> Hi i have this simple update form and scrip but somehow it doesnt seem to be update the field on the database can someone help out please. The html form is the second form bellow where the action send to status_update.php HTML FORM Code: [Select] <?php include("../header.html"); ?> <?php include("header_news.html"); extract($_REQUEST,EXTR_SKIP); ?><?php /* print("sfilm_refnum = $sfilm_refnum<BR>"); print("sfilm_addr01 = $sfilm_addr01<BR>"); print("sfilm_postcode = $sfilm_postcode<BR>"); print("Film Client = $fclient<BR>"); */ ?> <form id="search" action="list.php" method="post" name="search"> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td align="right" width="140"></td> <td width="320"><span class="hofblack10"> </span> </td> <td align="center" width="100"><input type="hidden" name="lstart" value="<?php print("$lstart"); ?>" /><input type="hidden" name="lend" value="<?php print("$lend"); ?>" /><input type="hidden" name="lamount" value="<?php print("$lamount"); ?>" /></td> <td align="center" width="100"></td> <td align="right"></td> </tr> </table> </form> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#4050c4"> <tr> <td width="60" class="hofwhite10">action</td> <td width="140"><span class="hofwhite14">DATE</span></td> <td width="80"><span class="hofwhite14">ID</span></td> <td><span class="hofwhite14">News Titile</span></td> <td width="100"><span class="hofwhite14">Status</span></td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table><table width="780" border="0" cellspacing="0" cellpadding="4"><tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> <tr height="0"> <td width="60" height="0"></td> <td width="80" height="0"></td> <td height="0"></td> <td align="right" width="120" height="0"></td> </tr> </table> <?php //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select DATABASE."); $query2="SELECT * FROM news WHERE !(news_status='deleted')"; $result2 = mysql_query($query2) or die("Couldn't execute QUERY - Select NEWS Qty"); $fqty = mysql_num_rows($result2); //SELECT or FIND the same USERNAME $query3="SELECT * FROM news WHERE !(news_status='deleted') ORDER BY news_id DESC"; $result3 = mysql_query($query3) or die("Couldn't execute QUERY - Select NEWS"); while ($row = mysql_fetch_array($result3)) { $news_id = $row['news_id']; $news_title = $row['news_title']; $news_story = $row['news_story']; $news_image = $row['news_image']; $news_image_caption = $row['news_image_caption']; $news_image_link = $row['news_image_link']; $news_date_day = $row['news_date_day']; $news_date_month = $row['news_date_month']; $news_date_year = $row['news_date_year']; $news_status = $row['news_status']; $news_website = $row['news_website']; $news_date_created = $row['news_date_created']; $news_date_modified = $row['news_date_modified']; ?> <table width="780" border="0" cellspacing="0" cellpadding="4" bgcolor="#eeeeee"> <tr> <td width="60"><span class="hofblack10"> <?php if($news_status=="deleted"){ print("<a class='hifblack10'>deleted</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>edit</a>"); } ?> </span></td> <td width="140"><span class="titlegrey12"> <?php if(!$news_date_day) { echo "00"; } else{ echo $news_date_day; } echo "/"; if(!$news_date_month) { echo "00"; }else{ echo $news_date_month; } echo "/"; if(!$news_date_year) { echo "0000"; }else{ echo $news_date_year; } ?> </span></td> <td width="80"><span class="titlegrey12"><?php print("$news_id"); ?></span> </td> <td><?php if($news_status=="deleted") { print("<class='hofblack10'>$news_title</span>"); }ELSE{ print("<a class='blueul' href='edit.php?id=$news_id'>$news_title</a>"); } ?></td> <td width="100"> <form id="list_update" action="status_update.php" method="post" name="list_update"> <select name="newnstatus" size="1"> <option <?php if($row['news_status'] == "") { print("selected"); } ?> selected="selected" value="">Status...</option> <option <?php if($row['news_status'] == "on") { print("selected"); } ?> value="on">On</option> <option <?php if($row['news_status'] == "off") { print("selected"); } ?> value="off">Off</option> <option <?php if($row['news_status'] == "deleted") { print("selected"); } ?> value="deleted">Delete</option> </select> <input type="hidden" name="nstatus" value="<?php echo $row[news_status]; ?>" /> <input type="hidden" name="id" value="<?php echo $row[news_id]; ?>" /> <input type="submit" name="update" value="update" /> </form> </td> </tr> <tr height="0"> <td bgcolor="white" width="60"></td> <td bgcolor="white" width="140" height="0"></td> <td bgcolor="white" width="80" height="0"></td> <td bgcolor="white" height="0"></td> <td bgcolor="white" width="100" height="0"></td> </tr> </table> <?php } mysql_close($connection);//}?> <table width="780" border="0" cellspacing="0" cellpadding="4"> <tr> <td width="60"></td> <td width="80"></td> <td><a class="blueullrg" href="add.php">Add News</a></td> <td align="right" width="120"></td> </tr> </table><?php // include("list_navigation.html"); ?> <?php include("../footer.html"); ?> </div></body></html> The action script php Code: [Select] <?php /* echo "fstatus: ".$fstatus."<BR>"; echo "id: ".$id."<BR>"; echo "fclient: ".$fclient."<BR>"; echo "newfstatus: ".$newfstatus."<BR>";*/ //set the date of agreement $timestamp = date('l jS \of F Y h:i:s A'); //get the DB connection variables include("../../../includes/config.php"); //connect to DB $connection = @mysql_connect($db_address,$db_username,$db_password) or die("Couldn't CONNECT."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select FILMS DATABASE."); // All appears well, so enter into database $query= "UPDATE news SET news_status = '$newnstatus' WHERE news_id='$id'"; $result = mysql_query($query) or die("could not execute query - Update FILMS Record to DB"); //setup an email to the Admin @ hof, w/o attachment $emailto="xx@xxx.co.uk"; $emailfrom="no-reply@xxxx.co.uk"; $emailsubject="xx Record Updated"; $emailmessage="Hello Registrar\n\n"; $emailmessage.="News ID: ".$id."\n"; $emailmessage.="Updated on: ".$timestamp."\n\n"; $emailmessage.="Status was: ".$nstatus."\n"; $emailmessage.="Status now: ".$newfnstatus."\n"; $emailmessage.="Thank you,\n\n"; $emailmessage.="Web Site ROBOT\n"; $emailmessage.="(Administrator)\n"; $emailmessage.="xxx.co.uk | xxx.biz\n"; $emailmessage.="----------------------------------------------\n"; $emailmessage.="e. http://www.xxx.co.uk/contact.php\n"; $emailmessage.="w. http://www.xxx.co.uk\n"; $emailheader="From: xxx.co.uk<$emailfrom>"; $emailheader .= 'Cc: xxx@xxx.co.uk'."\r\n"; $emailheader .= 'Bcc: xxx@xxxxx.co.uk'."\r\n"; $ok=mail($emailto,$emailsubject,$emailmessage,$emailheader); mysql_close($connection); if ($ok) { header("Location: list.php"); /* Redirect browser */ exit; } else { $errmsg="There was a problem, please try later or telephone us direct."; $errsta="1"; include("edit_error.html"); //echo "<p>Mail could not be sent. Sorry!</p>"; exit; } ?> Thanks in advance Please help! how can i query data from different tables? I've tried so many codes already but it won't work.
Attached Files
Untitled1.png 39.93KB
0 downloads Hello im new to php and i cant seems to view my database in my php
<?php include('../connect.php'); $sds=$_SESSION['SESS_FIRST_NAME']; $result = mysql_query("SELECT * FROM paymentdetails WHERE idnumber='$sds'"); while($row = mysql_fetch_array($result)) { echo '<tr class="record">'; echo '<td style="border-left: 1px solid #C1DAD7"><div align="left">'.$row['date'].'</div></td>'; echo '<td><div align="left">'.$row['amount'].'</div></td>'; echo '</tr>'; } ?> </tbody> </table>Here my database im really confuse on what to do CREATE TABLE IF NOT EXISTS `paymentdetails` ( `id` int(11) NOT NULL AUTO_INCREMENT, `idnumber` varchar(30) NOT NULL, `date` varchar(30) NOT NULL, `amount` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `paymentdetails` -- INSERT INTO `paymentdetails` (`id`, `idnumber`, `date`, `amount`) VALUES (1, 'SID-YWU49JU', '2014-08-07', '50000'); this is my query Code: [Select] SELECT SUM(no_Yards) AS 'yards', AVG(no_yards) AS 'avg', MAX(no_Yards) AS 'max', MIN(no_Yards) AS 'min' FROM swimming WHERE Season = '$ws' and when i display the data i want to display the date that the max and the min happened (from the database in the column Day_Swam) something like this Code: [Select] <?php echo "<tr>"; echo "<td style='background-color:#F90'>Max Length:</td>"; echo "<td>" . number_format($wsi_row['max']) . "</td>"; echo "<td>" . DATE WOULD GO HERE . "</td>"; echo "</tr>"; echo "</tr><tr>"; echo "<td style='background-color:#F90'>Min Length:</td>"; echo "<td style='background-color:#FF9'>" . number_format($wsi_row['min']) . "</td>"; echo "<td>" . DATE WOULD GO HERE . "</td>"; echo "</tr>"; ?> Hi I will try and explain this as best I can, as I am not sure if the "include" is causing the problem. What I am trying to achieve is count the total number of vehicles in the "vehicles" db table and pass it to views (I have recently moved over to MVC so still learning so please be kind and keep it simple for me please) I have a folder in views called "vehicletracker" , within this folder I have 2 files "index.php" and "widget.php".........The "widget.php" file is an "include" within "index php". The problem I am having is passing data from the controller to the view, I keep getting an "Undefined index: total" error and wonder if someone can help and show me where I am going wrong. This is my Model
<?php class Widget { private $db; public function __construct(){ $this->db = new Database; } public function countVehicles(){ $this->db->query("SELECT * FROM vehicles"); return $this->db->rowCount(); } } This is my controller
<?php class Widgets extends Controller{ public function __construct(){ $this->widgetModel = $this->model('Widget'); public function widget (){ $data['total'] = $this->widgetModel->countVehicles(); $this->view('vehicletracker/widget', $data); } } And my view
<h2 class="text-white"><?php echo $data['total']; ?></h2>
Thanks in advance for any help you can give Hi, after banging my head against the wall for a while thinking this would be a simple task, I'm discovering that this is more complicated than I thought. Basically what I have is a link table linking together source_id and subject_id. For each subject there are multiple sources associated with each. I had created a basic listing of sources by subject... no problem. I now need a way of having a form to create an ordered list in a user-specified way. In other words, I can currently order by id or alphabetically (subject name lives on a different table), but I need the option of choosing the order in which they display. I added another row to this table called order_by. No problem again, and I can manage all of this in the database, however I want to create a basic form where I can view sources by subject and then enter a number that I can use for sorting. I started off looping through each of the entries and the database (with a where), and creating a foreach like so (with the subject_id being grabbed via GET from the URL on a previous script) Code: [Select] while($row = mysqli_fetch_array($rs)) { //update row order if (isset($_POST['submit'])) { //get variables, and assign order $subject_id = $_GET['subject_id']; $order_by = $_POST['order_by']; $source_id = $row['source_id']; //echo 'Order by entered as ' . $order_by . '<br />'; foreach ($_POST['order_by'] as $order_by) { $qorder = "UPDATE source_subject set order_by = '$order_by' WHERE source_id = '$source_id' AND subject_id = '$subject_id'"; mysqli_query($dbc, $qorder) or die ('could not insert order'); // echo $subject_id . ', ' . $order_by . ', ' . $source_id; // echo '<br />'; } } else { $subject_id = $_GET['subject_id']; $order_by = $row['order_by']; $source_id = $row['source_id']; } And have the line in the form like so: Code: [Select] echo '<input type="text" id="order_by" name="order_by[]" size="1" value="'. $order_by .'"/> (yes I know I didn't escape the input field... it's all stored in an htaccess protected directory; I will clean it up later once I get it to work) This, of course, results in every source_id getting the same "order_by" no matter what I put into each field. I'm thinking that I need to do some sort of foreach where I go through foreach source_id and have it update the "order_by" field for each one, but I must admit I'm not sure how to go about this (the flaws of being self-taught I suppose; I don't have anyone to go to on this). I'm hoping someone here can help? Thanks a ton in advance This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314265.0 Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. hi guys, im new to this forum I'm new also to php, I need help from you guys: I want to display personal information from a certain person (the data is on the mysql database) using his name as a link: example: (index.php) names 1. Bill Gates 2. Mr. nice Guy i want to click Bill Gates (output.php) Name: Bill Gates Country:xxxx Age: xx etc. How can i make this or how to learn this? Hi, I've currently started to modify a chat script of mine to output a moderation panel but the moderation page seems empty(blank) every time I load it. What im trying to do is to take the ID part in my URL via the $_GET and look it up in my database table in the column named id, then select that specific row to be able to retrieve the StringyChat_ip and place it into another table to ban the IP and the second thing im trying to do is to be able to delete the specific row from my table.
My Http link look something like
http://imagecrab.fre.../ban.php?id=159
and my ban.php page where I want to lookup the 159 part and do the banning etc looks like
<? include("admin_code_header.php"); if ($_POST["DeletePost"]) { $id = $_POST['id']; $query = "DELETE FROM ".$dbTable." WHERE id='".$id."'"; mysql_query($query); echo "ID removed from system: ".$id; } if ($_POST["BanIP"]) { $IP_To_Add = $_POST["ip"]; $sql = "INSERT INTO ".$IPBanTable." (ip) VALUES (\"$IP_To_Add\")"; $result = mysql_query($sql); } $result = mysql_query("SELECT * FROM ".$dbTable." WHERE id='".$id."'",$db); while ($myrow = mysql_fetch_array($result)) { $msg = $myrow["StringyChat_message"]; $idm = $myrow["id"]; ?> <html> <form name="form<? echo $myrow["id"];?>" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input name="DeletePost" type="submit" id="DeletePost" value="Delete"> <input name="BanIP" type="submit" id="BanIP" value="Ban <? echo $myrow["StringyChat_ip"];?>"> </form> </html> <? } ?> Hello I am updating a SQL database - basically adding to an account field as follows... $sql1 = "select * from member where username = \"$owner\" limit 1 "; $result1 = mysql_query($sql1, $conn) or die(mysql_error()); $row1 = mysql_fetch_assoc($result1); $total_commissions = $row1['total_commissions']; $total_commissions = $total_commissions + $_SESSION['cost_per_token']; //add to data $balance = $row1['balance']; $balance = $balance + $_SESSION['cost_per_token']; //add to data #-------------------------------------------------------------------------- #Update db $sql1 = " UPDATE member SET total_commissions = \"$total_commissions\", balance = \"$balance\" WHERE username=\"$owner\" "; $result1 = mysql_query($sql1, $conn) or die(mysql_error()); is there a way to add to the data from the UPDATE query? e.g; $sql1 = " UPDATE member SET total_commissions = \"$total_commissions\ + $_SESSION['cost_per_token'] ", balance = \"$balance\ + $_SESSION['cost_per_token']" WHERE username=\"$owner\" "; Hi guys, I have had to make some changes to a database that I updated hockey players stats with. Since doing this I can no longer edit player stats in my admin section of the website. I was wondering if someone could possibly have a look at it for me. It is driving me nuts not being able to fix it. What should happen is: I choose the player from a list of teams to update. Their stats show up on next page in a table for the different competitions they play in (league, cup, play-offs). I could then update the stats and then once pressing the edit button at the bottom, this then updates my SQL database. Can anyone help? <?php if ($stat==1) { // normal players $table = "players"; } else { // snl_players $table ="snl_players"; } if ($act==edit) { $query11 = "SELECT * FROM `$table` WHERE `PlayerID` = '$PlayerID'"; $result11 = mysql_query($query11) or die ('Error: Sh2'); $rows = mysql_fetch_array($result11); $PlayerID = $rows['PlayerID']; $TeamID = $rows['TeamID']; $Team = $rows['Team']; $Player = $rows['Player']; $Games = $rows['Games']; $Goals = $rows['Goals']; $PPGoals = $rows['PPGoals']; $SHGoals = $rows['SHGoals']; $Assists = $rows['Assists']; $PIM = $rows['PIM']; $Points = $rows['Points']; $GamesCup = $rows['GamesCup']; $GoalsCup = $rows['GoalsCup']; $PPGoalsCup = $rows['PPGoalsCup']; $SHGoalsCup = $rows['SHGoalsCup']; $AssistsCup = $rows['AssistsCup']; $PIMCup = $rows['PIMCup']; $PointsCup = $rows['PointsCup']; /* $GamesNPL = $rows['GamesNPL']; $GoalsNPL = $rows['GoalsNPL']; $PPGoalsNPL = $rows['PPGoalsNPL']; $SHGoalsNPL = $rows['SHGoalsNPL']; $AssistsNPL = $rows['AssistsNPL']; $PIMNPL = $rows['PIMNPL']; $PointsNPL = $rows['PointsNPL']; */ $GamesPO = $rows['GamesPO']; $GoalsPO = $rows['GoalsPO']; $PPGoalsPO = $rows['PPGoalsPO']; $SHGoalsPO = $rows['SHGoalsPO']; $AssistsPO = $rows['AssistsPO']; $PIMPO = $rows['PIMPO']; $PointsPO = $rows['PointsPO']; $Nationality = $rows['Nationality']; $query11 = "SELECT * FROM `teams` WHERE `TeamID` = '$TeamID'"; $result11 = mysql_query($query11) or die ('Error: Sh2'); $rows = mysql_fetch_array($result11); $TeamName = $rows['TeamName']; echo ("<form name=\"form1\" method=\"post\" action=\"playerstats.php?act=editdo&PlayerID=$PlayerID&stat=$stat\"> <table width=\"80%\" border=\"0\"> <tr> <td width=\"30%\" class=\"data\">Player Name </td> <td width=\"70%\"><input name=\"Player\" type=\"text\" id=\"Player\" value=\"$Player\"></td> </tr> <tr> <td class=\"data\">Associated Team ID </td> <td class=\"data\"> <select name=\"TeamID\">"); $query11 = "SELECT * FROM `teams`"; $result11 = mysql_query($query11) or die ('Error: Sh2'); while ( $rows = mysql_fetch_array($result11) ) { $TeamName = $rows['TeamName']; $TeamID2 = $rows['TeamID']; if ($TeamID==$TeamID2) { echo(" <option value=\"$TeamID2\" selected>$TeamName</option>"); } else { echo(" <option value=\"$TeamID2\">$TeamName</option>"); } } echo("</select></td> </tr> <tr> <td class=\"data\">Games</td> <td><input name=\"Games\" type=\"text\" id=\"Games\" size=\"6\" value=\"$Games\"></td> </tr> <tr> <td class=\"data\">Goals</td> <td><input name=\"Goals\" type=\"text\" id=\"Goals\" size=\"6\" value=\"$Goals\"></td> </tr> <tr> <td class=\"data\">PPGoals</td> <td><input name=\"PPGoals\" type=\"text\" id=\"Goals\" size=\"6\" value=\"$PPGoals\"></td> </tr> <tr> <td class=\"data\">SHGoals</td> <td><input name=\"SHGoals\" type=\"text\" id=\"Goals\" size=\"6\" value=\"$SHGoals\"></td> </tr> <tr> <td class=\"data\">Assists</td> <td><input name=\"Assists\" type=\"text\" id=\"Assists\" size=\"6\" value=\"$Assists\"></td> </tr> <tr> <td class=\"data\">PIM</td> <td><input name=\"PIM\" type=\"text\" id=\"PIM\" size=\"6\" value=\"$PIM\"></td> </tr> <tr> <td class=\"data\">Points</td> <td><input name=\"Points\" type=\"text\" id=\"Points\" size=\"6\" value=\"$Points\"></td> </tr> <tr> <td class=\"data\">GamesCup</td> <td><input name=\"GamesCup\" type=\"text\" id=\"GamesCup\" size=\"6\" value=\"$GamesCup\"></td> </tr> <tr> <td class=\"data\">GoalsCup</td> <td><input name=\"GoalsCup\" type=\"text\" id=\"GoalsCup\" size=\"6\" value=\"$GoalsCup\"></td> </tr> <tr> <td class=\"data\">PPGoalsCup</td> <td><input name=\"PPGoalsCup\" type=\"text\" id=\"GoalsCup\" size=\"6\" value=\"$PPGoalsCup\"></td> </tr><tr> <td class=\"data\">SHGoalsCup</td> <td><input name=\"SHGoalsCup\" type=\"text\" id=\"GoalsCup\" size=\"6\" value=\"$SHGoalsCup\"></td> </tr> <tr> <td class=\"data\">AssistsCup</td> <td><input name=\"AssistsCup\" type=\"text\" id=\"AssistsCup\" size=\"6\" value=\"$AssistsCup\"></td> </tr> <tr> <td class=\"data\">PIMCup</td> <td><input name=\"PIMCup\" type=\"text\" id=\"PIMCup\" size=\"6\" value=\"$PIMCup\"></td> </tr> <tr> <td class=\"data\">PointsCup</td> <td><input name=\"PointsCup\" type=\"text\" id=\"PointsCup\" size=\"6\" value=\"$PointsCup\"></td> </tr> "); if ($stat==1) { } else { echo(" <tr><td class=\"data\">GamesPO</td> <td><input name=\"GamesPO\" type=\"text\" id=\"GamesPO\" size=\"6\" value=\"$GamesPO\"></td> </tr> <tr> <td class=\"data\">GoalsPO</td> <td><input name=\"GoalsPO\" type=\"text\" id=\"GoalsPO\" size=\"6\" value=\"$GoalsPO\"></td> </tr> <tr> <td class=\"data\">PPGoalsPO</td> <td><input name=\"PPGoalsPO\" type=\"text\" id=\"GoalsPO\" size=\"6\" value=\"$PPGoalsPO\"></td> </tr> <tr> <td class=\"data\">SHGoalsPO</td> <td><input name=\"SHGoalsPO\" type=\"text\" id=\"GoalsPO\" size=\"6\" value=\"$SHGoalsPO\"></td> </tr><tr> <td class=\"data\">AssistsPO</td> <td><input name=\"AssistsPO\" type=\"text\" id=\"AssistsPO\" size=\"6\" value=\"$AssistsPO\"></td> </tr><tr> <td class=\"data\">PIMPO</td> <td><input name=\"PIMPO\" type=\"text\" id=\"PIMPO\" size=\"6\" value=\"$PIMPO\"></td> </tr><tr> <td class=\"data\">PointsPO</td> <td><input name=\"PointsPO\" type=\"text\" id=\"PointsPO\" size=\"6\" value=\"$PointsPO\"></td> </tr><tr> <td class=\"data\">Nationality</td> <td><input name=\"Nationality\" type=\"text\" id=\"Nationality\" value=\"$Nationality\"></td> </tr> <td class=\"data\"> </td> <td> </td> </tr> <tr> <td class=\"data\"> </td> <td><input type=\"submit\" name=\"Submit\" value=\"Edit\"></td> </tr> </table> </form>"); } if ($stat!=0) { $query = "UPDATE `players` SET `Nationality` = '$Nationality', `GamesPO` = '$GamesPO' , `AssistsPO` = '$AssistsPO' , `GoalsPO` = '$GoalsPO' , `PPGoalsPO` = '$PPGoalsPO' , `SHGoalsPO` = '$SHGoalsPO' , `PointsPO` = '$PointsPO' , `PIMPO` = '$PIMPO' , `PIM` = '$PIM' , `PointsCup` = '$PointsCup' , `PIMCup` = '$PIMCup' , `AssistsCup` = '$AssistsCup' , `GoalsCup` = '$GoalsCup' , `PPGoalsCup` = '$PPGoalsCup' , `SHGoalsCup` = '$SHGoalsCup' , `GamesCup` = '$GamesCup' , `Points` = '$Points', `Assists` = '$Assists' , `Goals` = '$Goals' , `PPGoals` = '$PPGoals' , `SHGoals` = '$SHGoals' , `TeamID` = '$TeamID' , `Player` = '$Player' , `Games` = '$Games' WHERE `PlayerID` = '$PlayerID'"; $result = mysql_query($query) or die ("Can't Update"); echo ("The player has been updated.<br><br><a href=\"playerstats.php\"> Go back to the player List</a>"); } else { $query = "UPDATE `snl_players` SET `PIM` = '$PIM' , `GamesPO` = '$GamesPO' , `AssistsPO` = '$AssistsPO' , `GoalsPO` = '$GoalsPO' , `PPGoalsPO` = '$PPGoalsPO' , `SHGoalsPO` = '$SHGoalsPO' , `PointsPO` = '$PointsPO' , `PIMPO` = '$PIMPO' , `PointsCup` = '$PointsCup' , `PIMCup` = '$PIMCup' , `AssistsCup` = '$AssistsCup' , `GoalsCup` = '$GoalsCup' , `PPGoalsCup` = '$PPGoalsCup' , `SHGoalsCup` = '$SHGoalsCup' , `GamesCup` = '$GamesCup' , `Points` = '$Points', `Assists` = '$Assists' , `Goals` = '$Goals' , `PPGoals` = '$PPGoals' , `SHGoals` = '$SHGoals' , `TeamID` = '$TeamID' , `Player` = '$Player' , `Games` = '$Games' WHERE `PlayerID` = '$PlayerID'"; $result = mysql_query($query) or die ("Can't Update"); echo ("The player has been updated.<br><br><a href=\"playerstats.php\"> Go back to the player List</a>"); } } elseif ($act==teamlist) { $query112 = "SELECT * FROM `teams` WHERE `TeamID` = '$TeamID'"; $result112 = mysql_query($query112) or die ('Error: Sh2'); $rows2 = mysql_fetch_array($result112); $TeamName = $rows2['TeamName']; $Logo = $rows2['Logo']; if ($Logo!="") { echo("<img src=\"../Images/$Logo\" /><br><br>"); } else { } echo ("<strong>Edit $TeamName Players</strong><br><br>Click Player Names to edit details<br><br>"); $query11 = "SELECT * FROM `players` WHERE `TeamID` = '$TeamID'"; $result11 = mysql_query($query11) or die ('Error: Sh2'); while ( $rows = mysql_fetch_array($result11) ) { $Player = $rows['Player']; $PlayerID = $rows['PlayerID']; $TeamID = $rows['TeamID']; echo ("<span class=\"style1\"><a href=\"playerstats.php?act=edit&PlayerID=$PlayerID&stat=1\">$Player</a><br>"); } } else { echo ("Click Team Names to view players<br><br>"); $query11 = "SELECT distinct TeamID FROM `players` ORDER BY `TeamID`"; $result11 = mysql_query($query11) or die ('Error: Sh2'); while ( $rows = mysql_fetch_array($result11) ) { $TeamID = $rows['TeamID']; $query112 = "SELECT * FROM `teams` WHERE `TeamID` = '$TeamID'"; $result112 = mysql_query($query112) or die ('Error: Sh2'); $rows2 = mysql_fetch_array($result112); $TeamName = $rows2['TeamName']; echo ("<span class=\"style1\"><a href=\"playerstats.php?act=teamlist&TeamID=$TeamID&stat=1\">$TeamName</a><br>"); } echo ("<a name=\"snl\"></a><br><strong><a href=\"snlplayerstats.php\">SNL Teams</a></strong><br><br>"); } ?> I am trying to make a rating system and this script is not working. Code: [Select] $ratingget = $_REQUEST['star2']; mysql_select_db($database_news, $news); $query_ratingsys = "UPDATE news SET votes = votes +1 AND rating = rating +'$ratingget' WHERE id = '$id'"; $ratingsys = mysql_query($query_ratingsys, $news) or die(mysql_error()); I'm not shore what to do this update code isn't updating my database this is just the update code for my login Code: [Select] mysql_query("UPDATE users SET session_id='$session' WHERE email='$email' AND password='$pas'") or die(mysql_error()); //Add session ID to DB mysql_query("UPDATE users SET login_ip='$ip' WHERE email='$email' AND password='$pas'") or die(mysql_error()); //Add login IP to DBand this is all of it Code: [Select] <title>Log In</title><?php require('database.php'); //Include DB connection information if (isset($_POST['login'])) { //Execute the following if form is submitted $ip = mysql_real_escape_string($_SERVER["REMOTE_ADDR"]); //Geet user's IP Address $email = mysql_real_escape_string($_POST['email']); //Post email from form $password = mysql_real_escape_string(sha1(md5($_POST['pass']))); //Post password from form and encrypt if (empty($email) || empty($password)) { //Check for empty fields die("<b>Error:</b> All fields are required to be filled in."); } $check = mysql_query("SELECT * FROM users WHERE email = '$email'") or die(mysql_error()); $check2 = mysql_num_rows($check); if ($check2 == 0) { //Check if account exists die("<b>Error:</b> Email and password do not match the database."); } $row = mysql_fetch_array($check); $db_password = $row['password']+$row['key']; if ($password != $db_password) { //Check if password is correct die("<b>Error:</b> Email and password do not match the database."); } $allowed = $row['u']; if ($allowed != 1) { //Check if they have permission die("<b>Error:</b> You do not have permission to view this section."); } function randomstring($length = 10) { $validCharacters = "abcdefghijklmnopqrstuxyvwz1234567890"; $validCharNumber = strlen($validCharacters); $result = ""; for ($i = 0; $i < $length; $i++) { $index = mt_rand(0, $validCharNumber - 1); $result .= $validCharacters[$index]; } return $result; } $session = randomstring(); $key = $row['key']; $pas = $password . $key; mysql_query("UPDATE users SET session_id='$session' WHERE email='$email' AND password='$pas'") or die(mysql_error()); //Add session ID to DB mysql_query("UPDATE users SET login_ip='$ip' WHERE email='$email' AND password='$pas'") or die(mysql_error()); //Add login IP to DB $level = $row['accounttype']; $u = $row['u']; $fs = $row['fs']; $bc = $row['bc']; $fam = $row['fam']; $future = time() + 1209600; setcookie("uemail", $email, $future); //Set cookie containing username setcookie("sessionid", $session, $future); //Set cookie containging session ID setcookie("acounttype", $level, $future); setcookie("u", $u, $future); setcookie("fs", $fs, $future); setcookie("bc", $bc, $future); setcookie("fam", $fam, $future); ////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////// //header("Location: undefined.php"); //Redirect to members page } else { //If form is not submitted display the form echo<<<login <center> <h1>Log In To The Undefiend Section</h1> <h2>Or GO <a href="../main.php">Home</a></h2> <form method="post" action=""> Email: <input type="text" name="email"><br> Password: <input type="password" name="pass"><br> <input type="submit" name="login" value="Login"><br><br> </form></center> login; } ?> Hello, I have a form where individuals can update there personal information that is already stored in a database, i.e name, address, phone number etc. There are several fields they can update. Right now it sends an email to the owner that an individual has updated their records, and sends all the fields that are in the table. Is it possible to let the owner be notified by email which individual field was updated? Example their phone number has changed they make the update and the owner gets an e-mail with just that field update. I hope I explained myself properly. Thank you in advance. Hello, I am trying to update my database using a form. While submitting this function is called, but nothing is changed. If I replace the variables with values, the function works fine, but not with variables. Code: [Select] function updateCandidate($id, $F_Name, $L_Name, $Gender, $Bday, $PhoneNo, $Address, $City, $Country, $Nationality, $experience, $Stat) { $q = "UPDATE candidates SET F_Name = '$F_Name', L_Name='$L_Name', Gender='$Gender', Bday='$Bday', PhoneNo='$PhoneNo', Address = '$Address', City='$City', Country = '$Country', Nationality = '$Nationality', Experience_idExperience='$experience', Status= $Stat WHERE Users_UsersID = $id"; return mysql_query($q, $this->connection); I'm trying to update my database so that if someone enters an e-mail address that doesn't exist, the program updates the database with the new address. I've tested everything and $result returns the correct data every time (0 or 1) but if the address doesn't exist, nothing gets updated. I know I'm missing something, just not sure what it is... Code: [Select] { $result = mysql_query(" SELECT * FROM PlayerInfo WHERE Player_Email = '$playeremail'"); IF($result) { IF (mysql_num_rows($result) = 0) { //Insert into database: new e-mail address... } } I've also tested the insert into statement and it works, so that's not the issure. Any help appreciated. Thanks. |