Jump to content

sasa

Staff Alumni
  • Posts

    2,804
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by sasa

  1. just add - $string = preg_replace('|[^a-z0-9-]|i', '', $string);
  2. in your 1st post you have mysql_query("UPDATE users SET username = '$euser' WHERE username = '".$user['username']."'"); mysql_query("UPDATE users SET email = '$eemail' WHERE username = '".$user['username']."'"); if($erank == "member") { mysql_query("UPDATE users SET rank = '2' WHERE username = '".$user['username']."'"); } else if($erank == "moderator") { mysql_query("UPDATE users SET rank = '3' WHERE username = '".$user['username']."'"); } else if($erank == "gmod") { mysql_query("UPDATE users SET rank = '4' WHERE username = '".$user['username']."'"); } else if($erank == "admin") { mysql_query("UPDATE users SET rank = '5' WHERE username = '".$user['username']."'"); } mysql_query("UPDATE users SET avatar = '$eavatar' WHERE username = '".$user['username']."'"); mysql_query("UPDATE users SET currency = '$ecurrency' WHERE username = '".$user['username']."'"); in 1st query you change value in field username and another query can't find right row
  3. try <?php $out = array(); $dirname = "a1/"; $images = scandir($dirname); $ignore = Array(".", "..", "index.php"); foreach($images as $curimg){ if(!in_array($curimg, $ignore)) { //echo "<img src='a1/$curimg' alt='a1' />"; $out[$curimg][] = $dirname; }; } $dirname2 = "a2/"; $images = scandir($dirname2); $ignore = Array(".", "..", "index.php"); foreach($images as $curimg){ if(!in_array($curimg, $ignore)) { //echo "<img src='a2/$curimg' alt='a2' />"; $out[$curimg][] = $dirname2; }; } ksort($out); foreach ($out as $curimg => $d){ foreach ($d as $dirname){ echo "<img src='$dirname/$curimg' alt='$dirname' />"; } } ?>
  4. try $string = preg_replace("/<script[^>]*>.*?< *script[^>]*>/i", "", $string);
  5. +0 convert string to number you can use CONVERT() or CAST() function
  6. ORDER BY substring(prod_id,2)+0
  7. play with array_shift(), array_push() and array_reverse() functions
  8. CAR_checkbox.php <?php include("mysql_connect.php"); $q="SELECT * FROM `car_checkbox` WHERE `FileSerial` = '$id'"; $r=mysql_query($q); $num=mysql_numrows($r); if ($num>0) { $val1=mysql_result($r,'0','year_2006'); $val2=mysql_result($r,'0','year_2007'); } else { //Else nothing is checked $val1=0; $val2=0; } //Show form echo "<input type='hidden' name='id' value='$id'>"; echo '<input type="hidden" name="year_2006" value="0">'; if ($val1=="0") { echo "<input name='year_2006' type='checkbox' value='1'>2006"; } else { echo "<input checked='checked' input name='year_2006' type='checkbox' value='1'>2006"; } echo '<input type="hidden" name="year_2007" value="0">'; if ($val2=="0") { echo "<input name='year_2007' type='checkbox' value='1'>2007"; } else { echo "<input checked='checked' input name='year_2007' type='checkbox' value='1'>2007"; } ?> Personal Message (Offline) Checkbox not saving correctly to MYSQL table « on: 05-04-2008, 17:07:36 » Reply with quoteQuote Hi All, I have a basic Checkbox in PHP which saves to a MYSQL database. I am able to create a Checkbox which correctly populates from the MYSQL table. The issue is that when a user clicks on the save button the information is not saved back to the database correctly. Basically if you check the boxes and save the database record is set to 0 (unchecked) and the checkboxes return to an unchecked state. I suspect that the code is unable to determine if the checkbox is checked when it saves as there are no errors being returned during the update process. The Table is called car_checkbox and has the fields FileSerial (Primary Key), year_2006 and year_2007. The .php files I am using are TESTPHPCHECK.php which contains the code used for updating the Checkbox. TESTCheckbox.php which holds the form and table. CAR_Checkbox which is the code for the checkbox itself and populates the values stored in the table. If anyone has any solutions or advice it would be very much appreciated. Thanks in advance. CAR_checkbox.php Code: <?php include("mysql_connect.php"); $q="SELECT * FROM `car_checkbox` WHERE `FileSerial` = '$id'"; $r=mysql_query($q); $num=mysql_numrows($r); if ($num>0) { $val1=mysql_result($r,'0','year_2006'); $val2=mysql_result($r,'0','year_2007'); } else { //Else nothing is checked $val1=0; $val2=0; } //Show form echo "<input type='hidden' name='id' value='$id'>"; if ($val1=="0") { echo "<input name='year_2006' type='checkbox' value='year_2006'>2006"; } else { echo "<input checked='checked' input name='year_2006' type='checkbox' value='year_2006'>2006"; } if ($val2=="0") { echo "<input name='year_2007' type='checkbox' value='year_2007'>2007"; } else { echo "<input checked='checked' input name='year_2007' type='checkbox' value='year_2007'>2007"; } ?> TESTCheckbox.php I believe the code at the start of TESTCheckbox.php may have something to do with the issue but I have not been able to work it out. Code: <?php include ('./populate.php'); ?> <?php $id=$_GET['id']; $val1=$_GET['year_2006']; if ($val1=="on") { $val1=1; } else { $val1=0; } $val2=$_GET['year_2007']; if ($val2=="on") { $val2=1; } else { $val2=0; } ?> <table width='1044' align="left" cellpadding="0" cellspacing="0" > <form action="TESTPHPCHECK.php?id=$id" method="POST" name='theForm' onsubmit=''> <input type="hidden" name="id" value="<?php echo $id; ?>"> <!--DWLayoutTable--> <td height="117" colspan="17" valign="top"><INPUT name="image" TYPE="image" class='forminput' value="Save" SRC="Buttons/NavBanner.gif" /> <h3><?php echo $row->current_name; ?></h3></td> <td width="11"> </td> <tr> <td height="13"></td> <td></td> <td colspan="5" rowspan="2" valign="top" class="edit">CAR Recd. </td> <td rowspan="2" align="center" valign="top"><?php include ('CAR_checkbox.php'); ?></td> <td></td> <td></td> <td></td> <td></td> </tr> </form> </table> TESTPHPCHECK.php <?php include("mysql_connect.php"); $val1 = $_POST['year_2006']; $val2 = $_POST['year_2007']; $id = $_POST['id']; $query17 = mysql_query("UPDATE car_checkbox SET year_2006='$val1' WHERE FileSerial='$id'") or die(mysql_error()); $query18 = mysql_query("UPDATE car_checkbox SET year_2007='$val2' WHERE FileSerial='$id'") or die(mysql_error()); ## The above statements run the whole query ## tyr adding some error checking if(!$query17){ echo "There is an error with query 17 <br>"; } else { echo "Query 17 was successful<br>"; } if(!$query18){ echo "There is an error with query 18 <br>"; } else { echo "Query 18 was successful<br>"; } #for more error checking you can try checking your posted variables with print_r($_POST); mysql_close($link); ?>
  9. try <?php $data = array( array('id' => 1, 'order_no' => 20, 'name' => 'bxxx'), array('id' => 2, 'order_no' => 'NULL', 'name' => 'bbbbbbb'), array('id' => 3, 'order_no' => 'NULL', 'name' => 'cccc') ); foreach ($data[0] as $k => $v) $max_len[$k] = strlen($k); foreach ($data as $d){ foreach ($d as $k => $v){ if ($max_len[$k] < strlen("$v")) $max_len[$k] = strlen("$v"); } } $table = ''; foreach ($max_len as $i) $table .= '+-'.str_repeat('-', $i); $table .= "+\n"; foreach ($max_len as $n => $i) $table .= '| '.str_pad($n, $i, ' ',0); $table .= "|\n"; foreach ($max_len as $i) $table .= '+-'.str_repeat('-', $i); $table .= "+\n"; foreach ($data as $d){ foreach ($d as $k => $v){ $table .= '| '. str_pad($v, $max_len[$k], ' ', 0); } $table .= "|\n"; } foreach ($max_len as $i) $table .= '+-'.str_repeat('-', $i); $table .= "+\n"; echo $table; ?>
  10. try <?php $query = sprintf("INSERT INTO trades SET anchr='%s', url='%s', domain='%s', username='%s', password='%s', status='pending'", anti_inject($_POST['anchr']), anti_inject($_POST['url']), anti_inject($_POST['domain']), anti_inject($_POST['username']), anti_inject($_POST['password'])); mysql_query($query) or die(sql_failure_handler($query, mysql_error())); ?>
  11. change to # expects the csv file to be in the same dir as this script $skip_first_n_lines = 6; for($i=$skip_first_n_lines; $i<sizeof($fcontents); $i++) { etc.
  12. try <?php $lines = file('filename'); $key = rand(2, count($lines) - 3); echo $lines[$key]; ?>
  13. try <?php $id = $_POST['id']; if($id != ""){ if($db = mysql_connect("localhost", "xxx","jxxx")){ if(mysql_select_db("xxxxxx",$db)){ $acc1 = "select * from newitems where ID='".$id."'"; $query = mysql_query($acc1); $query = mysql_fetch_array($query); // add thi line } echo $id; echo $acc1; echo'<div style="background-image:url(tmp/backgroundrepeat.gif); background-repeat:repeat; padding-bottom:4px; padding-top:4px; padding-left:4px; padding-right:4px; border:solid #FFFFFF thin; margin-right:15px;"><strong>Selected Article - '. $query["newstitle"] .' </strong> </div>'; echo"<font class=\"smaller low\">Data of Article-".$id." ".$query["dateadded"]."</font><br>"; echo $result["newsinformation"]; ?>
  14. RewriteEngine on RewriteRule ^/index.php$ /big_shoes/large_trousers/big_jeans/big_shoes-large_trousers-big_jeans.html
  15. in function show_form change part print '<br />'; print "Article Title"; print "<br />\n"; input_text('title', $_POST); print "<br /><br />\n"; print 'Article Body'; print "<br />\n"; input_textarea('body', $_POST); print "<br /><br /><br />\n"; to print '<br />'; print "Article Title"; print "<br />\n"; input_text('title', $default); print "<br /><br />\n"; print 'Article Body'; print "<br />\n"; input_textarea('body', $default); print "<br /><br /><br />\n";
  16. $query = "SELECT...."; $result = mysql_query($query) or die(mysql_error()); while( $row = mysql_fetch_array($result) ) { $num[] = $row['columnname']; } $numbers = implode(',', $num);
  17. in line while ($result <= $num_of_posts) you compre object with number. How coud be work
  18. TRY function get_posts($table_name,$num_of_posts) { $query = "SELECT * from $table_name LIMIT $num_of_posts"; $result = mysql_query($query); if (!$result) { die(mysql_error()); } echo ('<div id = "blog">'); while ($row = mysql_fetch_row($result)) { //$row = mysql_fetch_row($result); echo ('<div id = "blog_title">'); echo ($row[1] . "<br />"); echo ('<div id = "blog_date">'); echo ($row[2] . "<br />"); echo ('<div id = "blog_tags">'); echo ($row[3] . "<br />"); echo ('<div id = "blog_post">'); echo ($row[4] . "<br />"); } echo ("</div>"); }
  19. SELCT blah FROM table WHERE id IN(1,5,37,95)
  20. change 1st part of your script to <?php require('config.php'); date_default_timezone_set('America/New_York'); mysql_connect("$path", "$username", "$password") or die(mysql_error()); mysql_select_db("$database") or die(mysql_error()); if ( isset($_POST['selected']) && is_array($_POST['selected']) ) {// name in your chkbox is selected! not del or select // foreach ( $_POST['del'] as $id ) { // $sql = "DELETE FROM `recentwanted` WHERE `id` = '$id' LIMIT 1"; // mysql_query($sql) or die(mysql_error()); // } //} $selected = implode(",", $_POST['selected']); // <-- change this line too if($selected == ''){ echo "Nothing selected!"; }else{ mysql_query("DELETE FROM recentwanted WHERE id in ($selected)"); echo "Deleted records!"; } } ?>
  21. ok change lines header ("location: member.php"); echo "<p> </p><p> </p><center><font color=#FFFF00><font size=36><font weight=bold>Welcome $Username to our members area.</font></font></font></center>"; to echo "<p> </p><p> </p><center><font color=#FFFF00><font size=36><font weight=bold>Welcome $Username to our members area.</font></font></font></center>"; include ("member.php");
  22. change header ("location: member.php"); to header('Refresh: 5; url=http://www.yoursite.com/member.php');
  23. in root of your serwer create page update.html and in .htaccess file put RewriteEngine on RewriteRule !(update.html$) /update.html this all request redirect to update.html
  24. is it true We provide all users free customer support. As much of it as you need. With real people, right here in Pennsylvania. By phone. By email. By live text chat. from http://www.aweber.com/
  25. 1. http://www.php.net/manual/en/function.pow.php 2. http://www.php.net/manual/en/language.operators.bitwise.php 3. http://www.php.net/manual/en/function.file-get-contents.php
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.