PHP - Php Mysql Database Schema Compare And Update
Has anyone got any script or refence to a tut where i can find a script that compares two mysql database (current) and outdated db and then takes the current db and updates the outdated one to match accordingly. Thanks
Similar Tutorials
Query About How To Retrieve A Password From The Database And Compare To The One The User Has Entered
This is a more general schema design question as opposed to specific queries.
I'm designing a database which tracks the production status of 2 (and in the future maybe 2 or so more) completely different products. So let's call these products productA and productB. I have a page where the user can see the progress of either of the products.
This concerns these 3 tables:
productA(id, order_id, status)
productB(id, order_id, status)
production_status(id, status, ordering, type)
The status is number based PER product so that it can move up a chain of statusses in its production process. So if a product is in status with ordering 10 it's done (assuming there are 10 production steps). So at ordering 1 its production just started. The status field contains at which production step it is which will be visible on the page. Now this is where i get stuck. I somehow have to differentiate between statusses so I know which statusses belong to which product. I put type in so it could filter for either productA or productB, but also for future products. But working with strings is not such a smart idea I think. I could make 2 more seperate tables, but I'm not sure how well that would scale.
So my question is what a good approach would be.
Some background info: I'm building a Joomla component for a small company. Like I said they want to track the status of these products. Every time a production person unpublishes said item on its production view inside the component, the product moves to the next status
Edited by Ortix, 13 May 2014 - 04:14 AM. Hello all, first post here so i hope i'm doing this right and am putting this into the right place. Im in the process of integrating a blog into my website, mostly it's set up however i'm currently working on the code to update the posts (theres only 2 parts a title and a comments[which is in actual fact the post content itself]). The code succsefully completes without any errors but for some reason it does not actually update the mysql database.. the code i'm using is as follows: Code: [Select] <?php require_once('header.php'); include "../blog/blogconfig.php"; if(isset($_POST['submit'])){ $update="UPDATE eq_blogarticle SET title='".$_POST['title']."',comments='".$_POST['comment']."' WHERE artid='$aid'"; if(!mysql_query($update)){ echo mysql_error(); }else{ header("location:blog.php?action=listmsgs"); exit; } } ?> <?php // get value of aid that sent from address bar by blog.php?action=listmsgs $aid=$_GET['aid']; // Retrieve data from database $sql="SELECT * FROM eq_blogarticle WHERE artid='$aid'"; $result=mysql_query($sql); $row=mysql_fetch_array($result); ?> <form name="form2" method="post" action="update.php"> <script type="text/javascript">var SITE_URL="<?php echo SITE_URL;?>";</script> <script type="text/javascript" src="<?php echo SITE_URL;?>/includes/js/nicEdit.js"></script> <script type="text/javascript"> //<![CDATA[ bkLib.onDomLoaded(function() { nicEditors.allTextAreas() }); //]]> </script> <body> <table width="100%" border="0" cellspacing="1"> <tr> <td colspan="2" class="temptitle">Equidisc Blog</td> </tr> <tr> <td width="74%" valign="top"> <table> Edit Blog Post <br> <br> Title: <br> <input name="title" type="text" class="input" id="title" value="<? echo $row['title']; ?>"> <br> <br> <span class="style1 style2 style3">Blog Post:</span> <br> <br> <textarea name="comments" cols="55" rows="12" class="input" id="comments"><? echo stripslashes($row['comments']); ?></textarea> <br> <br> <input name="aid" type="hidden" id="aid" value="<? echo $row['artid']; ?>"> <input type="submit" name="submit" value="Submit"> </form> </table> </td> <td width="26%" valign="top"><table width="100%" border="0" cellspacing="1"> <tr> <td colspan="2"><img src="../blog/images/fb.gif" width="16" height="16" /> <strong>Blog Menu</strong></td> </tr> <tr> <td><a href="blog.php">Home</a></td> </tr> <tr> <td><a href="blog.php?action=newblogpost">New Post </a></td> </tr> <tr> <td><a href="blog.php?action=listmsgs">Manage Posts </a></td> </tr> </table></td> </tr> </table> </body> <?php require_once('footer.php'); ?> Explanation: header/footer.php obvious ../blog/blogconfig.php holds my mysql connection settings and connects to the sql, this is the same config as is used for creating the new posts which i have no issues with so i dont think the issue lays there. If i run the query on phpmyadmin with dummy data it works fine and updates the entry.. Any help would be very much appreciated as i'm at the end of my tether with this!. Thanks in advance. Jo I'm having problems updating my database, I have 4 fields i want to change. I checked all the { on the page, that's not the problem, I tried to echo information from the database and it displayed my information so that's not the problem, i tried yelling at my computer, that didn't work, i tried to input data into the database with the insert function it worked but is not practical in my situation. I'm probably going to face palm when i find out whats wrong, help please btw, the $_SESSION['usr'] was set in another page and works. Code: [Select] <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Edit Info</title> <link rel="stylesheet" type="text/css" href="demo.css" media="screen" /> </head> <body> <div id="main"> <div class="container"> <font size="5" face="sans-serif">Change Settings <?php echo "{$_SESSION['usr']}"; ?></font> <form action="" method="POST"> <table cellpadding="3" cellspacinf="4" border="0"> <tr> <td>Name</td> <td><input type="text" name="name" /></td> </tr> <tr> <td>Age</td> <td><input type="text" name="age" /></td> </tr> <tr> <td>Gender</td> <td><input type="text" name="mf" /></td> </tr> <tr> <td>Location</td> <td><input type="text" name="loc" /></td> </tr> <tr> <td><input type="submit" name="submit" value="submit" /></td> </tr> </table> </form> <?php if ($_POST['submit']){ define('INCLUDE_CHECK',true); require 'connect.php'; $usr = $_SESSION['usr']; $sql = mysql_query("UPDATE members SET name='{$_POST['name']}', age='{$_POST['age']}, mf='{$_POST['mf']}', loc='{$_POST['loc']}' WHERE usr='{$_SESSION['usr']}'"); if($sql){ echo 'Changes Saved!'; }else{ echo 'Error'; } } ?> </div> </div> </body> </html> Hi everyone, I have been trying to get this code working but no matter what I try it will not work, I am trying to allow a user to update their personal details when they login to my website. I have created a form and submit button, the code is shwn below: <?php echo $_SESSION['myusername']; ?> <br><br> <form action="updated.php" method="post"> Firstname: <input type="text" name="firstname" /><br><br> Surname : <input type="text" name="surname" /><br><br> Date Birth: <input type="text" name="dob" /><br><br> Total Wins: <input type="text" name="wins" /> Total Loses: <input type="text" name="loses" /><br><br> Email Add: <input type="text" name="email" /><br><br> Country : <input type="text" name="born" /><br><br> Other Info: <input type="text" name="other" /><br><br> <input type="submit" name="Submit" value="Update" align="right"></td> </form> The updated.php file <?php mysql_connect ("localhost","root","") or die("Cannot connect to Database"); mysql_select_db ("test"); $sql=mysql_query("UPDATE memberdetails SET firstname='{$_POST['firstname']}', surname='{$_POST['surname']}', dob='{$_POST['dob']}', totalwins='{$_POST['wins']}', totalloses='{$_POST['loses']}', email='{$_POST['email']}', country='{$_POST['born']}', info='{$_POST['other']} WHERE username=$_SESSION['myusername']); if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "Details Updated"; ?> This is the error i recieve: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\website\updated.php on line 45 Line 45 is $sql=mysql_query line If anybody can help it will be very much appreciated! I have a problem . I 've been trying for a long time to make an update for php mysql to change the data. but every time I do not manage to make it work with a form. but it works if I only if I put this ($ sql = "UPDATE users SET username = 'value' WHERE id = 10 " ; ) so it only works when I put the value of the id. but I want in an html form to indicate what I want to change and what id goes. but I have tried so long that I do not feel like I so want someone help me. make the same database and same as my records and make the code and test it if it works show me please my database name : web test my table called : users my records are called : id int ( 11) AUTO_INNCREMENT username , varchar ( 255 ) password , varchar ( 255 ) first_name , varchar ( 255 ) last_name , varchar ( 255 ) email, varchar ( 255 ) Age, int ( 11) Look, my update.php is like this now <?php $servername = "localhost"; $username = "root"; $password = "....."; $dbname = "webtest"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "UPDATE users SET password='cotton candy' WHERE id=10"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } $conn->close(); ?> but now i have still have to go into the php file to change the valeu or the id but i looked on site and youtube how to put it in a simple html form but it still does not work. i want it in a html from. I want that when I enter the ID that the data of the user appears and that I can change any valeu separately. I am writing a code for a page which will get certain information from database into fields and update edited information. I can get information from database, but cannot update the edited information to database. Please, Can anyone help me ? Code: [Select] <? session_start(); include("includes/connection.php"); include("includes/config.php"); $sqlsettings = "SELECT * from admin"; $resultsettings = mysql_query($sqlsettings); $rowsettings = @mysql_fetch_array($resultsettings); if ($_SESSION['MyAccount']=='') { $_SESSION['MyAccount'] = "MyAccount"; header('LOCATION: login.php'); exit(); } $msg=''; if($_POST['continue'] == "true") { $AddedDate = $_POST['AddedDate']; $sqlUpdate = "UPDATE buyer_career SET CareerTitle='".mysql_real_escape_string($_POST['CareerTitle'])."', CareerDescription='".mysql_real_escape_string($_POST['CareerDescription'])."', ExpiryDate='".mysql_real_escape_string($_POST['ExpiryDate'])."', where BuyerCareerID=".$_POST['BuyerCareerID']; $result=mysql_query($sqlUpdate); header("Location:buyers_career.php?msg=Buying Lead has been updated successfully"); exit(); } ?> <? //retreiving data from selling leads $sqlBuyingLead="select * from buyer,buyer_career where buyer.BuyerID=buyer_career.BuyerID and BuyerCareerID=".$_GET['BuyerCareerID']; $resultBuyingLead=mysql_query($sqlBuyingLead); $buying_row=@mysql_fetch_array($resultBuyingLead); ?> <form name="PostNewCareer" method="post" action="edit_buyer_career.php" enctype="multipart/form-data" onSubmit="return validate(this);"> <input type="text" name="CareerTitle" style="width: 400px" class="basicPoint" id="CareerTitle" value="<?=$buying_row['CareerTitle']?>" /> <input type="hidden" name="AddedDate" value="<?=$buying_row['AddedDate']?>"> <input type="text" name="CareerVacancies" style="width: 400px" class="basicPoint" id="CareerVacancies" value="<?=$buying_row['CareerVacancies']?>"/> <input type="hidden" name="continue" value="true"> <input type="hidden" name="BuyerCareerID" id="BuyerCareerID" value="<?=$_GET['BuyerCareerID']?>"/> <input type="submit" value="Update Buying Lead" name="submitButton" /> Hi, Im just in the middle of creating an update script for my mysql database but don't know why it's not working. p.s. I'm a little new to PHP, but know quite a bit, it's probably something really small.. *facepalm* Here's the script: the form (update.php) <? // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $id = $_GET['id']; // Ask the database for the information from the links table $query="SELECT * FROM orders WHERE id='$id'"; $result = mysql_query("SELECT * FROM orders"); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $name=mysql_result($result,$i,"Name"); $location=mysql_result($result,$i,"Location"); $fault=mysql_result($result,$i,"Fault"); ?> <form action="updated.php" method="post"> <input type="hidden" name="ud_id" value="<? echo "$id";?>"> Name: <input type="text" name="ud_name" value="<? echo "$name"?>"><br> Location: <input type="text" name="ud_location" value="<? echo "$location"?>"><br> Fault: <input type="text" name="ud_fault" value="<? echo "$fault"?>"><br> <input type="Submit" value="Update"> </form> <? ++$i; } ?> ------------------------------------------------------ (processor) updated.php <?php // Connect to the database $link = mysql_connect('###', '###', '###'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('###', $link); $query="UPDATE orders SET Name='" . $_POST['ud_name'] . "', Location='" . $_POST['ud_location'] . "', Fault='" . $_POST['ud_fault'] . "' WHERE $id='" . $_POST['ud_id'] . "'"; echo $query; $checkresult = mysql_query($query); if ($checkresult) echo '<p>update query succeeded'; else echo '<p>update query failed'; mysql_close(); ?> ------------------------------------------------------ Every time I want to update, it comes up with: UPDATE orders SET Name='TEST', Location='TEST', fault='jbjh' WHERE ='' update query failed Any help would be appreciated. Hi. I'm trying to use UPDATE to update my datebase. When I run the code inside mysql phpadmin it works fine. But when I try and run something similiar from my php page its not updating. UPDATE user SET password='newpass', verified='0', random='asldk445435' WHERE email='email@email.com' This is the section that isn't working: // Thank you Page //generate new random number for activation process $randomcode = md5(rand(23456789,987654321)); // generate a new random password $newtemppass = createRandomPassword(); // encrypes new password $newtemppass = md5(rand(23456789,987654321)); $random = $randomcode; $verified = "0"; // Setup query to update datebase $query = "UPDATE {$usertable} SET password='$newtemppass', verified='$verified', random='$random' WHERE email='matt@flemingds.com' "; echo "<p>--------------</p>"; echo "<p>--------------</p>"; echo $newtemppass .' '.'This is your new password'; echo "<p>--------------</p>"; echo $verified .' '.'You are no longer verfied'; echo "<p>--------------</p>"; echo $random .' '.'New Random Code'; echo "<p>--------------</p>"; If you need the rest of my code. <?php //IF SUMBIT = TRUE THEN //IF USER_CODE = TRUE THEN //IF SALON NAME <> BAD CHARACTERS THEN //IF EMAIL = EMAIL IN DATEBASE THEN //CHANGE RANDOM CODE IN DATEBASE //SEND ID,SALONNAME,EMAIL,RANDOM_CODE TO EMAIL FROM DATEBASE //ELSE //EMAIL ADDRESS IS NOT IN DATABASE //STOP CODE //ELSE //SALON NAME IS INCORRECT, TRY AGAIN //STOP CODE //ELSE //PLESE RE-ENTER THE SECUIRTY CODE" CASE SENSITIVE //STOP CODE //ELSE //STOP END CODE ?> <?php // Start Session session_start(); ?> <?php $submit = $_POST['submit']; // Form Data $email = strip_tags($_POST['email']); $salonname = strip_tags($_POST['salonname']); if ($_POST[submit]) { echo "TRUE - CONTINUE_1 "; echo "<p>--------------</p>"; //echo $_SESSION[key].' - '.$_POST[user_code].'<br>'; if ($_SESSION[key]==$_POST[user_code]) { echo "TRUE - CONTINUE_2 "; echo "<p>--------------</p>"; $_SESSION[key]=''; if ($salonname) { echo "TRUE - CONTINUE_3 "; echo "<p>--------------</p>"; $email = trim($_POST['email']); if(!checkEmail($email)) { echo("Invalid email address!"); } else { // ENTER INFORMATION INTO DATEBASE include "dbConfig.php"; // table is mysql table, WHERE FIELD_NAME ='text'" OR =>='10'"; or VAR = '.$variable.') // SQL grabs records // * means "ALL RECORDS" or use FIELD_NAME, FIELD_NAME2 instead of * // $usertable = user where user is the TABLE // use WHERE FIELD_NAME = '$email' variable $SQL = "SELECT email,id,random,salonname FROM {$usertable} WHERE email = '{$email}' "; // mysql_query() is used to send a SQL query to database and returns TRUE or FALSE, or FILE HANDLE if using SELECT // $result = mysql_query($SQL); only POINTS to results $result = mysql_query($SQL) or die(mysql_query()); // mysql_fetch_assoc($result) GETS RESULTS from $result // assoc or associative array brings keys as text Array['One'] =, Array['Two']= and NOT Array[1]= // Place results into $db_field Array $db_field = mysql_fetch_assoc($result); if ($email <> $db_field['email']) { die($email .' '.'is not in database!'); } else $errorstop="go"; echo "<p>--------------</p>"; echo $db_field['id'] .' '.'This is your ID!'; echo "<p>--------------</p>"; echo $db_field['salonname'] .' '.'This is your Salon Name!'; echo "<p>--------------</p>"; echo $db_field['random'] .' '.'This is your random code'; echo "<p>--------------</p>"; echo $db_field['email'] .' '.'will be sent an Email!'; // Thank you Page //generate new random number for activation process $randomcode = md5(rand(23456789,987654321)); // generate a new random password $newtemppass = createRandomPassword(); // encrypes new password $newtemppass = md5(rand(23456789,987654321)); $random = $randomcode; $verified = "0"; // Setup query to update datebase $query = "UPDATE {$usertable} SET password='$newtemppass', verified='$verified', random='$random' WHERE email='matt@flemingds.com' "; echo "<p>--------------</p>"; echo "<p>--------------</p>"; echo $newtemppass .' '.'This is your new password'; echo "<p>--------------</p>"; echo $verified .' '.'You are no longer verfied'; echo "<p>--------------</p>"; echo $random .' '.'New Random Code'; echo "<p>--------------</p>"; } } else { // STOP CODE echo "FALSE - STOP_3 SALON NAME INVALID"; }// End salonanme check } else { echo "FALSE - STOP_2 INVALID SECUIRTY CODE"; }// End user code }// End if Sumbit else {// STOP CODE echo "FALSE - STOP_1 PLEASE FILL IN ALL FIELDS"; } ?> <?php // LINUX PLATFORM OPTION 3 // checkEmail function checks standard email format same as preg_match() // checkEmail function checks DSN records using checkdnsrr Use list() to seperate name and domain using split function // checkdnsrr ONLY WORKS on LINUX PLATFORM // Check to see if domain and username is active // uses fsockopen() to check if its in use using port 25 function checkEmail($email) { // checks proper syntax if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/" , $email)) { // gets domain name list($username,$domain)=split('@',$email); // checks for if MX records in the DNS if(!checkdnsrr($domain, 'MX')) { return false; } return true; } return false; } ?> <?php /** * The letter l (lowercase L) and the number 1 * have been removed, as they can be mistaken * for each other. */ function createRandomPassword() { $chars = "abcdefghijkmnopqrstuvwxyz023456789"; srand((double)microtime()*1000000); $i = 0; $pass = '' ; while ($i <= 7) { $num = rand() % 33; $tmp = substr($chars, $num, 1); $pass = $pass . $tmp; $i++; } return $pass; } // Usage //$password = createRandomPassword(); //echo "Your random password is: $password"; ?> Hello everyone I need code for this question
would you help me please..?
Hi there! On a page of mine, random tables get generated. The tables consist of 8 characters, so there's 5 . 10^13 possibilities. Yet ofcourse there is a possibility that 2 tables with the same name can be generated, which ofcourse is not desired. So I need an adjustment that can see whether there is already a name that's the same, and if so, make another random name. And if that one also exists, make a new one again. Untill the name doesn't exist yet and it remains. Here's the script I have right now: function createName($length) { $chars = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $i = 0; $password = ""; while ($i <= $length) { $password .= $chars{mt_rand(0,strlen($chars))}; $i++; } return $password; } $name = createName(8); mysql_select_db($database, $con); $sql = "CREATE TABLE " . $name . "( id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), devraag varchar(500), weergave varchar(500), naam varchar(500), inhoud varchar(500), tijd varchar(100))"; mysql_query($sql, $connection)or die(mysql_error()); I'm not goot with the combination of PHP and mysql, and really have no Idea how to do this. Any help? i am developing online test ,after succesful completion of the test i want to display the correct answe,in databse i have stored corect answer as radio button values(ex 1,2,3,4,) i want to display the coreect answer with a right mark,how can i achive this?could anybody help?
here is my code
<?php $testid=$_GET['testid']; include_once("header.php"); ?> <html> <head> <body> <?php include_once('connect.php'); $sqltest="select testname from test where testid='$testid'"; $sqltestresult=mysql_query($sqltest) or die(mysql_error()); while($result=mysql_fetch_array($sqltestresult)) { $testname=$result['testname']; } ?> <!--pass test name and time left --> <table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="50%" valign="middle"> <h1 style="margin-left:0;"><?php if(isset($testname)) { echo $testname ; } ?></h1> </td> <td width="50%" align="right" valign="middle"> <ul class="tabs" id="tabs"> <li id="showtime" style="font-weight:bold; color:#FF0000; bottom:5px; font-size:16px; float:right"></li> </ul> </td> </tr></table> <div class="div-tabs-container" class="div-tabs-container" style="width:79%;margin-left:3%" > <table cellpadding="0" cellspacing="0" border="0" id="questiontable" > <tr> <?php include_once('connect.php'); $sql="select * from testquestions where testid='$testid'"; $result=mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result)>0) { $data = array(); // create a variable to hold the information while (($row = mysql_fetch_array($result, MYSQL_ASSOC)) !== false) { $data[] = $row; // add the row in to the results (data) array } //shift off the first value array_shift($data[0]); $merge = call_user_func_array('array_merge', $data); $size=sizeof($merge); $newdata=array(); $num=1; $correctanswerarray=array(); $selctedanswers=array(); /* echo "<form action='fetchquestion.php' method='post' id='formsubmit' onsubmit='return out()' name='test'>"; */ foreach ($merge as $key => $value ) { $sql2="select qid, question,option1,option2,option3,option4,correct_answer from question where qid='$value' "; $result2=mysql_query($sql2) or die(mysql_error()); while($row2=mysql_fetch_assoc($result2)) { $questionid=$row2['qid']; $question=$row2['question']; $option1=$row2['option1']; $option2=$row2['option2']; $option3=$row2['option3']; $option4=$row2['option4']; $correctanswer=$row2['correct_answer']; #array to store the correct answer. $correctanswerarray[] = $questionid.$correctanswer; #$newdata[]=$row2; echo " <table class='bix-tbl-container' cellspacing='0' cellpadding='0' border='0' width='100%' id='questiontable'><tr> <td class='bix-td-qno jq-qno-2413' rowspan='2' valign='top' align='left'>$num</td> <td class='bix-td-qtxt' valign='top'><p>$question</p></td> </tr> <tr> <td class='bix-td-miscell' valign='top'><table class='bix-tbl-options' id='tblOption_2413' border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td nowrap='nowrap' class='bix-td-option bix-td-radio' width='1%' id='tdOptionNo_A_2413'> <input type='radio' class='result-option cls_2413' name='option_$questionid' value='1' id='disable'/> </td><td class='bix-td-option' width='1%'>A.</td> <td class='bix-td-option' width='48%' id='tdOptionDt_A_2413'><table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='bix-inner-td-option'>$option1</td> <td id='tdAnswerIMG_A_2413' class='jq-img-answer' valign='middle'style='display:none;padding-left:10px;'> <img src='/_files/images/website/accept.png' alt='' /> </td> </tr> </table></td></tr><tr><td nowrap='nowrap' class='bix-td-option bix-td-radio' width='1%' id='tdOptionNo_B_2413'> <input type='radio' class='result-option cls_2413' name='option_$questionid' value='2' id='disabble'/> </td><td class='bix-td-option' width='1%'>B.</td> <td class='bix-td-option' width='48%'id='tdOptionDt_B_2413'><table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='bix-inner-td-option'>$option2</td> <td id='tdAnswerIMG_B_2413' class='jq-img-answer' valign='middle' style='display:none;padding-left:10px;'> <img src='/_files/images/website/wrong.gif' alt=''/> </td> </tr> </table></td></tr><tr><td nowrap='nowrap' class='bix-td-option bix-td-radio' width='1%' id='tdOptionNo_C_2413'> <input type='radio' class='result-option cls_2413' name='option_$questionid' value='3' id='disable'/> </td><td class='bix-td-option' width='1%'>C.</td> <td class='bix-td-option' width='48%' id='tdOptionDt_C_2413'><table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='bix-inner-td-option'>$option3</td> <td id='tdAnswerIMG_C_2413' class='jq-img-answer' valign='middle' style='display:none;padding-left:10px;'> <img src='/_files/images/website/wrong.gif' alt='' /> </td> </tr> </table></td></tr><tr><td nowrap='nowrap' class='bix-td-option bix-td-radio' width='1%' id='tdOptionNo_D_2413'> <input type='radio' class='result-option cls_2413' name='option_$questionid' value='4' id='disable'/> </td><td class='bix-td-option' width='1%'>D.</td> <td class='bix-td-option' width='48%' id='tdOptionDt_D_2413'><table border='0' cellpadding='0' cellspacing='0'> <tr> <td class='bix-inner-td-option'>$option4</td> <td id='tdAnswerIMG_D_2413' class='jq-img-answer' valign='middle' style='display:none;padding-left:10px;'> <img src='/_files/images/website/wrong.gif' alt='' /> </td> </tr> </table></td></tr></table> \n <input type='hidden' name='count' value='$num' id='count'> <input type='hidden' name='queId[]' value='$questionid' id='queId'> </td> </tr> </table> "; $num++; } } echo " </tr> </table> "; #array of correct answrer #echo "array of correct answer<br/>"; #print_r($correctanswerarray); #echo "size of the coreect answer array"; $size1=sizeof($correctanswerarray); echo "<br/>"; } else { echo " no questions available for selected test"; } ?> </div> <!-- add div right side --> <div style="height:500px;width:150px;float:right;margin-top:-500px;border:1px solid #99CCFF"> </div> <div style="height:30px"> </div> <!-- add div bottom --> <div style="height:125px;border:1px solid #99CCFF"> </div> <?php include('footer.html'); ?> </body> </html> Edited by mac_gyver, 25 October 2014 - 10:05 AM. code tags around code please Hello, Sorry for my english... Well, I make a smaill website. members has to login and then member can see pictures (saved in a folder). When the admin upload pictures a folder wil be created. To get the actual folders in the "album" folder I use this code. <?php //get the folders $handle = opendir(realpath('../album/Album/.')); while ($direc = readdir($handle)) { if($direc == '.' || $direc == '..') continue; else { echo "\t\t<input type='checkbox' name='map[]' id='map[]' value='" . $direc. "' />" . $direc . "<br />\n"; } } closedir($handle); ?> The admin has to assign the folders wich are allowed to see by a member. I use checkboxes for that. And now my problem: When a member can see folder 1 to 4 and the admin upload 2 new folders and want to give that member to see these 2 new folders I want the following: 6 checkboxes (checkbox 1 > album 1, checkbox 2 > album 2... etc). As is said, this member can see folder 1 to 4, so in the CMS album 1 to 4 has to be checked ans album 5 to 6 not. This is my code for that: <?php $sql2 = "SELECT url FROM url WHERE gebruiker_id =" . $_GET['id'] . " ORDER BY url ASC"; $res2 = mysql_query($sql2); while ($rij = mysql_fetch_array($res2)) { $url = $rij['url']; // mappen ophalen $handle = opendir(realpath('../album/Album/.')); while ($direc = readdir($handle)) { if($direc == '.' || $direc == '..' || $direc == $url) { continue; } echo "\t\t<input type='checkbox' name='map[]' id='map[]' value='" . $direc. "' />" . $direc . "<br />\n"; } closedir($handle); } ?> Now my output is: <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 3' />album 3<br /> <input type='checkbox' name='map[]' id='map[]' value='album 4' />album 4<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> <input type='checkbox' name='map[]' id='map[]' value='album 1' />album 1<br /> <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 4' />album 4<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> <input type='checkbox' name='map[]' id='map[]' value='album 1' />album 1<br /> <input type='checkbox' name='map[]' id='map[]' value='album 2' />album 2<br /> <input type='checkbox' name='map[]' id='map[]' value='album 3' />album 3<br /> <input type='checkbox' name='map[]' id='map[]' value='album 5' />album 5<br /> <input type='checkbox' name='map[]' id='map[]' value='album 6' />album 6<br /> What do I have to do to check the checkboxes (album 1-4) and not to check the album 5-6??? My guess it has to do with the While in While loop but... Greetings, Ferdi 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 again everyone, I am trying to compare a php variable to the value of a row in mysql, but keep getting the following error: Code: [Select] Wrong perameter count for mysql_result() What syntax would I use to accomplish this? Here is my code: // connects to server and selects database. include ("../includes/dbconnect.inc.php"); // table name $table_name = "availability"; // split up date into 3 separate fields $date = "12/25/2010"; $date_split = explode("/", $date); $month = $date_split[0]; $day = $date_split[1]; $year = $date_split[2]; // check if earth room is already reserved $taken = "Reserved"; $sql = "SELECT earth_room FROM $table_name WHERE month='$month' AND day='$day' AND year='$year' LIMIT 1"; $result = mysql_query($sql) or trigger_error("A mysql error has occurred!"); $row = mysql_result($result); if($row == $taken){ echo "Room Already Reserved"; } else{ echo "Room Available"; } Thanks for the help, kaiman Hi, after following lots of advice and changing to MySqli I am running into a few probs. This is me just probably missing something stupid, I know what I want, but can't figure out what query I should use and where I should place it. All the queries I have tried have failed.
I just need a query that gets the $current_stored_password from the password field on the database, to confirm the last check
elseif ($current_password !== $current_stored_password) { include 'includes/overall/header.php'; echo $current_password . ' AND ' . $_POST['current_password'] . ' Password and password again do not match'; include 'includes/overall/header.php'; }Here is the whole script. <?php session_start(); error_reporting(0); //ini_set('display_errors', '1'); require( 'database.php' ); $username = $_SESSION['loggedinuser']; $current_stored_password = $_SESSION['password']; $current_password = $_POST['current_password']; $password = mysqli_real_escape_string($con, md5( $_POST['password'])); $password_again = mysqli_real_escape_string($con, md5( $_POST['password_again'])); // Run checks if (isset($_POST['current_password'], $_POST['password'], $_POST['password_again'])) { if( strlen( $_POST['current_password'] ) < 8 ) { include('includes/overall/header.php'); echo "Password Must Be 8 or More Characters."; include('includes/overall/footer.php'); } elseif( strlen( $_POST['password'] ) < 8 ) { include('includes/overall/header.php'); echo "Password Must Be 8 or More Characters."; include('includes/overall/footer.php'); } elseif ( strlen( $_POST['password_again'] ) < 8 ) { include('includes/overall/header.php'); echo "Password Must Be 8 or More Characters."; include('includes/overall/footer.php'); } elseif ($password !== $password_again) { include 'includes/overall/header.php'; echo ' Password and password again do not match'; include 'includes/overall/header.php'; } elseif ($current_password !== $current_stored_password) { include 'includes/overall/header.php'; echo $current_password . ' AND ' . $_POST['current_password'] . ' Password and password again do not match'; include 'includes/overall/header.php'; } else { // Define a query to run $query = "UPDATE `user` SET `password` = '$password' WHERE `username` = '$username'"; // Query the database $result = mysqli_query($con,$query); // Check if the query failed if( !$result ) { die('There was a problem executing the query ('.$query.'):<br>('.mysqli_errno($con).') '.mysqli_error($con)); } else { include 'includes/overall/header.php'; echo 'Password has been changed'; include 'includes/overall/footer.php'; } } } // Close the connection mysqli_close($con); ?>At the moment the message displayed when the form is submitted is echo $current_password . ' AND ' . $_POST['current_password'] . ' Password and password again do not match';How do I retrieve the password from the database to compare against the current password entered by the user? Any help is much appreciated. PS. Yes I know I have repeated code and that md5 is not secure, but I am just building onto a template I got and will be making changes to shorten the code and secure the password soon Hey, I'm new to this stuff. But I'm calling a Table with a list of products, I want people to be able to compare the products they checked. what is the best way of doing this with the code below? I put "blah" for everything except for the compare table and calls. This code seemed to work the best for the look I wanted for it. They all call the checkbox from 'Compare' in the mysql table. Thanks! $result = mysql_query("SELECT * from Compare_Tool ORDER BY Blah ASC"); //Table starting tag and header cells echo "<table border='1'><tr><th>Compare</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th><th>blah</th></tr>"; while($row = mysql_fetch_array($result)){ ?> <tr> <td align="center"><input name="checkbox[]" type="checkbox" Compare="checkbox[]" value="<? echo $row['Compare']; ?>"></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah']; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> <td ><? echo $row['blah]; ?></td> </tr> <?php } echo "</table>"; ?> Can anyone post a generic update function to update mysql table. The manual approach: update $tablename set $column1='a', $column2='b' where $id=$value; I want to perform a query which returns a subset of the fields in a table. One particular mySQL field is VARCHAR I have a query like this: $query = mysql_query("SELECT * FROM table WHERE code LIKE '3%') ; It's my understanding this should return all values which begin with "3", but it only returns about a dozen of the values 3, 30-39, 300-399, etc. (It works with string fields, but this field contains numerals.) Any help appreciated. thanks, Tom Hi All, I'm working on PHP scripts to interact with a web hosted MySQL DB for an Android Application. Simply what I am trying to do is in the PHP script is run a SELECT statement which will return the value of a column, UserType, and compare the result of this to a string, which will then execute code depending on it's value. This user type can only be either 'student' or 'lecturer'. Any help with this would be much appreciated. <?php require "init.php"; $user = $_GET["userID"]; #Selects column account type where the idNum equals $user which is passed from my app. $sql1 = "select accountType from user_info where idNum = '$user'"; $result1 = mysqli_query($con,$sql1); $row1 = mysqli_fetch_assoc($result1); #This is where I am stuck. Simply, I am trying to run the code in the loop where the result of $sql1 equals 'Student'. The else will run if it is not #student and therefore is 'Lecturer'. I'm also not sure if my code inside the IF is fully correct either as it's not running that far. if($row1['accountType'] == 'Student') { $sql2 = "select courseCode from user_info where idNum = '$user'"; $result2 = mysqli_query($con,$sql2); $row2 = mysqli_fetch_assoc($result2); $sql3 = "select * from module_details where classListCourseCode = '".$row2['courseCode']."'"; $result3 = mysqli_query($con,$sql3); $response = array(); while($row = mysqli_fetch_array($result3)) { array_push($response,array("moduleID"=>$row[0],"lecturerID"=>$row[1],"moduleName"=>$row[2],"classListCourseCode"=>$row[3])); } echo json_encode(array("server_response"=>$response)); } Thanks in advance. Hi, I need to compare records in a table based on the 'datetime' field, like if the difference between time is less than 15min. need to combine the records(rows) as a single resultant row until the time difference between them is less than 15min and when a record's time difference is >15min that should return as another row and so on. Please find following sample table and the required output format Sample Table: Code: [Select] ID NAME DATETIME 1 aaa 2011-10-10 06:30:00 2 bbb 2011-10-10 06:33:00 3 ccc 2011-10-10 06:38:00 4 ddd 2011-10-10 06:40:00 5 eee 2011-10-10 07:10:00 6 ffff 2011-10-10 07:14:00 7 sss 2011-10-10 08:16:00 8 jjj 2011-10-10 08:26:00 9 kkk 2011-10-10 08:28:00 10 mm 2011-10-10 09:46:00 11 ppp 2011-10-10 09:49:00 12 qqq 2011-10-10 09:52:00 Output Needed : Code: [Select] IDs START DATETIME END DATETIME 1,2,3,4 2011-10-10 06:30:00 2011-10-10 06:40:00 5,6 2011-10-10 07:10:00 2011-10-10 07:14:00 7,8,9 2011-10-10 08:16:00 2011-10-10 08:28:00 10,11,12 2011-10-10 09:46:00 2011-10-10 09:52:00 You can see 1st row in the output table having IDs 1,2,3,4 coz the time difference between them is less than 15minutes (it doesn't means time difference between start and end; it is actually the time difference between current record and previous one ; ie; ID-1 and ID-2 have difference less than 15min and ID-2 & ID-3 have difference less than 15min and ID-3 & ID-4 have difference less than 15min, so those 4 records combine together as a single row also shows their start time and end time. Then you can see diff between ID-4 and ID-5 is greater than 15 min so it should display as new row, and so on) How can I acheive above Output with mysql query ?? Please help.. |