I wanna check same exist database, but doesn't work the $check. What's wrong ı cannot find.
ı taking this error when post;
error 1-Members not added :(
Mysql error:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''459' at line 1
error 2- 459 memb_id already in databese, try again!
This is my code:
<?php
$row_data = array();
foreach($_POST['checkbox'] as $row=>$Name) {
$name=mysql_real_escape_string($Name);
$memb_id=mysql_real_escape_string($_POST['memb_id'][$row]);
$memb_srnm=mysql_real_escape_string($_POST['memb_srnm'][$row]);
$kur_id=mysql_real_escape_string($_POST['kur_id'][$row]);
$row_data = array("'$memb_id'", "'$memb_srnm'", "'$kur_id'");
}
if (!empty($row_data)) {
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id");
if (mysql_affected_rows() ){
echo '<h4 class="alert_error"><strong>'.ss($memb_id).'</strong> already in databese, try again! </h4>';
header('Location: index.php');
} else {
$query = 'INSERT INTO basvurular (memb_id, memb_srnm, basvur_kurid) VALUES (' .implode(',', $row_data) . ')';
}
if (mysql_query($query)){
echo '<h4 class="alert_success"> <label style="color: blue; font-size: 26px; font-weight: bold;"><img style="width: 4%" src="images/pers2.png" alt=""/>-'.mysql_affected_rows().'- </label> Succesfull :) </h4>';
header('Location: index.php');
}else{
echo '<h4 class="alert_error">Members not added :( <br> Mysql Error:'.mysql_error().'</h4>';
return false;}
}
?>
<article class="module width_3_quarter" style="padding-bottom: 10px; width: 95%">
<header>
<div style="float:right;font-size:14px;font-weight: bold; padding:10px"></div>
<h3 class="tabs_involved">POST SELECTED</h3>
</header>
<div class="tab_container">
<?php
$query = query("SELECT * FROM members INNER JOIN kurumlar ON kurumlar.kur_id = members.kur_id WHERE kurumlar.kur_id=' ".$_SESSION["kur_id"]." ' && ceza=0 ORDER BY memb_id DESC");
if (mysql_affected_rows()){
?>
<div id="tab1" class="tab_content">
<?php echo '<form action="" method="post" name="frm" onsubmit="return check">
<table class="tablesorter" cellspacing="0"> '; ?>
<thead>
<tr>
<th><a style="text-decoration: none;font-size:14px;font-weight: bold; color: blue" href="javascript:void(0);" id="link" onclick="slct()">All Select</a></th>
<th align= "left" >ID Number</th> <th></th>
<th align= "left" >USER NAME</th><label style="padding-right: 10px;padding-bottom: 10px;float:right " ><input style="color: red" type="submit" name="post" value="Selected Post"></label>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($row = row($query)){
?>
<tr>
<td><input type="checkbox" name="checkbox[]" id="checkbox[]" ></td>
<td><?php echo ss($row["membName"]);?></td><td><input name="memb_id[]" type="hidden" value="<?php echo ss($row["memb_id"]);?>"></td>
<td><?php echo ss($row["memb_srnm"]);?></td><td><input name="memb_srnm[]" type="hidden" value="<?php echo ss($row["memb_srnm"]);?>"></td>
<td><input name="kur_id[]" type="hidden" value="<?php echo ss($_SESSION["kur_id"]);?>"></td>
</tr>
<?php }?>
</tbody>
<?php echo '</table></form>'; ?>
</div>
<?php }else{ ?>
<h4 class="alert_warning">Nobody Here :(( </h4>
<?php }?>
</div>
</article>
You're missing a quote on this line:
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id'");
Also, to check whether a SELECT query returned any rows, you should use mysql_num_rows(), not mysql_affected_rows() -- the latter is only for queries that modify tables.
You should also check that the query is successful:
$check = mysql_query("SELECT * FROM basvurular WHERE memb_id='$memb_id")
or die(mysql_error());
Related
I have a page that allows for multiple record deletes using checkboxes and all works fine.
However, each record may have an image associated with it stored in a folder that would also need to be deleted but I have no idea how to achieve this even though I've searched Stackoverflow and Google.
How do I delete the record(s) from the MySQL database and the image(s) associated with it from the folder?
What I have so far is:
The code that deletes the records:
if ( isset( $_POST[ 'chk_id' ] ) ) {
$arr = $_POST[ 'chk_id' ];
foreach ( $arr as $id ) {
#mysqli_query( $KCC, "DELETE FROM pageContent WHERE contentID = " . $id );
}
$msg = "Page(s) Successfully Deleted!";
header( "Location: delete-familyservices.php?msg=$msg" );
}
The form that selects the records to delete:
<form name="deleteRecord" id="deleteRecord" method="post" action="delete-familyservices.php">
<?php if (isset($_GET['msg'])) { ?>
<p class="alert alert-success">
<?php echo $_GET['msg']; ?>
</p>
<?php } ?>
<table width="100%" class="table table-striped table-bordered table-responsive">
<tr>
<th>Page Title</th>
<th>Page Text</th>
<th>Page Image</th>
<th>Delete</th>
</tr>
<?php do { ?>
<tr>
<td width="30%" style="vertical-align: middle">
<h4 style="text-align: left">
<?php echo $row_rsContent['contentTitle']; ?>
</h4>
</td>
<td width="45%" style="vertical-align: middle">
<?php echo limit_words($row_rsContent['contentData'], 10); ?> ...</td>
<td align="center" style="vertical-align: middle">
<?php if (($row_rsContent['contentImage']) != null) { ?>
<img src="../images/<?php echo $row_rsContent['contentImage']; ?>" class="img-responsive">
<?php } else { ?> No Image
<?php } ?>
</td>
<td width="5%" align="center" style="vertical-align: middle"><input type="checkbox" name="chk_id" id="chk_id" class="checkbox" value="<?php echo $row_rsContent['contentID']; ?>">
</td>
</tr>
<?php } while ($row_rsContent = mysqli_fetch_assoc($rsContent)); ?>
</table>
<p> </p>
<div class="form-group" style="text-align: center">
<button type="submit" name="submit" id="submit" class="btn btn-success btn-lg butt">Delete Selected Page(s)</button>
<button class="btn btn-danger btn-lg butt" type="reset">Cancel Deletion(s)</button>
</div>
</form>
The final piece of code, which is a confirmation script:
<script type="text/javascript">
$( document ).ready( function () {
$( '#deleteRecord' ).submit( function ( e ) {
if ( !confirm( "Delete the Selected Page(s)?\nThis cannot be undone." ) ) {
e.preventDefault();
}
} );
} );
</script>
I've seen the unlink() function mentioned but I don't know if this is what to use or have any idea how to incorporate it into the existing code if it is.
you'll have to use the path of the image which is stored on you database like so :
unlink(' the link of the images which is fetched from db'); // correct
don't forget to check for image existence file_exists() //
Got this from another site and a bit of trial and error.
if($_POST) {
$arr = isset($_POST['chk_id']) ? $_POST['chk_id'] : false;
if (is_array($arr)) {
$filter = implode(',', $arr);
$query = "SELECT *filename* FROM *table* WHERE *uniqueField* IN ({$filter})";
$result = mysqli_query(*$con*, $query);
while ($row = mysqli_fetch_object($result)) {
$pathToImages = "*path/to/images*";
{
unlink("{$pathToImages}/{$row->contentImage}");
}
}
// DELETE CAN BE DONE IN ONE STATEMENT
$query = "DELETE FROM *table* WHERE *uniqueField* IN ({$filter})";
mysqli_query(*$con*, $query);
$msg = "Page(s) Successfully Deleted!";
header("Location: *your-page.php*?msg=$msg");
}
}
Thanks to everyone who contributed.
Hope this is of some help to others.
so I would like in my registered users page, or members page all my users on it (that's the easy part) where i'm having trouble is I would like to have 2 users side by side, and then on the next line 2 other users and so on.
Something like this:
enter image description here
i'm using php and it's to use after a php query from mysql, this is my code at the moment:
<?php
include '_database/database.php';
session_start();
$current_user = $_SESSION['user_username'];
$sql = "SELECT * FROM users order by user_id desc";
$result = mysqli_query($database,$sql) or die(mysqli_error($database));
while($rws = mysqli_fetch_array($result)){
?>
<table style="width: 200px;">
<tbody>
<tr>
<td style="width: 100px;"><img src="userfiles/avatars/<?php echo $rws['user_avatar'];?>" width="100" height="100"></td>
<td style="width: 200px;">
<?php echo $rws['user_country'];?> <?php echo $rws['user_username'];?><br>
<?php echo $rws['user_joindate'];?><br>
1<br>
2<br>
3<br>
See more
</td>
</tr>
</tbody>
</table>
<?php } ?>
Thank you !
<?php
include '_database/database.php';
session_start();
$current_user = $_SESSION['user_username'];
$sql = "SELECT * FROM users order by user_id desc";
$result = mysqli_query($database,$sql) or die(mysqli_error($database));
?>
<div class="container" style="width: 200px;">
<?php while($rw = mysqli_fetch_array($result)){ ?>
<div class="user" style="width: 100px; float: left;">
<img src="userfiles/avatars/<?php echo $rw['user_avatar'];?>" width="100" height="100">
<div class="userInfo">
<?php echo $rw['user_country'] . ' ' . $rw['user_username'];?><br>
<?php echo $rw['user_joindate'];?><br>
<!--Content--><br>
<!--Content--><br>
<!--Content--><br>
See more
</div>
</div>
<?php } ?>
</div>
i haven't tested the code.
You also can use for design HTML, CSS and JS frameworks like Bootstrap
I've created a form that is supposed to update table contents in input boxes, when the content of the input boxes are changed and submitted the database is supposed to update.
This is my first page:
<body>
<form action="qa1.php" method="post">
<ul>
<li><a class="active" href="df1.php">Disease</a></li>
<li><a href="drug.php" >Drug</a></li>
<li>Interaction</li>
Alternate Drug
</ul>
<?php
$query = "SELECT * FROM disease;";
$result = mysqli_query($dp, $query);
echo "<table border=5>
<tr>
<th>Select</th>
<th>Edit</th>
<th>Disease ID</th>
<th>Disease</th>
<th>Sub Disease</th>
<th>Associated Disease</th>
<th>Ethinicity</th>
<th>Source</th>
</tr>";
while($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td><input type='radio' name='select' value=".$row['Disease_id']."/> </td>";
echo "<td>".$row{'Disease_id'}."</td>";
echo "<td><a href='edit.php?Disease_id=".$row['Disease_id']."'>edit</a></td>";
echo "<td>".$row{'Disease'}."</td>";
echo "<td>".$row{'SubDisease'}."</td>";
echo "<td>".$row{'Associated_Disease'}."</td>";
echo "<td>".$row{'Ethinicity'}."</td>";
echo "<td>".$row{'Source'}."</td>";
echo "</tr>";}
echo "</table>";
$selectedRow=$_POST['select'];
?>
<div>
<table border="0" align="center" style="border-spacing: 40px 30px;">
<caption><strong>QualityAnalysis:</br></br></strong></caption></br></br>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="4" WIDTH="40%">
</br><div><center>
<button style="color: red">Add</button>
<input type = 'submit' value = 'Delete' name = 'submitdelete' button style="color: red"></button>
<input type = 'submit' value = 'Update' name = 'submitupdate'>
</center></div> </TABLE>
</body>
</html>
This is my editing page: edit.php
<body>
<form action="edit.php" method="post">
<ul>
<li><a class="active" href="df1.php">Disease</a></li>
<li><a href="drug.php" >Drug</a></li>
<li>Interaction</li>
Alternate Drug
</ul>
<div>
<?php
$conn = mysqli_connect('localhost','root','','tool');
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_error());
}
if(isset($_GET['Disease_id']))
{
if(isset($_POST['Update']))
{
$id=$_GET['Disease_id'];
$name=$_POST['Ethinicity'];
$query3=mysqli_query("update disease set Ethinicity='$name', where Disease_id='$id'");
if($query3)
{
header('location:qa1.php');
}
}
$query1=mysqli_query("select * from disease where Disease_id='$id'");
$query2=mysqli_fetch_array($query1);
?>
<table border="2" align="center" style="border-spacing: 40px 30px;">
<caption><strong>Edit</br></br></strong></caption></br></br>
<tr>
<td>Ethinicity<input type="text" list="Ethinicity" name="Ethinicity" value="<?php echo $row['Ethinicity'];?>"/>
<input type="hidden" name="Disease_id" value="<?php echo $row['Disease_id']; ?>"/>
<input type="submit" name="Update" value ="Update">
<?php
}
?>
</center></div></div>
</form>
But Data is not getting updated in the database. Can anyone help me with this?
Firstly, mysqli_query requires the connection parameter.
Secondly, there's a syntax error with your UPDATE query, there isn't a need for a comma.
So, it should be:
$query3=mysqli_query($conn, "update disease set Ethinicity='$name' where Disease_id='$id'");
$query1=mysqli_query($conn, "select * from disease where Disease_id='$id'");
Also, if($query3) won't check if the row is successfully inserted, use mysqli_affected_rows instead.
I have a login page which sets a _SESSION parameter of 'id' upon login. After logging in the user is redirected to the index.php page and at this point the session parameter is still set, I know this because I can print it with PHP. However, when navigating to the account.php page the parameter is lost and I am not sure why.
Most of the other questions asked on here regarding this are because of the session_start not being used but I have used this on the account.php page.
Any help in resolving this would be grateful.
The code for the account.php page is below:
<?php session_start(); ?>
<?php
$con=mysqli_connect("localhost","tkernick96","Tylerkernick1996","users");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = $_SESSSION['id'];
$query = mysqli_query($con,"SELECT * FROM users WHERE id = $id");
$row = mysqli_fetch_array($query,MYSQLI_ASSOC);
$firstname = $row ['firstname'];
$lastname = $row ['lastname'];
$email = $row ['email'];
$age = $row ['age'];
$nationality = $row ['nationality'];
$language1 = $row ['language1'];
$language2 = $row ['language2'];
$language3 = $row ['language3'];
$language4 = $row ['language4'];
$language5 = $row ['language5'];
$form = "<div id='header'>
<img src='logo.png' id='logo'>
<div id='headerdiv'>
<table id='login'>
<tr>
<td style='padding-right: 20px;'>
<h2 style='margin-top: 0px'>No account?</h2>
<h3 style='margin-top: 0px'><a href='signup.php'>Sign Up Now!</a></h3>
</td>
<td style='padding-left: 20px; border-left: 1px solid #838383'>
<h3>Login:</h3>
<form method='post' action='login.php'>
<input id='logininput' type='email' name='email' placeholder='Email'>
<br>
<input id='logininput' type='password' name='password' placeholder='Password'>
<input type='submit' name='login' value='Login'>
</form>
<p id='p1'><a href='forgotdetails.php'>Forgotten Details?</a></p>
</td>
</tr>
</table>
</div>
</div>";
$account = "<div id='header'>
<img src='logo.png' id='logo'>
<div id='headerdiv'>
<table id='accounttable'>
<tr>
<td id='account'>
<p id='p2'><a href='account.php'>My Account</a></p>
<p id='p2'><a href='account/companions.php'>My Companions</a></p>
<p id='p2'><a href='account/messages.php'>Messages(".$messages.")</a></p>
<p id='p2'><a href='logout.php'>Sign Out</a></p>
</td>
</tr>
</table>
</div>
</div>
<table id='profiletable'>
<tr>
<td id='profiletabletd1' rowspan='2'>
<img src='images/avatar.png' id='profileimage'>
</td
<td id='profiletabletd1'><p id='profilename'>".$firstname." ".$lastname.", ".$age."</p></td>
</tr>
<tr>
<td id='profiletabletd3'><p id='profileinfo'>Nationality: <b>".$nationality."</b>     Languages Spoken: <b>".$language1." ".$language2." ".$language3." ".$language4." ".$language5."</b></p></td>
</tr>
</table>
";
if ($id == "") {
$output = $form;
}
else {
$output = $account;
}
mysqli_close($con);
?>
index.php:
<?php session_start(); ?>
<?php
$con=mysqli_connect("localhost","tkernick96","Tylerkernick1996","users");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = $_SESSION['id'];
$form = "<table id='login'>
<tr>
<td style='padding-right: 20px;'>
<h2 style='margin-top: 0px'>No account?</h2>
<h3 style='margin-top: 0px'><a href='signup.php'>Sign Up Now!</a></h3>
</td>
<td style='padding-left: 20px; border-left: 1px solid #838383'>
<h3>Login:</h3>
<form method='post' action='login.php'>
<input id='logininput' type='email' name='email' placeholder='Email'>
<br>
<input id='logininput' type='password' name='password' placeholder='Password'>
<input type='submit' name='login' value='Login'>
</form>
<p id='p1'><a href='forgotdetails.php'>Forgotten Details?</a></p>
</td>
</tr>
</table>";
$account = "<table id='accounttable'>
<tr>
<td id='account'>
<p id='p2'><a href='account.php'>My Account</a></p>
<p id='p2'><a href='account/companions.php'>My Companions</a></p>
<p id='p2'><a href='account/messages.php'>Messages($messages) </a></p>
<p id='p2'><a href='logout.php'>Sign Out</a></p>
</td>
</tr>
</table>";
if ($id == "") {
$output = $form;
}
else {
$output = $account;
}
mysqli_close($con);
?>
it should be $_SESSION not $_SESSSION!
you should see a warning with the right error reporting level, e.g.
error_reporting(E_ALL);
Are you using IIS?
If it is, you should check the php.ini file (under c:\php or in c:\windows), find the session.save_path parameter, and be sure that points to a folder that exists.
Then edit the rights of that folder and give read/write permissions to the IUSR user.
If you're using Apache, you should find the user that is starting the daemon (you can find this in /etc/apache2/apache.conf), then be sure that that user have r/w permissions in the folder that php.ini session.save_path points.
Restart the IIS or Apache after that.
Hope it helps.
On a page I have 8500 Employees shown in table data in the form of <tr> and <td>.
The Name of the Employees shown with a checkbox in front of each name of employee.
When I click on checkboxes the I insert the employees data (Employee Name and Employee Id) session.
Everything is working fine but the problem is when I click on check All checkbox then all the employees checkboxes are selected then there is a button named as "View Selected". On the click of this button I want to all the selected employees. When user click on this button a new child window will be opened with selected employee data in the form table row and data.
I am doing this but using session which I have created on the click of employees checkboxes.
Everything is working on Mozilla Firefox but when I check this of Google Chrome then it is not working and I am getting the browser message KillPages or Wait. The loader image of Chrome is shown but data is not loading.
My new child window page code is this where I am reading the session and running the for-each loop to print the data in the form of table data.
<?php require_once("../../includes/global.php");
$sessionName = rq('sessionName');
$employees = $session->read($sessionName);
?>
<script type="text/javascript" src="<?php echo SITEURL_PAGE; ?
>configuration/js/attendancePolicy.js"></script>
<div style="width: 100%;">
<?php if(strpos($sessionName, 'location') !== false) {?>
<h3 style="padding-left:10px;">View <?php echo LOCATION_DISPLAY_NAME?>s</h3>
<?php } else {?>
<h3 style="padding-left:10px;">View <?php echo
us(substr(str_replace('ot_','',$sessionName), 0, -3))?></h3>
<?php }?>
<?php
$totalEmployees = $session->check($sessionName) ? (int)count($session->read($sessionName)) : 0;
?>
<form id="updateEmployeesForm" name="updateEmployeesForm" method="post" action="saveAttendancePolicy.php">
<input type="hidden" name="hidAction" value="addNewPolicy_step3" />
<input type="hidden" name="sessionName" id="sessionName" value="<?php echo $sessionName?>" />
<?php
$styleTab = '';
$style='';
if($totalEmployees > 30){
$styleTab = 'border-bottom: none;';
$style = 'overflow:auto; height: 230px !important; border-bottom: 4px solid #2C90D3;';
}
//for over time policy only
$functionSuffix = '';
if($sessionName == 'ot_locations_cb' || $sessionName == 'ot_divisions_cb' || $sessionName == 'ot_departments_cb' || $sessionName == 'ot_employees_cb') {
$functionSuffix = 'overTimePolicy';
}
$where = rq('where');
$employeeLoadPage = ($sessionName == 'ot_employees_cb')?'otpolicy_ajax':'';
if(stripos($sessionName, 'employee') > -1) {
$js = "closeClildWindow('', 'employeeDiv', 'yes','".$employeeLoadPage."');";
} else if(stripos($sessionName, 'location') > -1) {
$js = "searchPolicySpecificNew('', 'locations', 'locationDiv', {'session':'yes'},'".$functionSuffix."'); updateChildPolicyNew('".$sessionName."', 'yes','".$functionSuffix."');";
} else if(stripos($sessionName, 'division') > -1) {
$js = "searchPolicySpecificNew('', 'divisions', 'divisionDiv', {'session':'yes'},'".$functionSuffix."'); updateChildDepartmentPolicyNew('".$sessionName."', 'locations_cb', 'yes','".$functionSuffix."');";
} else if(stripos($sessionName, 'department') > -1) {
$js = "searchPolicySpecificNew('', 'departments', 'departmentDiv', {'session':'yes'},'".$functionSuffix."'); updateChildjobTitlePolicy('".$sessionName."', 'divisions_cb', 'locations_cb', '','".$functionSuffix."');";
}
if($where == 'viewEmp') {
if($sessionName == 'ot_employees_cb') {
$js="getSelectedEmployeesNew('OT');";
} else {
$js="getSelectedEmployeesNew();";
}
}
?>
<div class="totalRecord" style="float:right; width:99%;text-align:right; margin-top: 5px;">
<label>Total Record(s) :<?php echo $totalEmployees ?></label>
</div>
<div style="margin: 0 2% 0 2%; width: 96%;" class="div_row">
<table cellpadding="0" border="0" cellspacing="0" width="100%" class="bdrtable" style="border-bottom: 0px;">
<thead>
<tr>
<th align="left" scope="col" colspan="5"> <input type="checkbox" name="viewCheckAllName" id="viewCheckAllName" <?php if($totalEmployees > 0) {?> checked="checked"<?php }?> class="class_parent_pop" onClick="sessionCheckBox('class_parent_pop', '<?php echo $sessionName?>_pop', 'parent', this);" />
Check All </th>
</tr>
</thead>
</table>
</div>
<div style="margin-bottom: 2%; margin-left: 2%; margin-right: 2%; width:96%;<?php echo $style;?>" class="div_row">
<table cellpadding="0" border="0" cellspacing="0" width="100%" class="bdrtable" style="<?php echo $styleTab?>">
<?php if($totalEmployees > 0) { ?>
<tr>
<?php $i=1;
foreach($employees as $key=>$employeeArr) {
?>
<td align="left" width="33%"><?php echo $i; ?> </td>
<?php
if($i%3 == 0 && $i != $totalEmployees) {
echo '</tr><tr>';
}
$i++;
}
if($totalEmployees%3 != 0) {
for ($x=($totalEmployees%3); $x < 3; $x++) {
echo '<td align="left" width="33%"> </td>';
}
}
?>
</tr>
<?php }else{ ?>
<tr>
<td colspan="3" align="center"><?php echo "No Data Found"; ?></td>
</tr>
<?php }?>
</table>
</div>
<div class="clear"></div>
<div class="div_row" style="text-align: right; width: 96%; margin:0 2%;">
<?php if($totalEmployees > 0) {?>
<input type="button" name="updateEmp" id="updateEmp" value="Update" class="submit" onClick="sessionCheckBoxPopupUpdate('<?php echo $sessionName?>_pop', '<?php echo $sessionName?>');<?php echo $js; ?>" />
<?php } ?>
<input type="button" name="cancel" id="cancel" value="Cancel" class="submit" onClick="javascript:window.close();" />
</div>
</form>
It may not be the foreach loop that is slow, 8500 is good number of data to load, you might want to page the results.
Why don't you try the same query using phpmyadmin and see the time taken.