PHP - Add Multiple To Table
Ok, i have gots the code for posting one member at a time, I was wondering if it would be possible to make it so that you can just click a button or link and make that show another textbox that can be used to insert another member?
My code is: Code: [Select] <?php if ($_POST['post']) { $name = $_POST['name']; if ($name) { mysql_connect("localhost","slay2day_User","slay2day") or die(mysql_error()); mysql_select_db("slay2day_database") or die(mysql_error()); $insert = mysql_query("INSERT INTO members VALUES ('','$name')") or die (mysql_error()); die ("Member has been added successfully"); } else echo "Please fill out all fields"; } ?> <form action='addmember.php' method='POST'> Name: <input type='text' name='name'> <br /> <input type = 'submit' name='post' value='Add Members'> </form> Thanks in advance Similar TutorialsHi guys I need your help, I am trying already for days to sort it out but does not work. My file "pback.php" displays the mysql table "sp_users". I want to add the columns "school_name" and "school_address" from another table "sp_schools" (same database) at the right end of the displayed table in "pback.php" (after the column update) I tried with leftjoin but it does not work. Please help me. I am getting really frustrated. Thank you... Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxxx"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY user_id"; $result=mysql_query($sql); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000000; } .style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #000000; } --> </style> <title>User overview</title><table width="486" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#996600"> <tr> <td width="427"> <div align="left"> <table width="486" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><div align="center" class="style1 style3"><strong>SchoolPorta.com Users </strong></div></td> </tr> <tr> <td width="26" align="center"><span class="style2">id</span></td> <td width="70" align="center"><span class="style2">Name</span></td> <td width="114" align="center"><span class="style2">Lastname</span></td> <td width="146" align="center"><span class="style2">Email</span></td> <td width="88" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style10"><? echo $rows['user_id']; ?></span></td> <td><span class="style10"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style10"><? echo $rows['user_surname']; ?></span></td> <td><span class="style10"><a href="mailto:<?php echo $rows['user_login']; ?>"><?php echo $rows['user_login']; ?></a></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style10">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="left"> <p> </p> <p> </p> <p> </p> <p> <?php mysql_close(); ?> </p> </div> Hello
We have a database table that confirms the installations started and completed for our game... and I am looking to confirm how many installs start but never complete...
So, this is my current query...
SELECT description, ip from error_log where description like '%install%' order by ip; Hi Everyone, I have a code that stores an ID to a cookie named "cookieuser" and inserts it to a table named "cookieuser" wheneven someone new to my site visited. When someone revisits, it should only access the cookie in the computer and retrieve data in the table based on the cookie. The problem is, the code inserts multiple rows with different IDs (which is autoincremented). The codes works for returning visitors which only reads the cookie ID value. I noticed that the error reacts differently with different browsers: When in localhost, mozilla works as expected, ie inserts 4 rows, and chrome inserts 2 rows. In live server, mozilla creates 4 rows as well. The code I used is shown below. Hope someone knows the problem. Thank you in advance. Code: [Select] if (isset($_COOKIE['cookieuser'])) { $cookieuserx = $_COOKIE['cookieuser']; $sql = "SELECT userid FROM cookieuser WHERE userid = $cookieuserx"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ $date = date("Y-m-d H:i:s",time()); $sqlcookie = "INSERT INTO cookieuser (userid,lastgood,lastbad,lastneutral,lastvisit,hitcount,date_registered) VALUES('','$date','$date','$date','$date','1','$date')"; $rescookie = mysql_query($sqlcookie) or die(mysql_error()); $newcookieuser = mysql_insert_id(); $expire=time()+60*60*24*360; setcookie("cookieuser", $newcookieuser, $expire,"/"); $cookieuser = $newcookieuser; }else{ $cookieuser = $_COOKIE['cookieuser']; } }else{ $date = date("Y-m-d H:i:s",time()); $sqlcookie = "INSERT INTO cookieuser (userid,lastgood,lastbad,lastneutral,lastvisit,hitcount,date_registered) VALUES('','$date','$date','$date','$date','1','$date')"; $rescookie = mysql_query($sqlcookie) or die(mysql_error()); $newcookieuser = mysql_insert_id(); $expire=time()+60*60*24*360; setcookie("cookieuser", $newcookieuser, $expire,"/"); $cookieuser = $newcookieuser; } Hi guys, I need your help! I have two tables "sp_users" and "sp_schools" in the same database. Now I want to add column "time" from "sp_schools" to a phpfile which displays "sp_users". The column "time" should be after column "update". I made it upto here, but to get the second query and display Please help. I am devastated... Code: [Select] <?php $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name $tbl_name="sp_users"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name ORDER BY user_id"; $result=mysql_query($sql); ?> <style type="text/css"> <!-- .style2 {font-weight: bold} .style3 { font-family: Arial, Helvetica, sans-serif; color: #000033; } .style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #003333; } --> </style> <title>User overview</title><table width="486" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td width="427"> <div align="left"> <table width="486" border="1" cellspacing="0" cellpadding="3"> <tr> <td colspan="4"><div align="center" class="style1 style3"><strong>SchoolPorta Users </strong></div></td> </tr> <tr> <td width="26" align="center"><span class="style2">id</span></td> <td width="70" align="center"><span class="style2">Name</span></td> <td width="114" align="center"><span class="style2">Lastname</span></td> <td width="146" align="center"><span class="style2">Email</span></td> <td width="88" align="center"><span class="style2">Update</span></td> </tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td><span class="style8"><? echo $rows['user_id']; ?></span></td> <td><span class="style8"><? echo $rows['user_first_name']; ?></span></td> <td><span class="style8"><? echo $rows['user_surname']; ?></span></td> <td><span class="style8"><? echo $rows['user_login']; ?></span></td> <td align="center"><a href="update.php?id=<? echo $rows['user_id']; ?>" class="style8">update</a></td> </tr> <?php } ?> </table> </div></td> </tr> </table> <div align="center"> <?php mysql_close(); ?> </div> Hi I'm using this code to insert multiple records. The code executes but nothing is entered into my database. This usually happens when there's a mismatch in data types.
How do I ensure that description goes in as text which in sql is wrapped in single quotes, but also make sure the other variables go in as numeric.
// an array items to insert $array = array( 'theid' => $theid, 'descr' => $descr, 'costperunit' => $costperunit, 'quantity' => $quantity, 'costperlot' => $costperlot ); // begin the sql statement $sql1 = "INSERT INTO descriptions (jobid, description, costperunit, quantity, costperlot) VALUES "; $it = new ArrayIterator( $array ); // a new caching iterator gives us access to hasNext() $cit = new CachingIterator( $it ); // loop over the array foreach ( $cit as $value ) { // add to query $sql1 .= "('".$cit->key()."','" .$cit->current()."')"; if( $cit->hasNext() ) { $sql1 .= ","; } } Hi, I'm a little bit new to php and i'm having a small problem. Let me explain with the script : Code: [Select] <?php //connect to mysql $data = mysql_query("SELECT * FROM forum_topic WHERE topic_id='$topic'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) $dete = mysql_query("SELECT * FROM forum_topic WHERE login='$info['username']'") or die(mysql_error()); while($info2 = mysql_fetch_array( $dete )) { echo "......"; } ?> So I have the first SELECT command that will get the data from table forum_topic and array the data and after that I have a second SELECT that will get the data from table_members but this time time the WHERE clause equals to some data "arrayed" in the first SELECT command...And the end I need to output the data from both tables.... Here's the error I get : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/m/a/z/mazemontana/html/login/forum_viewtopic.php on line 73 ...I know that my syntax is probably not good but can't figure out how to do it..... Any help will be greatly appreciated! Thanx Hi, I'm very new to these forums and php alike. I've been working on this bit of code for weeks now. I've written numerous versions and made endless revisions; trying pieces from many similiar source and well, it's still not quite working out for me. The form I've been trying to finish will have multiple rows. The user will input values specific to each row, but I'm trying to make it so that each row is synonymous with each other in regard to the database table. Like an order form, an inventory form, or a roster. I'd really like to make this code work out because I can think of numerous applications for it's use. I'm sure others could use it for even more. So, as you see; the html code represents the table that contains the form. Currently, I only have five of these rows in the form, but would like for anybody using the code to be able to add in code for as many rows in the table as needed. Code: [Select] <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <FORM action="post_multiple.php" method="POST"> <table width="80%" border="1"> <tr> <td>Vendor</td> <td>Item Description</td> <td>Quantity</td> <td>Price</td> </tr> <tr> <td><select name="vendor" id="vendor" > <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> <tr> <td><select name="vendor" id="vendor"> <option value="other1">other1</option> <option value="other2">other1</option> <option value="other3">other3</option> <option value="other4">other4</option> <option value="other5">other5</option> </select></td> <td><input name="description" type="text" id="description" size="50" /></td> <td><input name="quantity" type="text" id="quantity" size="50" /></td> <td><input name="price" type="text" id="price" size="50" /></td> </tr> </table> <input type="submit" name="Submit" value="Submit" /> </FORM> </body> </html> In the php script I've tried using the count, loop, if, several others functions to try to get it to insert all the completed rows from the form into the table but just can't seem to get it to work out. Anyways, here's a representation of what i'd like to achieve. Not necessarily the code I've written trying to accomplish this, I'd have to upload a book if that were the case. <?php ini_set('display_errors','On'); error_reporting(E_ALL); $host="localhost"; // Host name $username="root"; // Mysql username $password="password"; // Mysql password $db_name="testing"; // Database name $tbl_name="test_multiple"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); //declarations $vendor = $_POST['vendor']; $description = $_POST['description']; $quantity = $_POST['quantity']; $price = $_POST['price']; // Check if button name "Submit" is active, do this $sql1="INSERT INTO $tbl_name (vendor, description, quantity, price) VALUES ('".$vendor."', '".$description."', '".$quantity."', '".$price."')"; $result1=mysql_query($sql1); mysql_close(); ?> If anybody can suggest where I need to go with that, that would be great. Like I said above, I've tried about everything I could find any reason to from forum threads I had found in google searches and whatnot. Also, if there is a good article, link or tutorial that would address this that anybody knows about that would be great. However, I'm not looking for a link to a product or plugin that will do this stuff for me. I'm trying to get halfway decent at php and would like to have working code for myself to build upon, modify, and learn from. Any help is greatly appreciated!!!! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=305991.0 <?php if(isset($_POST['ActivityId'])) { require_once('database.php'); $Search=$_POST['Search']; $query="select * from registration where Flag='A' AND Activity like '%,$Search,%'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)) { echo "<table border='2'><tr><td> Name--".$row['Name']."</td> <td>Contact Number--".$row['ContactNumber']."</td> <td>Email--".$row['Email']."</td> <td>Address--".$row['Address']."</td></tr></table>"; } } elseif(isset($_POST['EventId'])){ require_once('database.php'); $Search=$_POST['Search']; $query="select * from participation where EventId ='$Search'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)){ $LoginId= $row['LoginId']; echo $LoginId;} $query="select * from registration where LoginId='$LoginId'"; $result=mysqli_query($dbc,$query) or die('Not Connected to Reg'); while($row=mysqli_fetch_array($result)){ echo "<table border='2'><tr><td> Name--".$row['Name']."</td> <td>Contact Number--".$row['ContactNumber']."</td> <td>Email--".$row['Email']."</td> <td>Address--".$row['Address']."</td></tr></table>"; }} elseif(isset($_POST['Location'])) { require_once('database.php'); $Search=$_POST['Search']; $query="select * from registration where Flag='A' AND Address like '%$Search%'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)) { echo "<table border='2'><tr><td> Name--".$row['Name']."</td> <td>Contact Number--".$row['ContactNumber']."</td> <td>Email--".$row['Email']."</td> <td>Address--".$row['Address']."</td></tr></table>"; } } elseif(isset($_POST['BloodGroup'])) { require_once('database.php'); $Search=$_POST['Search']; $query="select * from registration where Flag='A' AND BloodGroup ='$Search'"; $result=mysqli_query($dbc,$query) or die('Not Connected'); while($row=mysqli_fetch_array($result)) { echo "<table border='2'><tr><td> Name--".$row['Name']."</td> <td>Contact Number--".$row['ContactNumber']."</td> <td>Email--".$row['Email']."</td> <td>Address--".$row['Address']."</td></tr></table>"; } } ?> <html><body><form action='<?php echo $_SERVER['PHP_SELF']?>' method="post"> <input type="text" name="Search"><br> <input type="submit" name="ActivityId" value="Submit Activity Id"><br> <input type="submit" name="EventId" value="Submit Event Id"><br> <input type="submit" name="Location" value="Submit Location"><br> <input type="submit" name="BloodGroup" value="Submit Blood Group"><br> </form> </body></html> Hi frds............. I have two tables named "registration" and "participation". Registration table have some columns like "LoginId", "email","contact no.", "Name" etc.and participation table have 2 column named "LoginId" and "EventId". Now if user enters EventId, I want to display the details like email,contact no. etc. I have a code but it not works properly....... If result have more than one row it only displays the email and contact no. of last one instead of all. Plzzzzzzzzz help anyone................... ????????/ Apologies... I'm a noob trying to reverse engineer code. I have a script that can retrieve values from a MySQL database (based on a session login that recognizes which user you are) and places those values into the text fields of a form, pre-populating the form. Code: [Select] <?php mysql_connect('localhost', 'db', 'password'); mysql_select_db('users'); $id = mysql_real_escape_string($_SESSION['userid']); $select = "SELECT * FROM user_info WHERE md5(Member_No) = '$id';"; $query = mysql_query($select); if ($row = mysql_fetch_array($query)) { ?> <form> FIRST name: <input type="text" name="First" value="<?php echo stripslashes($row['First']); ?>" LAST name: <input type="text" name="Last" value="<?php echo stripslashes($row['Last']); ?>" > Birthday: <input type="text" name="Birthday" value="<?php echo stripslashes($row['Birthday']); ?>" <input type="submit" value="Submit"> </form> <?php } ?> I want to be able to connect to that same database and update ALL the values (3 in the example above) with the single click of the form button. I think I was told some time ago that it's not possible to update all the values at once? Thanks, ~Wayne I have displayed check box values(ugroup field) from ugroups table.now what i want to do is,when user select multiple check boxes and submit it should be insert into relavent feild in table.now it's insert check boxes values.but not in relevant field.this is my code.Please help me.
//select ugroup's from group table. <?php $result = "SELECT id,ugroup FROM group"; $res_result = db::getInstance()->query($result); ?> <form action="db_sql/db_add_page.php" method="get"> Tittle :<input type="text" size="100" name="tittle" /> Description :<textarea cols="80" id="editor1" name="description" rows="10"></textarea> //Display ugroups in textboxes and checkboxes <?php while( $line=$res_result->fetch(PDO::FETCH_ASSOC)) { echo '<input type="checkbox" name="group[]" value=" '. $line['ugroup'] .'" />'; echo'<input type="text" name="ugroup" disabled="disabled" value=" '. $line['ugroup'] .'" size="7" "/>'; echo ' '; } ?><input type="submit" value="Submit"> </form>db_add_page.php if(isset($_POST)) { $tittle = $_POST['tittle']; $description = $_POST['description']; $ugroup = $_POST['group']; $acc_status = "INSERT INTO add_services (id,tittle,description,g1,g2,g3,g4,g5,g6,g7,g8) VALUES(NULL,'".$tittle."','".$description."','".$ugroup[0]."','".$ugroup[1]."','".$ugroup[2]."',' ".$ugroup[3]."','".$ugroup[4]."','".$ugroup[5]."','".$ugroup[6]."','".$ugroup[7]."')"; $rate = db::getInstance()->exec($acc_status); if(!$rate){ echo '<script type="text/javascript">alert("Update Error !");</script>'; }else{ header('Location:../add_page.php'); echo '<script type="text/javascript">alert("Successfuly Updated User Group !");</script>'; } }Attached Files group.jpg 22.14KB 0 downloads add_services.jpg 21.36KB 0 downloads what's wrong with this ? i can't upload Hi, I have a DB with two tables, customers and orders. One customer may have many orders, What I want to do is do a select on the two tables and get the customer info once, and then all the orders associated with the account. I saw how to do this once before using a join and then having to use a PHP foreach to break it up. I am just not sure of how to put the two together to make it work, or maybe there is an easier way completely. Any help is appreciated. Thanks B Example: Bob Smith Shoes Coat Boots Gloves Sally Jones Hat Purse Boots Umbrella Hi There, I have an SQL query that returns 10 rows, which I want to echo over 2 columns and 5 rows, however, I want rows 1-5 on the left hand column and rows 6-10 on the right hand side. Is there an easy way to do this? Normally I would do a fetch_array but, that would place the rows in order of, left, right, left, right - if that makes sense? Table is a standard table with 2 columns and 5 rows. Thanks Matt Yes, I am going to be one of those guys today. I have never done XML anything, besides past 2-3 hours or so, and I am getting frustrated. I have learned how to create simple XML files and save them. I am however having hard time figuring out how to create and XML file when trying to access an table from databse. I am looking to export from "registered_users" table all "registrations" and include "first_name", "last_name" and "age"
Sample:
<registered_users>
<registration>
<first_name>Bob</first_name>
<last_name>Smith</last_name>
<age>36</age>
</registration>
<registration>
<first_name>Jack</first_name>
<last_name>Miller</last_name>
<age>45</age>
</registration>
</registered_users>
It would be nice if the file would be saved as spearate "all_users.xml"
Any help would be appreciated
In my form I have this: Code: [Select] <div class="confSub {conferences.confClass}"> <div> <input type="hidden" name="confPK" value="{conferences.confPK}"> <label>Conference Attended:</label><input size="85" name="conference[{conferences.confCounter}]" type="text" value="{conferences.conference}"/> <label>Date:</label><input size="20" name="confDate[{conferences.confCounter}]" type="text" value="{conferences.confDate}"/> <span class="example left"> ( YYYY-MM-DD )</span> <label class="fullLabel clearfix">Description and Benefit to the University:</label> <textarea name="confDesc[{conferences.confCounter}]" cols="90" rows="5">{conferences.confDesc}</textarea> <input class="checkbox clearfix" name="confPres[{conferences.confCounter}]" value="yes" type="checkbox" {conferences.checkedConf}/> <label class="midLabel">Conference Presentation?</label> <label class="clearfix">Title of Presentation:</label> <input class="pushLeft" size="85" name="confPresTitle[{conferences.confCounter}]" type="text" value="{conferences.ConfPresTitle}"/> </div> </div> I need to take the values of the same index for eachof five arrays ($_POST['conference'], $_POST['confDate'], $_POST['confDesc'], etc...) and insert/update them into a mysql table. So conference[0], confDate[0], confDesc[0], confPres[0], and confPresTitle[0] all need to go into the same index of their respective fields in the DB table. If it was one array I could just do something like: foreach($_POST['conference'] as $conference) { // Update Conference $degreeQuery = "UPDATE CONFERENCES SET Conference = '".$conference."', StaffPK1 = '".$getPK1."' WHERE ConferencePK1 ='".$confID."'"; $degreeQuery = mysql_query($degreeQuery); } I'm having trouble with how to add a value from each array into the sql table. I could do it through a different foreach loop for each array and iterate through all foreach loops with another loop, but that doesn't seem very efficient. I'd like to do it with one sql statement for each set of "conference" data. Thanks in advance, Shannon Ok, I need some serious help here. I have a jQuery .load method that retrieves a single users name from a database. However... I also need to incorporate error checking into the script that the .load method access, so that, if the user enters a name in the field that is not in the database, it will insert it into the database, and then then pull it back out again to be returned by the ajax call. This is the jQuery that performs the call: Code: [Select] $('#submit').click(function(e) { var user = $('#user').val(); var checkurl = "indexData.php"; $('#username').load(checkurl, 'user=' + user); e.preventDefault(); }); This is the script form indexData.php: Code: [Select] <?php $db = mysql_pconnect('localhost', 'joeme0', 'Galatians2'); if (!$db) { die('Could not connect: ' . mysql_error()); } mysql_select_db('joeme0_brave'); $name = $_POST['name']; $checkQuery = "select name from users where name='$name'"; $checkResult = mysql_query($checkQuery); if ($checkResult > 1) { $insQuery = "insert into users (id, name) values ("", '$name')"; $insResult = mysql_query($insQuery); if ($insResul 0) { $query="select name from users where name='$name'"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { echo $row['name']; } } else { echo "Cold not insert your name into the database"; } } else { $query="select name from users where name='$name'"; $result=mysql_query($query); while($row=mysql_fetch_array($result)) { echo $row['name']; } } ?> So far I can get it to pull out a name that is manually entered into the database no problem. But I can't get it to insert a name that isn't in the database, and then query the database a second time to pull that same name back out again. The page is pretty simple. The user comes to the page, enters their name in the text field, either clicks the submit button or presses the enter key. The scripts fire off the ajax call to the database, check to see if the name exists, if not enter it and pull it back out (this is where I have the problem), if so, pull it out and display it back on the page. Hi
I come from a desktop (vb.net) background and have used oridinary text files for my databases. I use file locking to prevent other processes from writing to the same file simultaneously.
Now I am moving over the PHP/MySQL - what precautions should I take to stop a simultaneous processes from writing to a table at the same time.?
Do I need to lock the table before writing to it?
Does MySQL deal with this automatically and just block my process until the table becomes free?
(I am talking about a single table here, not multiple dependant tables - I know that is another issue)
Thanks
Nigel
Well I have a script file that was originally written like this: Code: [Select] $query = "UPDATE ".$prefix."users SET nickname='".$nickname."' WHERE username='".$loggedinname."'"; mysql_query($query); $query = "UPDATE ".$prefix."users SET gender='".$gender."' WHERE username='".$loggedinname."'"; mysql_query($query); $query = "UPDATE ".$prefix."users SET color='".$color."' WHERE username='".$loggedinname."'"; mysql_query($query); $query = "UPDATE ".$prefix."users SET profile='".$profile."' WHERE username='".$loggedinname."'"; mysql_query($query); $query = "UPDATE ".$prefix."users SET favpet='".$favpet."' WHERE username='".$loggedinname."'"; mysql_query($query); $query = "UPDATE ".$prefix."users SET about='".$about."' WHERE username='".$loggedinname."'"; mysql_query($query); I tried to simplify it by rewriting the following codes below, but unfortunately it did not work. It wouldnt give any errors, but the columns aint updated at all: Code: [Select] mysql_query("UPDATE ".$prefix."users SET nickname='".$nickname."' , gender='".$gender."' , color='".$color."' , profile='".$profile."' , favpet='".$favpet."' , about='".$about."' , WHERE username='".$loggedinname."'"); Did I make any mistake rewriting the codes? Or is it actually impossible to update six columns using only one mysql_query? Please help... hi, i'm new to php. i've got a problem. I've 3 tables and table has following content table 1 id name email address phone execution_date executor_name web_address table 2 id name email address phone execution_date executor_name project_title table 3 id name email address phone execution_date executor_name reviewer I want to export these table to and spreadsheet (.xls) with some criteria a form will assign which data will published at the spreadsheet with these criteria #all data can be exported from three tables #some column can be selected from three tables #some or all data can be selected from individual table i've implement a script for this but it didn't meet my requirements. Can anyone help? here is my script <?php $DB_Server = "localhost"; //your MySQL Server $DB_Username = "root"; //your MySQL User Name $DB_Password = "pass"; //your MySQL Password $DB_DBName = "mydb"; //your MySQL Database Name $search_from_date = $_POST['start_date']; $search_to_date = $_POST['end_date']; $Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password) or die("Couldn't connect to MySQL:<br>" . mysql_error() . "<br>" . mysql_errno()); $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:<br>" . mysql_error(). "<br>" . mysql_errno()); $now_date = date('m-d-Y H:i'); if(($_POST['typer_of_report'] == 'rrc_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName = 'rrc_record'; } if(($_POST['typer_of_report'] == 'erc_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName2 = 'erc_record'; } if(($_POST['typer_of_report'] == 'aeec_report') || ($_POST['typer_of_report'] == 'all_report')) { $DB_TBLName3 = 'aeec_record'; } $file_type = "vnd.ms-excel"; $file_ending = "xls"; //} header("Content-Type: application/$file_type"); header("Content-Disposition: attachment; filename=protocol_report.$file_ending"); header("Pragma: no-cache"); header("Expires: 0"); if($DB_TBLName) { $sql = "Select * from ".$DB_TBLName." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $Use_Title = 1; $title = "Report for $DB_TBLName on $now_date"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } //} echo "\n...\n"; } if($DB_TBLName2) { $sql = "Select * from ".$DB_TBLName2." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); $Use_Title = 1; $title = "Report for $DB_TBLName2 on $now_date"; if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } echo "\n...\n"; } if($DB_TBLName3) { $sql = "Select * from ".$DB_TBLName3." where execution_date >= '".$search_from_date."' and execution_date <= '".$search_to_date."' order by execution_date desc"; $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno()); $Use_Title = 1; $title = "Report for $DB_TBLName3 on $now_date"; if ($Use_Title == 1) { echo("$title\n"); } $sep = "\t"; //tabbed character for ($i = 0; $i < mysql_num_fields($result); $i++) { echo mysql_field_name($result,$i) . "\t"; } print("\n"); while($row = mysql_fetch_row($result)) { $schema_insert = ""; for($j=0; $j<mysql_num_fields($result);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL".$sep; elseif ($row[$j] != "") $schema_insert .= "$row[$j]".$sep; else $schema_insert .= "".$sep; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } } ?> have anyone any idea? |