PHP - Mysql Strangeness, Table Saves Intermittently...
This is a general mystery. I have two tables for a simple form. One contains names and the other emails. The names table has name and auto increment. The email tables have the email, id, and foreign key mapped with php's mysql_last_id_thingy().
The ids are fine. The problem is, out of ten tests, only six emails were saved. The rest are blank! What could cause such a thing to happen? any ideas? Chris Similar TutorialsHi I don't know exactly what to do to see correct date of birth into my sql database. I have following code i.e. $month=$_POST['month']; $year=$_POST['year']; $date=$_POST['date']; $date_value="$month/$date/$year"; echo"YYYY-mm-dd format:$date_value"; and sql insert statement is like this $sql = "INSERT INTO table_name(fname, lname, gender, add1, add2, city, state, zip, country, email, phone, cellphone, dob, photo1) VALUES('$fname','$lname','$gender','$add1','$add2','$city','$state','$zip','$country','$email','$phone','$cellphone', '$date_value','" . $image['name'] . "')"; I don't know what exactly I need to do? Even though I changed the setting in php ini to register_globals = On I would appreciate any kind of help regarding this matter. Thanks Smita Can anyone help me out with this. I have been struggling on and off it for weeks. Heres the description of the problem. I insert into a MySQL database from a query that is performed using an array that is posted from a page. The incoming array contains selected users (unique id's) that are used to lookup the users telephone numbers in a query and then insert into a DB. This code works intermittently. It will insert the records fine and then on the next attempt it may not? There is not pattern to it working and failing. Does anyone have any idea why this is happening? I have tried a loop using the posted array data count and also a loop based on the count of records brought back from the query but to no avail, it is still intermittently working. The '$stripped_message' data is just a text string. Code: [Select] <?php $date = date('Y-m-d H:i:s'); for ($i=0;$i<count($_POST['recipient']);$i++) // loop based on count of selected users $uk_mob_number = "44".substr($row_selected_recipients['User_mobile'], 1); // take off the first digit and replace with 44 $unique = makeRandomstring(); // Create a unique string for each entry $values.="('$unique','$date','$stripped_message','$uk_mob_number','sent','$date','$userid'),"; // usleep(50000); // Tried a delay to try to fix, did not work } // End of loop $values=substr($values,0,-1); // to remove last comma $query="INSERT INTO `sms` (`sms_unique`, `sms_sent`, `sms_body`, `sms_to`, `sms_status`, `sms_db_entry_time`, `sms_user`) VALUES $values".";"; ?> Hi! I have read like crazy to find a tutorial on a login page without My_SQL. Anyway I am working on a easy login/logged out page with sessions. Here is the login page with tree users in an array.
The things that I need some hints to solve is, when clicking on login the error message don't show. Instead the script goes to the logged in page right away. And when you write the wrong password you get loged in anyway.
I am not sure how or if it's possible to write a varible to a file this way. But I tried and recived a parse error with the txt varible.
When searching for topics I get more confused with the My_SQL varibles. I am near a breaking point at cracking the first step on PHP, but need some advice.
<?php $page_title = 'Logged in'; //Dynamic title include('C:/wamp/www/PHP/includes/header.html'); ?> <?php session_start(); //A array for the sites users with passwords $users = array( 'Dexter'=>'meow1', 'Garfield'=>'meow2', 'Miro'=>'meow3' ); //A handle to save the varible users to file on a new line from the last entry $handle = fopen("newusers.txt, \n\r") $txt = $users; fclose($handle); if(isset($_GET['logout'])) { $_SESSION['username'] = ''; header('Location: ' . $_SERVER['PHP_SELF']); } if(isset($_POST['username'])) { if($users[$_POST['username']] == $_POST['password']) { $_SESSION['username'] = $_POST['username']; }else { echo "Something went wrong, Please try again"; } } ?> <?php echo "<h3>Login</h3>"; echo "<br />"; ?> <!--A legend form to login--> <fieldset><legend>Fill in your username and password</legend> <form name="login" action="777log.php" method="post"> Username: <br /> <input type="text" name="username" value="" /><br /> Password: <br /> <input type="password" name="password" value="" /><br /> <br /> <input type="submit" name="submit" value="Login" /> </fieldset> </form> <?php //Footer include file include('C:/wamp/www/PHP/includes/footer.html'); ?>The logged in page <?php //Header $page_title = 'Reading a file'; include('C:/wamp/www/PHP/includes/header.html'); ?> <?php session_start(); //Use an array forthe sites users $users = array( 'Dexter'=>'meow1', 'Garfield'=>'meow2', 'Miro'=>'meow3' ); // if(isset($_GET['logout'])) { $_SESSION['username'] = ''; echo "You are now loged out"; //The user is loged out and returned to the login page header('Location: ' . $_SERVER['PHP_SELF']); } if(isset($_POST['username'])) { //Something goes wrong here when login without any boxes filled if($users[$_POST['username']] == $_POST['password']) { $_SESSION['username'] = $_POST['username']; }else { echo "Something went wrong, Please try again"; $redirect = "Location: 777.php"; } } ?> <?php if($_SESSION['username']): ?> <p><h2>Welcome <?=$_SESSION['username']?></h2></p> <p align="right"><a href="777.php">Logga ut</a></p><?php endif; ?> <p>Today Ben&Jerrys Chunky Monkey is my favorite!</p> <?php //Footer include('C:/wamp/www/PHP/includes/footer.html'); ?> create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello, I need some help. Say that I have a list in my MySQL database that contains elements "A", "S", "C", "D" etc... Now, I want to generate an html table where these elements should be distributed in a random and unique way while leaving some entries of the table empty, see the picture below. But, I have no clue how to do this... Any hints? Thanks in advance, Vero Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) I know I'm doing it something right, but can someone tell me why only one table is showing up? Can you help me fix the issue? Heres my code: function showcoords() { echo"J3st3r's CoordVision"; $result=dbquery("SELECT alliance, region, coordx, coordy FROM ".DB_COORDFUSION.""); dbarray($result); $fields_num = mysql_num_fields($result); echo "<table border='1'>"; // printing table headers echo "<td>Alliance</td>"; echo "<td>Region</td>"; echo "<td>Coord</td>"; // printing table rows while($row = mysql_fetch_array($result)) { // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row AS $Cell) echo "<tr>"; echo "<td>".$row['alliance']."</td>\n"; echo "<td>".$row['region']."</td>\n"; echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n"; echo "</tr>\n"; } echo "</table>"; mysql_free_result($result); } I have 2 rows inserted into my coords table. Just frustrated and ignorant to php. I have a table like this: http://empirebuildingsestate.com/company.html How can I separate the table values into variables so I can insert them into my mySQL database? I have been trying DOMDocument but i need some help. Hello everyone, I am working on a form that is similar to a shopping cart system and I am thinking of creating a button that submits the checked value and saves them to a $_SESSION variable. And also a link that links to a cart.html that takes the values of a $_SESSION variable. I am have trouble figuring what tag/attribute should I use in order to achieve that.
Right now my code attached below submits the checked values to cart.html directly. However I want my submit button to save the checked box to a $_SESSION variable and STAY on the same page. And then I will implement a <a> to link to the cart.php.
I researched a little bit about this subject and I know it's somewhat related to ajax/jquery. I just wanted to know more about it from you guys. I appreciate your attention for reading the post and Thanks!
Below is the form that I currently have:
<form name= "finalForm" method="POST" action="cart.php"> <input type="Submit" name="finalSelected"/> <?php foreach($FinalName as $key => $item) {?> <tr> <td><input type="checkbox" name="fSelected[]" value="<?php echo htmlspecialchars($FinalID[$key])?>" /> <?php echo "$FinalID[$key] & $item";?> </td> </tr> <?php } ;?>Below is the code for cart.php <?php require ('connect_db.php'); if(isset($_POST['finalSelected'])) { if(!empty($_POST['fSelected'])) { $chosen = $_POST['fSelected']; foreach ($chosen as $item) echo "aID selected: $item </br>"; $delimit = implode(", ", $chosen); print_r($delimit); } } if(isset($delimit)) { $cartSQL = "SELECT * from article where aID in ($delimit)"; $cartQuery = mysqli_query($dbc, $cartSQL) or die (mysqli_error($dbc)); while($row = mysqli_fetch_array($cartQuery, MYSQLI_BOTH)) { $aTitle[] = $row[ 'name' ]; } } ?> <table> <?php if(isset($delimit)) { $c=0; foreach($aTitle as $item) {?> <tr> <td> <?php echo $aTitle[$c]; $c++;?> </td> </tr> <?php }}?> </table> Hello, So I need a bit of help with tables. I currently have my website set up with the following tables: products (productId, productName, link, productPrice, productDesc) productscents (scentId, scentName, scentDesc) salves (productId, productName, productDesc) So now most products in the products table can be made in any of the scents in the productScents table (except for the salves and reed diffuser jar). I have a separate table of the salve types that can be ordered. How do I join each product with each productScent. For example: If I have the following products with their Id number: 1 Body Mist 2 Massage Oil 3 Reed Diffuser Jar and the following scents with their id (id has leading zeros): 0001 Mango 0002 Passionfruit 0003 Grapefruit How would I create a master products table that will display the following: 3 Reed Diffuser Jar 10001 Mango Body Mist 10002 Passionfruit Body Mist 10003 Grapefruit Body Mist 20001 Mango Massage Oil 20002 Passionfruit Massage Oil 20003 Grapefruit Massage Oil I hope this makes sense. lol. Any help would be greatly appreciated. Hi $eid2 = mysql_query("SELECT id FROM engines WHERE keyword = '%$tricker_engine%' LIMIT 1") or die(mysql_error()); $row = mysql_fetch_assoc($eid2); $eid = $row['id']; I want $eid to be the ID of the row where keyword = '%$tricker_engine%'. What is wrong with my code above? I have a mysql table named songs with 3 columns, id, artist,title. Most of the songs in the artist column are correct, ex: artist ------------------ John Denver Loretta Lynn Shania Twain Luke Bryan But some of the songs in the artist column are reveresed with a comma, ex: artist ----------------- Dever, John Lynn. Loretta Twain, Shania Bryan, Luke Is there an easy php code snippet or mysql statement that i can use to reverse the order of first name and last name and remove the comma in the last example so the artst columd matches the first example? I hope this makes sense, thanks, Dale. Greetings,
My current code logs into a database, opens a table named randomproverb, randomly selects 1 proverb phrase, and then SHOULD display the proverb in the footer of my web page.
As of right now, the best I can do is get it to display "Array", but not the text proverb... this code below actually causes my whole footer to not even show up.
Please help!
<?php include("inc_connect.php"); //Connects to the database, does work properly, already tested $Proverb = "randomproverb"; $SQLproverb = "SELECT * FROM $Proverb ORDER BY RAND() LIMIT 1"; $QueryResult = @mysql_query($SQLproverb, $DBConnect); while (($Row = mysql_fetch_assoc($QueryResult)) !== FALSE) { echo "<p style = 'text-align:center'>" . {$Row[proverb]} . "</p>\n"; } $SQLString = "UPDATE randomproverb SET display_count = display_count + 1 WHERE proverb = $QueryResult[]"; $QueryResult = @mysql_query($SQLstring, $DBConnect); ... ?> I have a survey that uses colors. At the moment someone takes the survey I need to capture the values that are in a table called "tbl_colors" and write them to each survey in "tbl_surveys" as a row. tbl_colors id, hex_color 1 FFF432 2 CC3399 3 DD3399 and so on to the number 12 tbl_survey id, timestamp, name, hex01, hex02, hex03, hex04, etc to hex12 I have written code that "works" but I know it is extremely redundant and overloaded and someone could probably do the same thing in less than 10 lines of code. So, I post it here so I can learn from my mistakes. // Make a MySQL Connection $query = "SELECT * FROM tbl_colors WHERE id = 1"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color1 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 2"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color2 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 3"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color3 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 4"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color4 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 5"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color5 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 6"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color6 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 7"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color7 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 8"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color8 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 9"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color9 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 10"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color10 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 11"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color11 = $row['hex_color']; $query = "SELECT * FROM tbl_colors WHERE id = 12"; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $color12 = $row['hex_color']; //echo $color1.$color2.$color3.$color4.$color5.$color6.$color7.$color8.$color9.$color10.$color11.$color12; mysql_query("INSERT INTO tbl_surveys (hex01, hex02, hex03, hex04, hex05, hex06, hex07, hex08, hex09, hex10, hex11, hex12) VALUES ('$color1', '$color2', '$color2', '$color3', '$color4', '$color5', '$color6', '$color7', '$color8', '$color9', '$color10', '$color11', '$color12')"); I am trying to place a unique number into a mysql table. Currently, my code generates a random number, then is supposed to scan through the table for that number. If the code finds that number already in the table, it generates a new random number and repeats the process. I have commented my code for the purpose of this help forum: Code: [Select] $result = mysqli_query($link,"SELECT * FROM testTable"); do { $end = true; //prepares end of loop $idNum = rand(1,10); //rand(1,999999); <-- for testing purposes I have reduced the number generated $idNumTx = (string)$idNum; //loop through the rows while ($row = mysqli_fetch_assoc($result)) { if ($row['idNum'] = $idNum) //check if the random number equal to this row { $end = false; //prep end of loop repeat echo $idNumTx; //display rand number that failed for testing purposes echo " NO! "; //display error for testing purposes } } } while(!$end); I know I must be doing something wrong, as when I run this, it runs the if statement within the while loop always executes, and I get an output like: Code: [Select] 1 NO! 1 NO! 1 NO! 1 NO! 1 NO! 1 NO! 5 Win Win is when it places the value before it, in this case 5, into the table. However, the value of 5 might already be in the table and it doesn't seem to matter. I execute the code multiple times, and it seems to increase the number of "# NO!" almost (but not every) time. However, each time ALL of the "# NO!" are the same #, and the "# Win" just seems to be random (as it should be, but not unique). Checking the table after shows me random numbers between 1 and 10 (as it should) in the correct field, but the are not unique. (Ex/ Both row 1 and 5 could have the same value, say 6) I'm hopefully doing something simple wrong, so someone please point it out to me Hi,
The following code was written by someone else. It allows me to upload images to a directory while saving image name in the mysql table.
I also want the code to allow me save other data (surname, first name) along with the image name into the table, but my try is not working, only the images get uploaded.
What am I missing here?
if(isset($_POST['upload'])) { $path=$path.$_FILES['file_upload']['name']; if(move_uploaded_file($_FILES['file_upload']['tmp_name'],$path)) { echo " ".basename($_FILES['file_upload']['name'])." has been uploaded<br/>"; echo '<img src="gallery/'.$_FILES['file_upload']['name'].'" width="48" height="48"/>'; $img=$_FILES['file_upload']['name']; $query="insert into imgtables (fname,imgurl,date) values('$fname',STR_TO_DATE('$dateofbirth','%d-%m-%y'),'$img',now())"; if($sp->query($query)){ echo "<br/>Inserted to DB also"; }else{ echo "Error <br/>".$sp->error; } } else { echo "There is an error,please retry or check path"; } } ?>joseph Im trying to insert some values automatically into a table once the form loads, but Im getting an error. Here is the code Code: [Select] <?php $aid = $_GET['aid']; $sd = $_GET['sd']; ?> <style> #message {margin:20px; padding:20px; display:block; background:#cccccc; color:#cc0000;} </style> <div id="message">Your notification has been submitted.</div> <div style="text-align:center "> <?php $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="INSERT INTO broken_links (articleid, article) VALUES ('$aid', '$sp')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Submitted"; mysql_close($con) ?> <table border="0" cellpadding="3" cellspacing="3" style="margin:0 auto;" > <input type="submit" id="Login" value=" Thank you. Please press to close " onclick="tb_remove()"></td> </tr> </table> </div> Any help will be appreciated Ok, I got someone to help me fix this but he had no idea what the error was... I have 2 tables, one called points and the other called members. In members i have got: id name In points i have got: id memberid promo I have the following code: Code: [Select] <?php $con = mysql_connect("localhost","slay2day_User","slay2day"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("slay2day_database",$con); $sqlquery="SELECT Sum(points.promo) AS score, members.name, members.id = points.memberid Order By members.name ASC"; $result=mysql_query($sqlquery,$con); while ($row = mysql_fetch_array($result)) { //get data $id = $row['id']; $name = $row['name']; $score = $row['score']; echo "<b>Name:</b> $name<br />"; echo "<b>Points: </b> $score<br />" ; echo "<b>Rank: </b>"; if ($name == 'Kcroto1'): echo 'The Awesome Leader'; else: if ($points >= '50'): echo 'General'; elseif ($points >= '20'): echo 'Captain!'; elseif ($points >= '10'): echo 'lieutenant'; elseif ($points >= '5'): echo 'Sergeant'; elseif ($points >= '2'): echo 'Corporal'; else: echo 'Recruit'; endif; endif; echo '<br /><br />'; } ?> I am getting the following error when i do the query in mysql: Code: [Select] #1109 - Unknown table 'points' in field list And when i open the webpage i get the following error: Code: [Select] Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/slay2day/public_html/points/members.php on line 18 Please Help me? guys, please help i need balance amount of fees all students has to pay. Following is the DB structure. `feepayid` is primary key for paymentstable and paymentregister & `studentid` is primary in studentstable. I have written a query for this, please evaluate the query. paymentstable feepayid classid paydate paymode feeamount remarks feediscount 32 8 2012-03-06 19:32:35 1 500 hgfhf 0 31 8 2012-03-04 19:32:35 1 800 hgfhf 0 30 8 2012-02-06 19:32:35 1 1200 hgfhf 0 29 8 2012-02-06 19:32:35 1 1100 hgfhf 0 paymentregister feepayid payid totalfee studentid 32 3 1500 2 31 2 3500 2 30 1 4500 4 29 3 5500 4 studentstable studentid studentname 2 john 4 mathew 5 peter 6 mary Code: [Select] SELECT d.`studentid`, SUM(a.`totalfee` - (SELECT SUM(`feeamount`) FROM `paymentstable` WHERE a.`feepayid` = `feepayid`)) AS balancefee FROM `studentstable` d LEFT JOIN `paymentregister` a ON a.`studentid` = d.`studentid` GROUP BY d.`studentid`; Hey Guys I have the following table: (login) I need that table to be echoed he But it needs to filter it for the school they are logged in as. Help: When they login they have to select what school they are at so you can use that code. example: PHS = Poole High School |