PHP - How To Make Sync Update B/t Public And Admin Pages In Php
Hi, I want to create a simple online buying site. I have an admin site with login where admin can add items to the database table, and change other fields such as price and description of product and I want to make a public html page to display the updates made in my admin page. I appreciate it if someone give me some suggestions on how to get started. My admin php scripts is working fine (so SQL queries for UPDATE, DELETE, INSERT) but I don't know how to 'sync' it with the an nice html table of products the user can checkbox off to purchase on the public website. Let me know, thanks.
Similar TutorialsHi i created a website where you cam view ip webcams via php. I want to make it so people can make the camera private and public. I made two fields in mysql called "Username" and "Puborprivate" I tried to make the "Puborprivate" have two numbers "0" would be private and "1" would be public. How could I do this? My site is cwuforum.com/live/ <? for ($i = 1; $i <= $first_day_of_month-1; $i++) { $days_so_far = $days_so_far + 1; $count_boxes = $count_boxes + 1; echo "<td width=\"125\" height=\"100\" class=\"beforedayboxes\"></td>\n"; } for ($i = 1; $i <= $days_in_month; $i++) { $days_so_far = $days_so_far + 1; $count_boxes = $count_boxes + 1; IF($_GET['month'] == $todays_month+1){ IF($todays_date == $day){ $class = "publicholidayhighlightedboxes"; } ELSE { $class = "dayboxes"; } } ELSE { IF($i == $todays_date){ $class = "highlighteddayboxes"; } ELSE { $class = "dayboxes"; } } The problem is I can only display one highlighted box in one month. For example, in November, there are two public holidays, but only 1 public holiday box is highlighted. Would appreciate if someone can help me out asap. Thank you This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=316783.0 Hello everyone: I wanted to see how I can make a simple login page (user name and password) that redirects to a page(s) if the login is correct. Also, I wanted to put protection on the page(s) that will send the user back to the login page if the credentials are nor correct. I would imagine the username/password would be stored in a database table (Admins), and the correct login info would be stored in a session ..? I am use to doing this with ASP, but never PHP. I want to make sure I understand how to do this properly and securely so I can use this as a model for other systems. In ASP I would do a protected page like this: a_login_check.asp Code: [Select] <% if session("admin_user_name") = "" then session.abandon response.redirect "login.asp" end if %> Protected-Page.asp Code: [Select] <!-- #include file="include/a_check_login.asp" --> <html> ... CONTENT ... </html> And of course there is the login page itself ... (I thought it would be nice to add a "Forgot Password" link on the login page, but if that is too complicated I can do that later .. or is it easy ??) Anyway, can someone point-out to me how to do this. I would appreciate it! The table is: next next_id id 0 2 1 1 3 2 0 4 3 0 1 4 The form: <?php include 'dbc.php'; page_protect(); if(!checkAdmin()) { header("Location: login.php"); exit(); } if($_POST['doSubmit'] == 'Create') { list($next_id) = mysql_fetch_row(mysql_query("select next_id from users where id='$id'")); mysql_query("update users set approved='1' where id='$id'"); mysql_query("update users set next='1' where id='$next_id'"); mysql_query("update users set next='0' where id='$id'"); list($to_email) = mysql_fetch_row(mysql_query("select user_email from users where id='$id'")); $ret = $_SERVER['PHP_SELF'] . '?'.$_POST['query_str']; header("Location: $ret"); exit(); $message = "Hello \n "; @mail($to_email, "Aaaaack", $message, "From: \"Lobo\" <auto-reply@$host>\r\n" . "X-Mailer: PHP/" . phpversion()); } ?> Code: [Select] <html> <body> <table width="80%" border="0" cellpadding="5" cellspacing="2" class="myaccount"> <tr> <td>i<form name="form1" method="post" action="form.php"> <input name="doSubmit" type="submit" id="doSubmit" value="Create"> </p> </form> </td> </tr> </table> </body></html> I am sorry if this is posted in the wrong place! Here to learn. Thank you for any clues! Login.php Code: [Select] <?php session_start(); mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $username = $_POST['username']; $password = $_POST['pass']; if (isset($_POST["submit"])) { $log = "SELECT * FROM regis WHERE username = '$username'"; $login = mysql_query($log); $row = mysql_fetch_array($login); $number = mysql_num_rows($login); if ($number > 0) { $_SESSION['username'] = $row['username']; $_SESSION['userlevel'] = $row['userlevel']; if($_SESSION['userlevel']==1) { $_SESSION['is_logged_in'] == 1; header("Location: form2.php"); } else if($_SESSION['userlevel']== 0) { $_SESSION['is_logged_in'] == 1; header("Location: registration.php"); } } Registration.php Code: [Select] <?php echo 'Welcome:' .$_SESSION['is_logged_in'];?> form2.php Code: [Select] <?php session_start(); if (empty($_SESSION['is_logged_in'])) { header("Location:chatframe.php"); die(); // just to make sure no scripts execute } ?> <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $message=$_POST['message']; $a=$_SESSION['username']; if(isset($_POST['submit'])) //if submit button push has been detected { if(strlen($message)>1) { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { print "You IP is banned from posting."; } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$a','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } ?> <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <form name="smile" method="post" action="form2.php" onSubmit="return a()" > Your message:<br><textarea name='message' cols='40' rows='2'></textarea><br> <img src="smile.gif" alt=":)" onClick="addsmiley(':)')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt=":)" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <input type='submit' name='submit' value='Send' class='biasa' ></form> <br> <br> </body> </html> In this registration.php when im called back its appear nothing im means the number is not showing and the login code even im had also put the "$_SESSION['is_logged_in'] == 1;" outside if else userlevel statement and then i put $d= $_SESSION['is_logged_in'] == 1; and im echoing back but it is nothing im thinks something wrong in session is login and also still it cannot redirect to admin -form2.php when session is login in is 1 Okay so my news script is set to view only 10 pieces of news. But I want it so that it starts a new page once I have more than 10 pieces of news. Code: [Select] <?php require("functions.php"); include("dbconnect.php"); session_start(); head1(); body1(); new_temp(); sotw(); navbar(); $start = 0; $display = 10; $query = "SELECT * FROM news ORDER BY id DESC LIMIT $start, $display"; $result = mysql_query( $query ); if ($result) { while( $row = @mysql_fetch_array( $result, MYSQL_ASSOC ) ) { news_box( $row['news'], $row['title'], $row['user'], $row['date'], $row['id'] ); } mysql_free_result($result); } else { news_box( 'Could not retrieve news entries!', 'Error', 'Error', 'Error'); } footer(); mysql_close($link); ?> I tried a few things but they failed....miserably. Hey i want to make category pages with php. so i have embeded youtube videos on my website and i want to make a category so that every embeded link that is named under that category goes on the new web page i am making. so lets say i have a category in my table that is called "Call of duty black ops" would the code be something like this ? ( and yes i want it to be ordered by date aswell ) Code: [Select] $query = "SELECT * FROM `G4V_Videos`.`Category`.`Call of duty black ops` ORDER BY `Date added` DESC LIMIT 24"; $result = mysql_query($query); thanks guys! When login in (in login.php), the script is assigning user information to scalar variables like so: $user_name = $assoc['user_name']; $user_id = $assoc['user_id']; Now I'd like to make use of those variables on other pages like this for example: echo "Posted by " . $user_name; I want that to be visible for everybody, even if the user logs out. Any ideas? How can I call a public function inside of another public function? The get_primary_edge() says it's undefined, but it's just another public function in the class so shouldn't this work? Code: [Select] public function get_dynamic_edge($uid) { $uid = (int)$uid; $sql = "( SELECT `users`.`id` FROM partners INNER JOIN `users` ON `partners`.`user_id` = `users`.`id` WHERE partners.friend_id = '${uid}' AND `approved` = 1 ) UNION ALL ( SELECT `users`.`id` FROM `partners` INNER JOIN `users` ON `partners`.`friend_id` = `users`.`id` WHERE `partners`.`user_id` = '${uid}' AND `approved` = 1 )"; $result = mysql_query($sql) or die(mysql_error()); $i = 0; while (($row = mysql_fetch_assoc($result)) !== false) { $dynamic[$i] = array( 'uid' => $row['id'], 'score' => get_primary_edge($row['id']), ); $i++; } print_array($dynamic); } I am using a WordPress theme that uses some of its own functions besides WP functions. Let me make clear from the start that when I say "Multiple Checkboxes" in the paragraphs below I am NOT talking about checkboxes that each hold a single value. I am talking about one Checkbox field that allows multiple values to be selected and puts those values into an array with one Name value and stores the output in a string in a single mysql table field. Right up front, what I need during the Edit Ad functions is the inbuilt function that will Delete the previous Array of values in any multiple checkbox when the ad is updated. Right now updating the ad works for every situation except NO values selected or for Unchecking all previously selected values in a Multiple Checkbox. If I have, for example, 4 checkboxes selected and unselect all of them before submitting the edited ad it will return the last saved array of values but not an Empty array with no checkboxes selected. This theme has a Form Builder with a Custom fields builder used by the admin to create forms for a classified ads website. According to which category of ad the Ad creation procedure will show different forms, with different fields. I had to manually create the capability to generate multiple checkboxes...so that the different multiple checkboxes when selected and updated to the mysql table might hold a variety of values in a comma-delimited array. That works fine. When the Ad is edited on its own page, (outside of the Wordpress admin dashboard) the problem is that if a user would uncheck all checkboxes in a particular multiple checkbox then the unselected state does not overwrite the previous array of values. What returns after editing is the previous selected values. I have tried jquery functions but none of them are working the way I had hoped. so one type of checkbox might have a hypothetical value like this "name="cp_checkbox_help[]" and if three options are selected then on submit the value could be--- name="cp_checkbox_help[Sunday,Monday,Tuesday]" I use implode and explode to store the array as comma separated and retrieve the array for editing or display. I guess I need to create a Null or empty value as a default that only changes when selections are made. But, since I use implode and explode to make the array "pretty" I don't know if simply specifying nothing will erase a whole array on update. Here is some of the code used to see how I get what I get-- This displays the checkboxes that I create and name and fill with different values-- case 'checkbox': ?> <?php $options = explode(',', $result->field_values); echo '<div id="checkboxes"><table width="100%" border="0" cellspacing="0" cellpadding="5"> <tr> <th colspan="2" scope="col">' . $result->field_label. '</th> </tr>'; $myvals= explode(',', $post_meta_val); foreach ($options as $option) { { ?> <tr> <td width="4%"><input style="display:inline-block; float:left;" type="<?php echo $result->field_type; ?>" name="<?php echo $result->field_name; ?>[]" class="checkbox<?php if($result->field_req) echo ' required'?>" id="<?php echo $field_label; ?>" value="<?php echo $option; ?>" <?php foreach ($myvals as $myval) { if (in_array($myval, array($option), true)) {echo 'checked="yes"';}}?>/></td> <td width="96%"style="vertical-align:top; text-indent: 7px; text-align: left;" ><?php echo $option . '</td> </tr> ' ?> <?php } } echo ' </tr> </table></div><div class="clr"></div>'; break; Following is the main part of the code that updates the Ad form-- // update the ad and return the ad id $post_id = wp_update_post($update_ad); if($post_id) { // now update all the custom fields foreach($_POST as $meta_key => $meta_value) { if (cp_str_starts_with($meta_key, 'cp_')) if (cp_str_starts_with($meta_key, 'cp_checkbox_charley')) $meta_value= implode(',', $_POST['cp_checkbox_charley']); if (cp_str_starts_with($meta_key, 'cp_checkbox_help')) $meta_value = implode(',', $_POST['cp_checkbox_help']); if (cp_str_starts_with($meta_key, 'cp_checkbox_hello')) $meta_value= implode(',', $_POST['cp_checkbox_hello']); //echo $meta_key . ' <--metakey <br/>' . $meta_value . ' <--metavalue<br/><br/>'; // for debugging update_post_meta($post_id, $meta_key, $meta_value); } $errmsg = '<div class="box-yellow"><b>' . __('Your ad has been successfully updated.','cp') . '</b> <a href="' . CP_DASHBOARD_URL . '">' . __('Return to my dashboard','cp') . '</a></div>'; } else { // the ad wasn't updated so throw an error $errmsg = '<div class="box-red"><b>' . __('There was an error trying to update your ad.','cp') . '</b></div>'; } return $errmsg; } Back on the Edit Ad page this is the Submit <p class="submit center"> <input type="button" class="btn_orange" onclick="window.location.href='<?php echo CP_DASHBOARD_URL ?>'" value="<?php _e('Cancel', 'cp')?>" /> <input type="submit" class="btn_orange" value="<?php _e('Update Ad »','cp') ?>" name="submit" /> I have a feeling what I need is just a couple of lines to detect no posted values and then... but if one checkbox array has 6 values in it and another checkbox array has only 3 values, for example, do I need to count each specific checkbox for number of values and then overwrite or will one function completely delete the previous array and its commas? I would really appreciate some expert assistance here! I am working with a site that needs some kind of calendar solution. Each user will have their own events calendar. The plan is that your events calendar could sync with google, ical, BB calendar when done. Should I build the calendar in PHP, then worry about syncing with these other apps? Or should I use come kind of 3rd party calendar to power the one I have? Or...does anyone know of any applications that help you sync calendars if I were to create one myself? I looked into google cals, but they have a limit on the amount of calendars per day you can create. Any ideas as to how I should go about this? All answers appreciated! I'm updating my database with a set of data from another database. When there is an item deleted from the source db, how would I make sure it's deleted from the db copy given that I have to run the update in a batch and can't run it when the item is deleted? Would I truncate the db at the beginning of each update, then pull all the of data over? Commands out of sync; you can't run this command now Query: DELETE FROM case_ref WHERE user_id='3';DELETE FROM updates WHERE user_id='3' php]<?php // Check if the form has been submitted: if (isset($_POST['delete'])) { if ($_POST['sure'] == 'Yes') { // Delete the record. // Make the query: $query = "DELETE FROM case_ref WHERE user_id='$id';"; $query .= "DELETE FROM updates WHERE user_id='$id'"; $r = mysqli_multi_query ($dbc, $query); if (mysqli_affected_rows($dbc) >= 1) { // If it ran OK. echo '<h3>All cases & updates associated with user have been deleted</h3>'; } // Make the query: $q = "DELETE FROM users WHERE user_id='$id' LIMIT 1"; $r = $r = mysqli_query ($dbc, $q); if (mysqli_affected_rows($dbc) == 1) { // If it ran OK. echo '<h3>User has been deleted</h3>'; } else { // If the query did not run OK. $errors[] = '<p class="error">The user could not be deleted due to a system error.</p>'; // Public message. $errors[] = '<p>' . mysqli_error($dbc) . '<br />Query: ' . $query . '</p>'; // Debugging message. } } else { // No confirmation of deletion. $errors[] = '<p class="error">The user has NOT been deleted.</p>'; } }else{ //show the form echo '<form id="form1" name="form1" method="post" action="delete_user.php?user_id=' . $id . '"> <table width="100%" border="1" cellpadding="5" cellspacing="5"> <tr> <td width="30%">Do you wish to delete this user?</td> <td width="19%"><input type="radio" name="sure" value="Yes" /> Yes </td> <td width="17%"><input type="radio" name="sure" value="No" checked="checked" /> No</td> <td width="34%"> <input type="submit" name="button" id="button" value="Submit" /> <input name="delete" type="hidden" id="delete" value="1" /></td> </tr> </table>'; } // Print any error messages, if they exist: if (!empty($errors)) { foreach ($errors as $msg) { echo "$msg\n"; } } mysqli_close($dbc); ?>[/php] hello. I need your help please. I'm building logistics website with user panel and admin panel. I've done all login and register forms. now I want to : admin can add package with: tracking number , weight , cost , and declaration form. user can fill declaration form after admin add package to user panel. then admin can see the declared form. is it possible in php? thank you in advance Hey there I'm trying to gather a users Facebook info and use that to create a user account for them on my database. My code works perfectly for the first person who links his Facebook account with my site and adds all the user info to the database. After that with any other users it will display the logged in Facebook users name with their profile pic. The problem arises when it tries to add this person to the mysql database. It returns the error "An error has occurred and we are unable to sync your Facebook account." Before the <head> Code: [Select] <?php define('FACEBOOK_APP_ID', 'imagine_app_id_here'); define('FACEBOOK_SECRET', 'imagine_secret_here'); function get_facebook_cookie($app_id, $application_secret) { $args = array(); parse_str(trim($_COOKIE['fbs_' . $app_id], '"'), $args); ksort($args); $payload = ''; foreach ($args as $key => $value) { if ($key != 'sig') { $payload .= $key . '=' . $value; } } if (md5($payload . $application_secret) != $args['sig']) { return null; } return $args; } $cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET); ?> In the <body> Code: [Select] <?php if ($cookie) { //###cookie is set, user is logged in $user = json_decode(file_get_contents('https://graph.facebook.com/'.$cookie['uid'])); define('INCLUDE_CHECK',true); require("connect.php"); $fbookid = $user->{'id'}; $fbookname = $user->{'name'}; $query = mysql_query("SELECT * FROM tz_members WHERE facebook_id='$fbookid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ echo "<font color='#FF0000'>You are logged in through Facebook.</font>"; } else { mysql_query("INSERT INTO tz_members(facebook_id,usr,regIP,dt) VALUES( '".$fbookid."', '".$fbookname."', '".$_SERVER['REMOTE_ADDR']."', NOW() )"); $query = mysql_query("SELECT * FROM tz_members WHERE facebook_id='$fbookid'"); $numrows = mysql_num_rows($query); if ($numrows == 1){ echo "<font color='#FF0000'>Your Facebook account has been synced with our user database.</font>"; } else { echo "<font color='#FF0000'>An error has occured and we are unable to sync your Facebook account.</font>"; } mysql_close(); } echo '<img src="http://graph.facebook.com/'.$user->{'id'}.'/picture" alt="'.$user->{'name'}.'"/>'; echo $user->{'name'}; echo '<fb:login-button perms="email,user_birthday" onlogin="window.location.reload(true);" autologoutlink="true"></fb:login-button>'; } else { //###user is not logged in, display the Facebook login button echo '<fb:login-button perms="email,user_birthday" autologoutlink="true"></fb:login-button>'; } ?> Javascript: Code: [Select] <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.login', function(response) { window.location.reload(); }); </script> Any help would be greatly appreciated! We are building a site for users to post articles on certain topics and we want to show their number of followers on various social media platforms. Apart from them having the means to add it manually, there must be a method of syncing with their account, that they punch in, so that it dynamically updates our database with their number of followers. How is it done? I'm learning MVC and getting a bit confused with the accessibility of variables in classes... Code: [Select] class Load { public $load2; } Does this mean that the variable $load2 will be accessible just by all functions within the class Load? or: Does that mean that the variable $load2 will be accessible by all other classes, eg model, controller...etc inc all the functions within? I have the following static method: public static function query($query){ self::$num_queries++; return mysql_query($query)or die(mysql_error()); } I then call it like this: $oql = Mysql::query("SELECT first FROM members WHERE member_id = '{$this->owner}'"); $rql = mysql_fetch_assoc($oql); I then get the following error: Quote Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /incl/php/classes/Photo.php on line 13 Why am I getting this error? |