Jump to content

sasori

Members
  • Posts

    332
  • Joined

  • Last visited

Everything posted by sasori

  1. I already done that before i even posted this question here,, but the output is the same,,its the same weird combination of characters..
  2. here's the first code class SampleObject{ public $var1; private $var2; protected $var3; static $var4; public function __construct(){ $this->var1 = "Value One"; $this->var2 = "Value Two"; $this->var3 = "Value Three"; SampleObject::$var4 = "Value Four"; } } $so = new SampleObject(); $serializedso = serialize($so); file_put_contents("wordtocount.txt",$serializedso); echo $serializedso; run it then browser response is O:12:"SampleObject":3:{s:4:"var1";s:9:"Value One";s:18:"�SampleObject�var2";s:9:"Value Two";s:7:"�*�var3";s:11:"Value Three";} now here's the 2nd code include_once("class.serialization.php"); $serialize = file_get_contents("wordtocount.txt"); $unserialized = unserialize($serialize); print_r($unserializedcontent); now system response is: O:12:"SampleObject":3:{s:4:"var1";s:9:"Value One";s:18:"�SampleObject�var2";s:9:"Value Two";s:7:"�*�var3";s:11:"Value Three";} Now my question is, "Is there a way to print the output into a nice way after serialization?", I would like to see the output similar to this ( [var1] => Value One [var2:private] => Value Two [var3:protected] => Value Three ) so how am i gonna do that? to show it on a nicer way?
  3. i was able to solve the problem my self ..thanks anyway $file = "testfile.txt"; $fh = fopen("testfile.txt",'r+'); if($fh){ $data = file_get_contents($file); rewind($fh); $change = str_replace("replaceme","withthis",$data); fwrite($fh,$change); }
  4. I tried what you said 'w+'..now all the words on the test file were gone..and none was written at all
  5. hi i am having problem with writing and replacing strings to a file i have this 'testfile.txt' with the words adsfadsfasdfadsfasdfadfasddfsasori asdfadsfasdsasori asasdfasdfsasori adsfadfsasori now here's my php code $file = 'testfile.txt'; $fh = fopen($file,'r+'); $data = fread($fh,filesize($file)); $string = "sasori"; $replace = "replacement"; $change = str_replace($string,$replace,$data); fwrite($fh,$change); fclose($fh); whenever i run this on command prompt php.exe -f replace.php the data on the text file just appends the replacement..it doesn't replace the original search string adsfadsfasdfadsfasdfadfasddfsasori asdfadsfasdsasori asasdfasdfsasori adsfadfsasoriadsfadsfasdfadsfasdfadfasddfreplacement asdfadsfasdreplacement asasdfasdfreplacement adsfadfreplacement please tell me what to do in order to replace also those other strings
  6. hi, I was reviewing functions in php, and then i bumped into this array_diff_uassoc function, it doesn't give much example on the online manual. I was trying to compare the first array to 2 different arrays. on the manual it says this function can accept 1 or more arrays to compare against but then I am receiving this error Warning: Missing argument 3 for key_compare_func() in C:\xampp\htdocs\practice\test2\test2.php on line 7 and here's my code $a = array("a"=>"apple","b"=>"banana","d"=>"carrot","f"=>"fuck"); $b = array("a"=>"apple","b"=>"banana","c"=>"carrot","f"=>"fuck"); $c = array("a"=>"apple","b"=>"banana","e"=>"carrot","fuck"); function key_compare_func($a,$b,$c){ if($a === $b){ return 0; } if($a === $c){ return 0; } if(($a > $b) && ($a > $c)){ return 1; }else{ return -1; } } echo "<pre>",print_r(array_diff_uassoc($a,$b,$c,"key_compare_func")),"</pre>"; please help me out.TIA.
  7. i tried using session instead of using cookies..now its cool and working smoothly ^^,
  8. its not working...the user is logged out when clicked the log out from header,..but on the homepage the menu still shows log out...it only changes to log in if i refresh my browser
  9. hi, I created a log-in page for my practice site. and then I altered the menu, and place an if else loop to make login and logout menu to appear this snippet is my login.php code if(empty($errors)){ $query = "SELECT user_id, first_name FROM users WHERE email='$e' AND password1=SHA('$p')"; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_NUM); if($row){ setcookie('user_id',$row[0]); setcookie('first_name', $row[1]); $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if((substr($url, -1) == '/') || (substr($url, -1) == '\\')){ $url = substr($url, 0, -1); } $url .= '/loggedin.php'; header("Location: $url"); exit(); this code is for my navigation menu <h3>Menu</h3> <ul> <li class="navtop"><a href="index.php" title="Go to Home Page">Home</a></li> <li><a href="register.php" title="Register">Register</a></li> <li><a href="view_users.php" title="View The Existing Users">View Users</a></li> <li> <?php if((isset($_COOKIE['user_id'])) && (!strpos($_SERVER['PHP_SELF'],'logout.php'))){ echo '<a href="logout.php" title="Logout">Logout</a>'; }else{ echo '<a href="login.php" title="Login">Login</a>'; } ?> </li> <li><a href="password.php" title="Change Your Password">Change Password</a></li> </ul> this code is working.. when i log-in, it redirects to loggedin.php page and the menu shows "logout" button.... but when I go to homepage...the logout still exist...can you guys help me with this?..i believe i already remove the cookies on logout.php page if(!isset($_COOKIE['user_id'])){ $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if((substr($url, -1) == '/') || (substr($url, -1) == '\\')){ $url = substr($url, 0 , -1); } $url .= './index.php'; header("Location: $url"); exit(); }else{ setcookie('first_name','',time() - 3600,'/',0); setcookie('user_id','',time() - 3600,'/',0); } $page_title = 'Logged out'; require('./includes/header.html'); echo "<h1>Logged out!</h1> <p>you are now logged out {$_COOKIE['first_name']}!</p><p><br /><br /></p>"; and here's the screen shot
  10. omg..its now redirecting..thanks for the help bro...and thanks for emphasizing the "return $data"...next time ill keep my eye on that returning stuffs
  11. both doesn't return anything,.. (even if i corrected my mistake on the function escape_data($data) ,,before it was escape_data($dbc) ..but i think it doesn't have something to do with the problem)
  12. hmmmn...it doesn't return anything when I tried to log-in after i included echoing $e or $p in the script..it just squirts out the sql query itself because of the echo rigth before sql query
  13. its impossible...because sir, Im 100% sure, I tried logging in the exact email address and password from my users table (infact i only use 1 password for all dummy email accounts and the all got same password hash,.. any other solutions you might have in mind?
  14. I added those echo stuffs in the code,it didn't showed those characters, and still I am receiving the same error, even though my sql query is correct, here's the screenshot
  15. which/what should i echo on top of the header sir?
  16. nope..that's just the way it is, i guess there's no problem with my escape_data function...but with my header? i don't really know where the problem is
  17. i don't know why is my code not redirecting to "loggedin.php" , i don't see anything wrong with it, please have a look at my code,.you might see errors that is not familiar to my eyes. thanks <?php //send nothing to browser prior to setcookie function escape_data($data){ global $dbc; if(ini_get('magic_quotes_gpc')){ $data = stripslashes($data); }else{ return mysql_real_escape_string(trim($data),$dbc); } } if(isset($_POST['submitted'])){ require_once('./includes/mysql_connect.php'); $errors = array(); if(empty($_POST['email'])){ $errors[] = 'You forgot to enter your email address!'; }else{ $e = escape_data($_POST['email']); } //check password if(empty($_POST['password'])){ $errors[] = 'You forgot to enter your password'; }else{ $p = escape_data($_POST['password']); } if(empty($errors)){//if everything is ok //retrieve user_id,first_name $sql = "SELECT user_id, first_name FROM users WHERE email='$e' AND password1 =SHA('$p')"; $result = mysql_query($sql) or die (mysql_error()); $row = mysql_fetch_array($result,MYSQL_NUM) or die (mysql_error()); if($row){ setcookie('user_id',$row[0]); setcookie('first_name',$row[1]); //redirect user to loggedin.php page $url = 'http://'. $_SERVER['HTTP_HOST'] .dirname($_SERVER['PHP_SELF']); if((substr($url, -1 )== '/') || (substr($url, -1)== '\\')){ $url = substr($url,0,-1); } $url .= '/loggedin.php'; header("Location: $url"); exit(); }else{ $errors[] = 'The email address and password did not match those file'; //public message $errors[] = mysql_error() . '<br /><br />Query: '. $sql; } }//end if empty errors mysql_close(); }else{ //end of main submit conditionals $errors = NULL; } $page_title = 'Login'; require('./includes/header.html'); if(!empty($errors)){ echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred: <br />'; foreach($errors as $msg){ echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p>'; } ?> <!--create form--> <h2>Login</h2> <form action="login.php" method="post"> <p>Email address: <input type="text" name="email" size="20" maxlength="40"/></p> <p>Password: <input type="password" name="password" size="20" maxlength="20" /></p> <p><input type="submit" name="submit" value="login" /></p> <p><input type="hidden" name="submitted" value="TRUE" /></p> </form> <?php require('./includes/footer.html'); ?>
  18. haha..ok great..its now working sir. what a very nice tutorial!!!.. two thumbs up..it helped me alot.. problem solved..
  19. i forgot to add single quotes on $_GET['s'] , but it doesn't change anything..there is still error I'm sorry, what I meant to say was, did you echo $start to see what it's holding? I understand how one could have been confused by what I said before. Hi Mr. Crayon Violent, I was googling for an easier pagination tutorial.. I found yours in PHPfreaks. but I have a problem, the "<<" and "<" links aren't working, here's the link to my live practice page http://practice.uuuq.com and here's the code (it's not a full copy paste, I made sure I understand what you are talking about in the tutorial) $sql = "SELECT COUNT(*) FROM users"; $result = mysql_query($sql) or die (mysql_error()); $r = mysql_fetch_row($result); $numrows = $r[0]; //rows per page $rowsperpage = 5; $totalpages = ceil($numrows/$rowsperpage); //check if current page is set or set a default if(isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])){ $currentpage = (int)$_GET['currentpage']; }else{ $currentpage = 1; } //if current page is greater than total pages if($currentpage > $totalpages){ $currentpage = $totalpages; } //if current page is less than the total page if($currentpage < 1){ $currentpage = 1; } //set offset $offset = ($currentpage - 1) * $rowsperpage; //select datas $sql = "SELECT first_name, last_name, email, date_format(registration_date,'%M %e, %Y') as date FROM users ORDER BY first_name ASC LIMIT $offset, $rowsperpage"; $result = mysql_query($sql) or die (mysql_error()); while($row = mysql_fetch_assoc($result)){ echo $row[first_name]." : ".$row[last_name]." : ".$row[email]." : ".$row[date]."<br />"; } //set pagination links if($currentpage > 1 ){ echo "<a href='{$_SERVER['PHP_SELF']}currentpage=1'><<</a>"; $prevpage = $currentpage - 1; echo "<a href='{$_SERVER['PHP_SELF']}currentpage=$prevpage'><</a>"; } //range num links to show $range = 3; //numlinks for($x =($currentpage - $range); $x < (($currentpage + $range) + 1); $x++){ //check if valid page if($x > 0 && $x <= $totalpages){ ///check if the iteration is on the current page if($x == $currentpage){ echo "[<b>$x</b>]"; }else{ echo "<a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a>"; } } } //if not on last page if($currentpage != $totalpages){ $nextpage = $currentpage + 1; echo "<a href='{$_SERVER['PHP_SELF']}currentpage=$nextpage'>></a>"; //echo forward link to last page echo "<a href='{$_SERVER['PHP_SELF']}currentpage=$totalpages'>>></a>"; }
  20. i forgot to add single quotes on $_GET['s'] , but it doesn't change anything..there is still error
  21. you yours is wrong..the problem is here $query = "SELECT first_name, last_name, email FROM users ORDER BY registration_date ASC LIMIT $start,$display"; if i will remove the $start and $display variable, the error is gone..but the output is useless, the main purpose of the LIMIT, is for pagination
  22. help, im trying to learn pagination using native php. i think my code is correct by the browser keeps saying i have an invalid mysql resource. here's my code require('./includes/mysql_connect.php'); $display = 5; if(isset($_GET['np'])){ $num_pages = $_GET['np']; }else{ $query = "SELECT COUNT(*) FROM users ORDER BY registration_date ASC"; $result = mysql_query($query); $row = mysql_fetch_array($result, MYSQL_NUM); $num_records = $row[0]; } if($num_records > $display){ $num_pages = ceil($num_records/$display); }else{ $num_pages = 1; } if(isset($_GET[s])){ $start = $_GET[s]; }else{ $start = 0; } $query = "SELECT first_name, last_name, email FROM users ORDER BY registration_date ASC LIMIT $start,$display"; $result = mysql_query($query); $num = mysql_num_rows($result); if($num > 0); echo '<table>'; echo '<tr> <tr><td><b>First</b></td> <td><b>Last</b></td> <td><b>Email</b></td> </tr>'; while($row = mysql_fetch_array($result,MYSQL_ASSOC)){ echo '<tr>'; echo '<td>'.$row[first_name].'</td>'; echo '<td>'.$row[last_name].'</td>'; echo '<td>'.$row[email].'</td>'; echo '</tr>'; } echo '</table>'; mysql_close(); if($num_pages > 1){ $current_page = ($start/$display) + 1; if($current_page != 1){ echo '<a href="test.php?s=' .($start - $display) .'&np='. $num_pages.'">Previous</a>'; } } for($i=1; $i <= $num_pages; $i++){ if($i != $current_page){ echo '<a href="test.php?s"'. (($display * ($i - 1))) . '&np=' . $num_pages . '">' . $i. '</a>'; }else{ echo $i. ''; } } please tell me what is wrong and why does it says wrong.
  23. it worsen the situation LOL
  24. here's my database structure user_id , first_name , last_name, email, registration_date, password1, here's my code <?php $page_title = "Edit a User"; require('./includes/header.html'); if((isset($_GET['id'])) && (is_numeric($_GET['id']))){ $id = $_GET['id']; }elseif((isset($_POST['id'])) && (is_numeric($_POST['id']))){ $id = $_POST['id']; }else{ echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed in error.</p><p><br /><br /> </p>'; require('./includes/footer.html'); exit(); } require_once('./includes/mysql_connect.php'); function escape_data($data){ global $dbc; if(ini_get('magic_quotes_gpc')){ $data = stripslashes($data); }else{ return mysql_real_escape_string(trim($data),$dbc); } } if(isset($_POST['submitted'])){ $errors = array(); if(empty($_POST['first_name'])){ $errors[] = 'You forgot to enter your first name.'; }else{ $fn = escape_data($_POST['first_name']); } if(empty($_POST['last_name'])){ $errors[] = 'You forgot to enter your last name'; }else{ $ln = escape_data($_POST['last_name']); } if(empty($_POST['email'])){ $errors[] = 'You forgot to enter your email'; }else{ $e = escape_data($_POST['email']); } if(empty($errors)){ $query = "SELECT user_id FROM users WHERE email = '$e' AND user_id !='$id'"; $result = mysql_query($query); if(mysql_num_rows($result) == 0){ $query = "UPDATE users SET first_name='$fn', last_name ='$ln', email='$e' WHERE user_id = $id"; $result = mysql_query($query); if(mysql_affected_rows() == 1){ echo '<h1 id="mainhead">Edit a user</h1> <p>The user has been edited</p><p><br /><br /></p>'; }else{ echo '<h1 id="manhead">System Error</h1> <p class="error">The user could not be edited due to system error. We apologize for any inconvenience.</p>'; echo '<p>'. mysql_error(). '<br /><br />Query: '. $query . '</p>'; require('./includes/footer.html'); exit(); } }else{ //Already registered echo '<h1 id="mainhead">Error!</h1> <p class="error">The email address has already been registered.</p>'; } }else{//report errors echo '<h1 id="mainhead">Error!</h1> <p class="error">The following error(s) occurred: <br />'; foreach($errors as $msg){ echo " - $msg<br />\n"; } echo '</p><p>Please try again.</p><p><br /></p>'; }//endif report errors }// end if submit $query = "SELECT first_name, last_name, email FROM users WHERE user_id='$id'"; $result = mysql_query($query); if(mysql_num_rows($result) == 1){ $row = mysql_fetch_array($result,MYSQL_NUM); echo '<h2>Edit a User</h2> <form action="edit_user.php" method="post"> <p>First Name:<input type="text" name="first_name" size="15" maxlength="15" value="' . $row['0'] .'"/></p> <p>Last Name:<input type="text" name="last_name" size="15" maxlength="30" value="' . $row['1'] .'"/></p> <p>Email:<input type="text" name="email" size="20" maxlength="40" value="'. $row['2'] . '"/></p> <p><input type="submit" name="submit" value="Submit" /> <input type="hidden" name="submitted" value="TRUE" /> <input type="hidden" name="id" value="'. $id .'" /> </form>'; }else{ echo '<h1 id="mainhead">Page Error</h1> <p class="error">This page has been accessed error.</p><p><br ><br /></p>'; } mysql_close(); require('./includes/footer.html'); ?> the problem is once i try to edit a record through the web browser..it says the data is edited but then it doesn't insert the first name, last name and email address what should I do ?
  25. hello Sir(s), Do you know any software/tool that is capable of creating UML like diagrams for mysql database tables? please post a reply if you know any. thank you. ???
×
×
  • 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.