PHP - Your Opinion On This Situation..
On one of my pages, I have 1 form, which just a few text boxes / check boxes. Currently, I have the form submit a new record into the DB and then refreshes the entire page to show the new result.
My question is, should I display all records using JQuery or PHP. PHP refreshed the whole page, thus more queries are run per page. Does it matter much? Thanks. Similar TutorialsOn my web site I have users, each user has his/her individual profile. Currently in the profile its just information like name, user name, favorites, ect. (Information Stuff) I want to add the feature of profile image. (Pictures associated with each profile) But i want the pics to only be able to be seen associated with that person (I dont want you to be able to get the images exact url and be able to get that pic off the internet) So what is the best way to do it? Is there a way to put the pics in mySQL? XML? Other Option? What's your opinion? Started learning PHP a few weeks ago, I want to ask if anyone can give me some feedback (warnings, pointers, ...) about some code I wrote, with the objective to learn more about functions as well as MySQL. I created three functions, one to create a new table (in an existing DB), one to add a new Record and one to delete an existing record. Next I want to try to use an array as parameters for these functions. Code: [Select] <?php require 'DB.php'; // Connection string mysql_connect("localhost", "root", "") or die(mysql_error()); /* echo "Connected to MySQL<br />"; */ mysql_select_db("test") or die(mysql_error()); /* echo "Connected to Database"; */ // Create a MySQL table in the selected database function newTable($tableName) { mysql_query("CREATE TABLE IF NOT EXISTS $tableName ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), age INT)") or die(mysql_error()); } // Insert Two values in the corresponding rows in table $tableName function newRecordTwoVal ($tableName, $recordName1, $recordName2, $recordVal1, $recordVal2) { $myQuery=mysql_query("SELECT * FROM $tableName WHERE $recordName1=$recordVal1 AND $recordName2='$recordVal2';"); $doesItExist= mysql_fetch_array($myQuery); if ($doesItExist) { print ('Person already exists'); } else { mysql_query("INSERT INTO $tableName ($recordName1, $recordName2) VALUES('$recordVal1', '$recordVal2'); ") or die(mysql_error()); echo "Data Inserted!"; } } function delRecord ($tableName, $recordName1, $recordName2, $recordVal1, $recordVal2) { $myQuery=mysql_query("DELETE FROM $tableName WHERE $recordName1=$recordVal1 AND $recordName2='$recordVal2';"); } newTable('Moderators'); newRecordTwoVal ('Moderators', 'age', 'name', '40', 'Jack'); delRecord('Moderators', 'age', 'name', '40', 'Jack'); ?> This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=356626.0 Hello!
I have five websites on a single server, and each website uses the same geographic data, for instance US zip codes and city/state latitudes and longitudes. Each website uses it's own copy of these "large" tables.
I would like to avoid having to maintain the same data in 5 databases, but I am more concerned with database performance, e.g., the speed at which the data is retrieved for each website.
Question: Should I set up a new separate database that contains the shared tables for all websites and allow each website to connect to this new database for shared data? Or is it better for each website have it's own copy of the duplicate tables?
Thanks for any info!
Cheers
So I wrote a question/answer script, and I am having issues with inputting symbols. It works great it you only have letters, number, dots, commas, and likely other symbols. However query fails every time you insert certain symbols. Here is an error: Quote 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 '" ' ''' \ | / ) // ')' at line 3 My test input was following: Quote ' " ' ''' \ | / ) // I am not sure which symbol causes this, and I need help fixing this. How do I go about this without stripping any symbols? Maybe change table structure somehow? I spent several hours trying to figure this thing out. Thought I had it nailed, but still getting duplicate record entries into the MySQL DB when I do NOT want them.
Here's the plot:
People filling out the possible attendance form for a Ham Radio event *sometimes* bring a 2nd person (either a spouse or a friend). The 2nd person may, or may not, also has a Callsign which I need to put INSERT the same MySQL Callsign column. In any event, to also identify the 2nd person as coming 'with' the 1st person.
MOST of the attendees are individuals with NO 2nd person.
My entry form has these primary fields:
callsign
fullname
AND...
callsign2
fullname2
What I came up with was to process the MySQL INSERT for the primary callsign & fullname into their respective MySQL DB Columns (which works fine), and then........... immediately following the main Query INSERT, to do a substitution type thing depending on whether or not a form entry was made in the callsign2 field, AND/OR, the fullname2 field.
This partially works, but if there is ONLY a primary callsign and fullname in the form, I'm still getting a duplicate record entry which includes the callsign in the `with` column (which should ONLY take place IF there is a 2nd person indicated).
Confusing?
Here is what I have been wrestling with to try and accomplish the objective, and now my eyes are glazed over ;-(
// TRICKY PART HERE // If a 2nd Callsign AND a Fullname if ($callsign2 != ' ' && $fullname2 != ' ') { // Still make reference to the primary Callsign in the MySQL DB `with` column $with = $callsign; // Assignment to allow 2nd Callsign to be entered in the MySQL `callsign` column $callsign=$callsign2; $fullname=$fullname2; $sql="INSERT INTO `mytable` (`callsign`, `fullname`, `with`) VALUES ('$callsign', '$fullname', '$with')"; // If NO 2nd Callsign BUT a Fullname } elseif ($callsign2 = ' ' && $fullname2 != ' ') { // Make reference to the primary Callsign in the MySQL DB `with` column $with = $callsign; $callsign=$callsign2; $fullname=$fullname2; $sql="INSERT INTO `mytable` (`callsign`, `fullname`, `with`) VALUES ('$callsign', '$fullname', '$with')"; } else { // The only thing I could thing of to (hopefully) NOT make a 2nd entry // record in the MySQL DB IF there is NO 2nd person referenced $with = $callsign; } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); }This mostly works EXCEPT if only a single (primary) person entry. The recap the objetives: 1. If ONLY a primary/single person entry on the form: * callsign & fullname get INSERTed into the `callsign` and `fullname` columns in the DB as ONLY one record entry 2. If BOTH a primary and 2nd person on the form: A. IF the 2nd person has a Callsign, then the 2nd record entry would be: * callsign2 & fullname2 get INSERTed into the `callsign` & `fullname` columns in the 2nd DB as a separate record entry * callsign of the primary person also gets INSERTED into the `with` column in the same 2nd DB record entry B. IF the 2nd person does NOT have a callsign, then the 2nd record entry would be: * fullname2 gets INSERTed into the `fullname` column in the DB as a separate 2nd DB record entry * callsign of the primary person also gets INSERTED into the `with` column in the same 2nd DB record entry I obvioiusly have overlooked something, but just can't seem to figure it out at this point {SIGH}. Thanks for any enlightenment. -FreakingOUT Hello I am busy trying to setup a free to use budgeting and cashflow tool. I was recently going through my finances and whilst I found lots of spreadsheets on the subject, I didn't find a website that would allow me to store my data anonymously and access it when and where I felt fit. Bare in mind that I am a bit of a novice so go easy on me... So firstly, I've setup a page to collect 'account' information...that is, income items and expense items. I ask them to enter the amount, the frequency and when the next due date is. The DB looks like this: Code: [Select] CREATE TABLE IF NOT EXISTS `income_accounts` ( `inc_acc_ID` int(11) NOT NULL AUTO_INCREMENT, `user_ID` int(11) NOT NULL, `freq_ID` int(11) NOT NULL, `amount` decimal(7,2) NOT NULL, `next_due` date NOT NULL, `income_typeID` int(11) NOT NULL, PRIMARY KEY (`inc_acc_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=105 ; and the same for expense 'accounts': Code: [Select] CREATE TABLE IF NOT EXISTS `expense_accounts` ( `exp_acc_ID` int(11) NOT NULL AUTO_INCREMENT, `user_ID` int(11) NOT NULL, `freq_ID` int(11) NOT NULL, `amount` decimal(7,2) NOT NULL, `next_due` date NOT NULL, `ex_typeID` int(11) NOT NULL, PRIMARY KEY (`exp_acc_ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ; So once I have these entered by the user I should be able to then generate a cashflow forecast. For example, I give 5 options for the user: '4 weeks' , '8 weeks', '3 months', '6 months' '12 months'. Selecting one of these will then generate a table listing all of the items that apply for each period with a total at the bottom. Lets take '4 weeks' for an example. First I need to determine if the 'next_due' value is within the time period selected (4 weeks). If it is, what frequency is it? If it is every week then each column of the 4 column table created (i.e. 4 weeks/4 columns) will have it in it. If it is monthly frequency it will be only in the column for which it is due (i.e. column 1 would be todays date to todays date +6, column 2 = todays date + 7 to todays date +13 etc...) This will go through both the income table and the expense table and once all the items have been checked and added to the page table a further row would be added to total all the items in each column, and give a sum (i.e. sum of incomes less sum of expenses). For the '6 month' and '12 month' option, I want to display 1 month per column, rather than 1 week...just to not squeeze things up to much... I do not have a great deal of experience with arrays but my instinct tells me that they are the answer....otherwise I guess I could create a temporary DB table? I'm happy to share the code I've written so far if it helps...otherwise any advice on the best way to achieve this would be great. |