PHP - Cannot Write Or Update Data In The Database, Please Help!
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? 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"); ?> 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"); } ?> 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 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 Hi Everyone, Hopefully this will be a quick one. How would i write each line in a textbox as a new row in a mysql database? I cant seem to find the solution on google. Thanks Not sure where to post this question. I have a MySQL database and add records with a PHP form to the tables. I have 2 fields (char) in one table. When the fields contain the character ' it wont write the record to the table! For example...if I enter. " John's house" it wont accept the record since ' appears in John's name! How do I work around this? Thanks Is this the correct way to write binary data to a file? $string = 'this is a string'; $handle = fopen('b.dat', 'wb'); for($i=0;$i<strlen($string);$i++){ $hx = bin2hex($string{$i}); fwrite($handle, pack("H*", $hx)); } If so, how do I read it an convert it back to a string? If it is not correct, how do I do it? Just trying to create a simple form that will let you enter a message that will get written to a text file. Code for SetMessage.php: Code: [Select] <?php if($_SERVER['REQUEST_METHOD'] != 'POST') { ?> <form method="POST" action="setmessage.php" name="setmessage"> <p>Message to Display:<Input type="text" name="message" size="50"></p> <p><input type="submit" value="Submit" name="submit"></p> </form> <?php } else { //Writes the contents of the message to a file echo file_put_contents('message.txt', $_POST['message']); } ?> When submitting, I get the error "Call to undefined function: file_put_contents() on line 16" Hi everyone, Here's the part of the script I think is wrong : <?php include "util/log.php"; include "util/connect.php"; if (loggedin() == $NO) { header("Location: login.php"); exit(); } else if (isset($_GET["p"])) { $udata = explode("-", $_COOKIE["log"]); $query = "SELECT * FROM l_users WHERE user='$udata[0]'"; $usrsql = mysql_query($query) or handledberror(mysql_error()); $usrdata = mysql_fetch_array($usrsql); switch ($_GET["p"]) { case "delete": include "util/linkfunc.php"; if (isset($_GET['id'])) delete_link($_GET['id']); else delete_all(); $CONTENT = "pages/urls.php"; break; case "approve": include "util/approve.php"; $CONTENT = "pages/approve.php"; break; case "urlview": case "add": case "edit": include "pages/modify.php"; $CONTENT = "pages/edit.php"; break; case "reset": include "util/linkfunc.php"; if (isset($_GET['id'])) reset_link($_GET['id']); else reset_all(); $CONTENT = "pages/urls.php"; break; case "urls": default: $CONTENT = "pages/urls.php"; } } else { $udata = explode("-", $_COOKIE["log"]); $query = "SELECT * FROM l_users WHERE user='$udata[0]'"; $usrsql = mysql_query($query) or handledberror(mysql_error()); $usrdata = mysql_fetch_array($usrsql); $CONTENT = "pages/urls.php"; } ?> <html> <head><title>EzyLinkExpire :: Member's Area</title><head> <body bgcolor="#1D2B60" link=#CCFFFF vlink=#CCFFFF> <table align="center" cellspacing="0" width=90% bgcolor="white" bordercolordark="black" bordercolorlight="black"> <tr> <td bgcolor="#1D2B60"> <img src="images/logo.gif" border="0"></td> <td valign=top bgcolor="#1D2B60" align=right><font color="white" size="1" face="Verdana">Welcome <? print $usrdata["fname"] . " ". $usrdata["lname"]; ?>!<br>User Since: <? print date("F d Y",$usrdata["since"]); ?><br>Server Time:<? print date("r"); ?><br><a href="login.php?a=logout" color=#CCFFFF>Click Here To Logout</a><br><a href="members.php" color=#CCFFFF>Click Here To Goto the Main Page</a></font></td> </tr> <tr><td colspan=2 height=14 bgcolor="#1D2B60"></td></tr> <tr> <td width="100%" height="100%" colspan=2 bgcolor="white" bordercolordark="black" align="center" bordercolorlight="black" border=1 valign="top"> <br><? include $CONTENT; ?><br><br> </td> </tr> </table> </body> <style type="text/css"> table.t {border: thin solid #000000; background-color: #FFFFFF} td.th {border: thin solid #000000; background-color:#FFFFFF; font-style: bold 12px; text-align:center; font-size: 12px; font-weight:bold} td.t {border: thin solid #000000; background-color:#FFFFFF; font-style: bold 12px; text-align:center; font-size: 12px; font-weight:bold} td.te {border: thin solid #000000; background-color:#FFFFFF; text-align:center; } td.ac1 {border: thin solid #000000; background-color:#FFFFFF; text-align:left; } td.ac2 {border: thin solid #000000; background-color:#FFFFFF; text-align:left; } a.t {color: #3366FF} a.msg {color: #3366FF} font.msg {font-style: bold 12px; font-size: 12px; font-weight:bold} </style> <script language='javascript'> function deleteconfirm() { if (confirm("Are you sure you want to delete all links?")) document.location = "members.php?p=delete"; } function resetconfirm() { if (confirm("Are you sure you want to reset the hit count for all links?")) document.location = "members.php?p=reset"; } </script> </html> Thank you, Sylvain I am a complete newbie. I have installed xampp. I created a database and the tables but that is all. I need to create all my relationships and test my database. to do this, do I now need to write the php code to view the results in a browser or... do I do it in MySQL. If so, Can someone just point me in the direction I need to go for my next step.
Thanks
I have a table that has a cell that I've made editable:
echo "<td contenteditable='true'>" . $row['Comments'] . "</td>";Which is cool I guess, but it doesn't go anywhere from there. I'd like to make it so that upon changing, it links back to an SQL UPDATE query that I define. Is this possible through some sort of onChange function? I have a MySQL database with each record of a person who has registered for an event, I am displaying the information on a web page for a user, but he wants to be able to print out all the records in alphabetical order by last name, first name later on so he will have a hard copy of each person who has registered at the table when they arrive. How can I write each record to a Txt file that he can print out later that will be formated with the record contents along with each fields definition (Ex. Last Name - Smith, First Name - John, etc)? Hey guys i am writing a code which will get data frm the user and then write a file in my server and well sadly i am really confused with the annoying errors and warnings i am getting please help here is my code <?php //This File Gets the data from the chat setup form and then writes the chat file or edits it //Get Data from the form $cname=$_POST['cname']; $nicklen=$_POST['nicklen']; $msglen=$_POST['msglen']; $pm=$_POST['pm']; $msgh=$_POST['msgh']; $aname=$_POST['aname']; $pass=$_POST['pass']; $cheight=$_POST['cheight']; $cwidth=$_POST['cwidth']; $prcadmin=$_POST['prcadmin']; $cas=$_POST['cas']; $frznick=$_POST['frznick']; $sm=$_POST['sm']; $id=$_COOKIE["id"]; //Check if the cookie id is empty if (!isset($id)) { header( 'Location: www.techbreeze.in/mychat/chat-add.html') ; } //Check if any field is empty and redirect to setup page if empty if ((isset($cname))&&(isset($nicklen))&&(isset($msglen))&&(isset($pm))&&(isset($msgh))&&(isset($aname))&&(isset($pass))&&(isset($cheight))&&(isset($cwidth))) { if ((is_numeric ($nicklen)) && (is_numeric ($msglen))&&(is_numeric($pm))&&(is_numeric($msgh))&&(is_numeric ($cheight))&&(is_numeric ($cwidth))) { //Start writting data into the file $str1=";"; $str2 = ".php"; $str4 = "\n"; $File = $id . $str2; $fh = fopen($File, 'w') or die("can't open file"); $stringData = "<?php\n"; fwrite($fh, $stringData); $strt1= "require_once /mychat/src/phpfreechat.class.php;\n"; $stringData = $strt1; fwrite($fh, $stringData); $strt1='$params["serverid"] ='; $stringData = $strt1 . $id . $str1 . $str4; fwrite($fh, $stringData); fclose($fh); $strt3 = "$params"; $stringData = $strt3; fwrite($fh, $stringData); fclose($fh); } else { echo "Only numeric Inputs allowed for the fields"; echo "<br><br><br>"; echo "Enter the maximum length of nick"; echo "<br>"; echo "Maximum Lenth of message"; echo "<br>"; echo "Max number of Simultaneous PM"; echo "<br>"; echo "No. of msg to be stored in history"; echo "<br>"; echo "Height of the Chat Room"; echo "<br>"; echo "Width of Chat Room"; echo "<br><br><br>"; echo "Please Fill them up Carefully!"; echo "<meta HTTP-EQUIV='REFRESH' content='6; url= http://www.techbreeze.in/chat-setup.html'>"; } } else { echo "You Have one or more incomplete Field"; echo "<br>"; echo "Please Fill them up Carefully!"; echo "<meta HTTP-EQUIV='REFRESH' content='2; url= http://www.techbreeze.in/chat-setup.html'>"; } ?> ok now the error i am getting is Quote Warning: fclose(): 3 is not a valid stream resource in /home/techbr/domains/techbreeze.in/public_html/mychat/chatcreate.php on line 52 Any ideas as to what i should do and why i am getting this error. 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, 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> <? } ?> 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? 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. 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>"); } ?> 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); |