PHP - Simple_html_dom: Simple Use-case - To Get Back Data For Storing In Sqlite Db
hello dear php-experts,
https://europa.eu/youth/volunteering/organisations_en#open
<?php // Report all PHP errors (see changelog) error_reporting(E_ALL); include('inc/simple_html_dom.php'); //base url $base = 'https://europa.eu/youth/volunteering/organisations_en#open'; //home page HTML $html_base = file_get_html( $base ); //get all category links foreach($html_base->find('a') as $element) { echo "<pre>"; print_r( $element->href ); echo "</pre>"; } $html_base->clear(); unset($html_base); ?>
I have the above code and I'm trying to get certain elements of the page but it isn't returning anything.
Is it possible that certain PHP functions might be disabled on the server to stop that? The above code works perfectly on other sites.
Is there any workaround?
btw: i have created a small snipped as a proof of concept to run this with Python and BeautifulSoup -
import requests from bs4 import BeautifulSoup url = 'https://europa.eu/youth/volunteering/organisations_en#open' response = requests.get(url) soup = BeautifulSoup(response.content, 'lxml') print(soup.find('title').text) block = soup.find('div', class_="eyp-card block-is-flex")
and this....
European Youth Portal >>> block.a <a href="/youth/volunteering/organisation/48592_en" target="_blank">"Academy for Peace and Development" Union</a> >>> block.a.text '"Academy for Peace and Development" Union' >>> block.select_one('div > div > p:nth-child(9)') <p><strong>PIC:</strong> 948417016</p> >>> block.select_one('div > div > p:nth-child(9)').text 'PIC: 948417016'
what is aimed in the end - i want to gather the first 20 results of the page - and put them in to a sql-db or alternatively show the information in a little widget Similar TutorialsI am trying to convert and old website from mysql database to sqlite. One of the chores it must do is collect information from the database and put it in a list/menu select box on a page so the user can choose which item to pursue.
In the following (incomplete) snippit, I am doing something incorrectly because the sql query does get the proper information (I can put it in a table on the page just fine). But I'm having trouble getting the information into the select options on a list/menu. It appears to be putting them all, one after the other in the first option spot. The last one seems to be the only one of 6 or 7 that shows up.
It's been 10 or 12 years since I've messed with php, so I think I'm way behind... any help would be appreciated.
---------------------------
<form action="sqlPropDisplay.php" method="post" id="Residential"> <?php session_start(); if(!isset($_SESSION['User'] )) header('Location : error.php'); ?> im not being redirected even when the $_SESSION['User'] is not set neither does it display any error message other than a white blank space. Please help me som1 as how I can make this to work or suggest any other altenatives so as to get it redirected as i dont want anonymous users to access some contents unles he logs in as members. Thanx This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=327423.0 Im making a application but many users can access it at the same time, also the data that needs to be stored into the database in 3 parts firstly the user will enter some details the comany will fill out the reamining details and the user will then accept or decline the companies proposal. The issue im havign will it be easier to just store all of this information into session variables and then save them into the database at the end when all of the details are ready ? Thank You Can anyone tell me whats wrong with this: The file uploads fine, the url however does not get posted to the database? I added a 'or die' but it didn't execute...Do I need to move the query higher up the script? <?php include ('base.php'); $id = $_GET['id']; if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "imgs/pictures/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } $file = $_FILES["file"]["name"]; $sql = "UPDATE `chillp_security`.`staff` SET `picture` = \'imgs/pictures/$file\' WHERE `staff`.`id` = $id;"; ?> Hi, I have a XHTML/PHP page that loads a PHP file each couple of seconds for building up the page. The PHP file should retreive data that keeps changing. What would be the best way to store and retreive the data? Obviously i can do this with a database but that will put a lot of stress on the server as each user keeps polling the database. So i was looking into other methods of doing this. I have tried doing this with a plain text file and CSV files using fwrite to put the initial data into a file with separators. Then retrieving that file and explode it into a multidimensional array again. I am unsuccessful here to assign the key values to the new array. I have also tried many snippets for this but these where also not working properly for me. Maybe XML is the key, i didn't really delve into it yet but it seems i have to get extra programs or parser to actually write and change files? But then again i can't find any working tutorials on how to put multi dimensional strings back and forth between PHP and XML. So what needs exactly to be done. Well i'm creating a game where you can fight each other with 4 units on a turn base. The units have a speed stat that determines when it's there turn to act. Like if (unit 1) has 3 speed and (unit 2) 5 speed they will move like this on the time line (unit 1) -> (unit 2) -> (unit 1) -> (unit 1) -> (unit 2). So the plan is each time the user acts with a unit to increment it's speed by the base value. A script will run each time picking up the next unit in line. The PHP page does a check on which player the unit belongs to and if that matches the players ID it will sent the necessary information. The other player will get something like "not your turn". Tx, Hey I am having a small problem with setting and storing data using $_SESSION for a login script to validate that a user is logged in. The outputted error message I'm getting is; Notice: Undefined index: userid ...\...\ Notice: Undefined variable: userid in ...\...\ The PHP code I'm using for the validation Code: [Select] <?php session_start(); //must call session_start before using any $_SESSION variables $username = $_POST['username']; $password = $_POST['password']; $userid = $_POST['userid']; //validating a user function validateUser() { session_regenerate_id (); //this is a security measure $_SESSION['valid'] = 1; $_SESSION['userid'] = $userid; } Let me know if you need any other bits of code to establish what is happening I really need help with this. Thanks. I want to store a series of data which are called in a main php file. Do you suggest to store them in xml as file1.xml: <title>TITLE</title> <content>CONTENT</content> or file1.php: $title="TITLE"; $content="CONTENT"; AND is it better to create separate file for each article or storing all data in one single file? Hi there, I am working on a PHP web form and I have a very simple situation I guess, I have a variable named: $MyVal When I do print_r($MyVal); To see whats inside, I get: SimpleXMLElement Object ( [0] => 8.23 ) Now I am assigning this variable into a session variable so that I can do calculations with it. So I assign: $_SESSION['MySesVal'] = $MyVal; But after assigning to session variable, when I do my calculations: $finalValue = $_SESSION['MySesVal'] * 4; I get 0. So is it because the actual $MyVal variable has some XML stuff as: SimpleXMLElement Object ( [0] => 8.23 ) So what is the right way to properly assign $MyVal variable to a session variable to do calculations. Please reply. All comments and feedbacks are always welcome. Thank you! Here is my code... Code: [Select] <?php mysql_connect("localhost", "user", "pass")or die("cannot connect"); mysql_select_db("database")or die("cannot select DB"); $myemail = mysql_real_escape_string($_POST['myemail']); $mypassword = mysql_real_escape_string($_POST['mypassword']); $mypassword = md5($mypassword); $myemail = stripslashes($myemail); $mypassword = stripslashes($mypassword); $sql="SELECT * FROM users WHERE email='$myemail' and password='$mypassword'"; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1){ session_start(); $_SESSION["myemail"]= "$myemail"; header("location:home.php"); } else { header("location:fail.php"); } ?> What can I do to this code so that it will also store first name from the database inside a session? Hey everyone I'm pulling data from my db and then trying to store each value to its own var. the problem is the amount of values is always changing. here is what I have that isnt working $result = mysql_query("SELECT thismonth FROM list"); while($row = mysql_fetch_array($result)) { echo $row[0] . "<br>"; // this prints out all the values perfectly } no I just dont know how to store them so i can use them later. Hello,
I have a table with these columns (database)
table.JPG 34.95KB
0 downloads
and i have a static form through which user define the installments. Static 24 input boxes are there like this
<form name="installment" method="post" action="" enctype="multipart/form-data" onsubmit="return validate()"> <table id="dt_hScroll" class="table table-striped"> <thead> <tr> <th>SL No.</th> <th>Amount</th> <th>Due Date</th> </tr> <tr> <td> 1. </td> <td> <input type="text" name="installment1" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date1" class="tcal span4" value="<?php //echo date("Y-m-d"); ?>" /> </td> </tr> <tr> <td> 2. </td> <td> <input type="text" name="installment2" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date2" class="tcal span4" /> </td> </tr> <tr> <td> 3. </td> <td> <input type="text" name="installment3" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date3" class="tcal span4" /> </td></tr> <tr> <td> 4. </td> <td> <input type="text" name="installment4" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date4" class="tcal span4" /> </td></tr> <tr> <td> 5. </td> <td> <input type="text" name="installment5" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date5" class="tcal span4" /> </td></tr> <tr> <td> 6. </td> <td> <input type="text" name="installment6" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date6" class="tcal span4" /> </td></tr> <tr> <td> 7. </td> <td> <input type="text" name="installment7" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date7" class="tcal span4" /> </td></tr> <tr> <td> 8. </td> <td> <input type="text" name="installment8" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date8" class="tcal span4" /> </td></tr> <tr> <td> 9. </td> <td> <input type="text" name="installment9" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date9" class="tcal span4" /> </td></tr> <tr> <td> 10. </td> <td> <input type="text" name="installment10" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date10" class="tcal span4" /> </td></tr> <tr> <td> 11. </td> <td> <input type="text" name="installment11" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date11" class="tcal span4" /> </td></tr> <tr> <td> 12. </td> <td> <input type="text" name="installment12" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date12" class="tcal span4" /> </td></tr> <tr> <td> 13. </td> <td> <input type="text" name="installment13" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date13" class="tcal span4" /> </td></tr> <tr> <td> 14. </td> <td> <input type="text" name="installment14" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date14" class="tcal span4" /> </td></tr> <tr> <td> 15. </td> <td> <input type="text" name="installment15" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date15" class="tcal span4" /> </td></tr> <tr> <td> 16. </td> <td> <input type="text" name="installment16" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date16" class="tcal span4" /> </td></tr> <tr> <td> 17. </td> <td> <input type="text" name="installment17" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date17" class="tcal span4" /> </td></tr> <tr> <td> 18. </td> <td> <input type="text" name="installment18" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date18" class="tcal span4" /> </td></tr> <tr> <td> 19. </td> <td> <input type="text" name="installment19" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date19" class="tcal span4" /> </td></tr> <tr> <td> 20. </td> <td> <input type="text" name="installment20" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date20" class="tcal span4" /> </td></tr> <tr> <td> 21. </td> <td> <input type="text" name="installment21" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date21" class="tcal span4" /> </td></tr> <tr> <td> 22. </td> <td> <input type="text" name="installment22" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date22" class="tcal span4" /> </td></tr> <tr> <td>23. </td> <td> <input type="text" name="installment23" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date23" class="tcal span4" /> </td></tr> <tr> <td> 24. </td> <td> <input type="text" name="installment24" id="installment" class="span4" value="0" /> </td> <td> <input type="text" name="due_date24" class="tcal span4" /> </td></tr> <tr><td></td><td> <input type="submit" name="save" id="save" value="Save" class="btn btn-info span3" /> <input type="hidden" readonly="readonly" name="roll_no" value="<?php echo $roll_no; ?>" class="span5" /> </td><td></td></tr> </thead> </table> </form>Here i am not getting how to store it in that table. Actually all the 24 inputs are not mandatory. If user fills only 2 then also it should store it in the database table. I tried to do like this if(isset($_POST['save'])) { $roll_no = $_POST['roll_no']; $ins_amt1 = $_POST['installment1']; $due_date1 = $_POST['due_date1']; $ins_amt2 = $_POST['installment2']; $due_date2 = $_POST['due_date2']; $ins_amt3 = $_POST['installment3']; $due_date3 = $_POST['due_date3']; $ins_amt4 = $_POST['installment4']; $due_date4 = $_POST['due_date4']; $ins_amt5 = $_POST['installment5']; $due_date5 = $_POST['due_date5']; $ins_amt6 = $_POST['installment6']; $due_date6 = $_POST['due_date6']; $ins_amt7 = $_POST['installment7']; $due_date7 = $_POST['due_date7']; $ins_amt8 = $_POST['installment8']; $due_date8 = $_POST['due_date8']; $ins_amt9 = $_POST['installment9']; $due_date9 = $_POST['due_date9']; $ins_amt10 = $_POST['installment10']; $due_date10 = $_POST['due_date10']; $ins_amt11 = $_POST['installment11']; $due_date11 = $_POST['due_date11']; $ins_amt12 = $_POST['installment12']; $due_date12 = $_POST['due_date12']; $ins_amt13 = $_POST['installment13']; $due_date13 = $_POST['due_date13']; $ins_amt14 = $_POST['installment14']; $due_date14 = $_POST['due_date14']; $ins_amt15 = $_POST['installment15']; $due_date15 = $_POST['due_date15']; $ins_amt16 = $_POST['installment16']; $due_date16 = $_POST['due_date16']; $ins_amt17 = $_POST['installment17']; $due_date17 = $_POST['due_date17']; $ins_amt18 = $_POST['installment18']; $due_date18 = $_POST['due_date18']; $ins_amt19 = $_POST['installment19']; $due_date19 = $_POST['due_date19']; $ins_amt20 = $_POST['installment20']; $due_date20 = $_POST['due_date20']; $ins_amt21 = $_POST['installment21']; $due_date21 = $_POST['due_date21']; $ins_amt22 = $_POST['installment22']; $due_date22 = $_POST['due_date22']; $ins_amt23 = $_POST['installment23']; $due_date23 = $_POST['due_date23']; $ins_amt24 = $_POST['installment24']; $due_date24 = $_POST['due_date24']; $items = array(); $installment[] =array($ins_amt1, $ins_amt2, $ins_amt3, $ins_amt4, $ins_amt5, $ins_amt6, $ins_amt7, $ins_amt8, $ins_amt9, $ins_amt10, $ins_amt11, $ins_amt12, $ins_amt13, $ins_amt14, $ins_amt15, $ins_amt16, $ins_amt17, $ins_amt18, $ins_amt19, $ins_amt20, $ins_amt21, $ins_amt22, $ins_amt23, $ins_amt24); //$in_values= serialize($installment); $due_date[] = array($due_date1, $due_date2, $due_date3, $due_date4, $due_date5, $due_date6, $due_date7, $due_date8, $due_date9, $due_date10, $due_date11, $due_date12, $due_date13, $due_date14, $due_date15, $due_date16, $due_date17, $due_date18, $due_date19, $due_date20, $due_date21, $due_date22, $due_date23, $due_date24); //$in_dates= serialize($due_date); //$s1 = "insert into installment(id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) values ('', ".$fee_id.", '".$roll_no."', ".$in_values.", '".$in_dates."', '', 'unpaid', ''"; foreach($installment as $row_key => $value) { $item = $value; $uom = $due_date[$row_key]; $items[] = sprintf("(%d, %d, '%s', %d, '%s', '%s', '%s', '%s')", '', $fee_id, mysql_real_escape_string($roll_no), intval($item), $uom, '', '', '' ); } $msql = 'INSERT INTO installment (id, fee_id, student_id, amount, due_date, paid_date, status, rec_no) VALUES '.implode(', ', $items);But it is taking only one data. Can somebody please suggest. The data has to be saved like this saveddata.JPG 70.92KB 0 downloads Somebody please help. Thank you hi everyone, i just signed up on this forum. I have issue, my clients wants to save time by copying data into a textarea and then letting the script process it and store it in database. the problem is never done that. the data is made up for eg. Title Mr Name Radio86 Address Chiltren House etc.... how do i split this data up and store it in database, btw ive just started programming in php in other words newbie Please help me, thanks in advance This is more of a database architect question.
I am building a CMS for website development. I am ready to use it for the first time on one of my clients. Now, my issue is is how to set up some or one of my table(s) for some areas that my client wants to be able to change in the admin section.
In their website on the front page, I put together this nice block slider. Its 6 blocks with text, a background image and nice effects. At first it was always going to be static, which was no issue at all, but later they came to me and asked if they could be able to change words in the boxes themselves in the admin section..
Of course this can be easily done by creating a table that is associated with this home page block thing and each row in the table will correspond to one of the blocks on the home page.
But I believe there might be an easier way to store this type of data without having to create another table for every feature the client wants to edit, for example they also want to be able to edit a slider on another page.
The WordPress database then came into my mind and how they store most of their data as JSON. So I was then thinking of creating a table named 'modules' for examples with three columns (id, title, data). Then inside the data column store the editable fields as a JSON string object.
For example a row could like like :
1, "Front Page Box Slider", {"slider-home" : [ {"data" : "value", "img_1", "value1"}, {"data" : "value", "img_2", "value2"} ]}
I've been doing a bit of research on this and people have just been saying, never do this if you do want your data to be searched through, which I don't.
Can anyone tell me why or why not I should do this, or maybe a better solution to my problem?
Thank you
Edited by carlosmoreeira, 17 September 2014 - 07:37 PM. I have created a login form. I am sending values through Ajax for form validation. However, I am having problem with the code that I am unable to store values in Sessions & Cookies.
I have added a "Remember me" checkbox into login form. I want to validate Boolean value using Javascript Checked property and send the data to PHP for validation.
If user clicks on remember me checkbox then the data should be stored in either Sessions & Cookies. If it is not checked then data should be stored only in Sessions. I am posting here my login form code, Ajax code & PHP code.
Could you guys help me to point out my mistake what I am doing wrong in this code?
Login Form:
<input type="checkbox" id="cb" name="cb"> <label for="cb">Remember me</label>Ajax Code: function login(){var e = _("email").value; var pass = _("password").value; var cb = _("cb").value; if(e == "" || pass == ""){ _("status").innerHTML = "Please fill out the form"; } else { _("loginbtn").style.display = "none"; _("status").innerHTML = 'please wait ...'; var ajax = ajaxObj("POST", "handlers/login_handler.php"); ajax.onreadystatechange = function() { if(ajaxReturn(ajax) == true) { if(ajax.responseText == "login_failed"){ _("status").innerHTML = "Login failed, please try again."; _("loginbtn").style.display = "block"; } else { window.location = "message.php?msg=Hello "+ajax.responseText; } } } ajax.send("e="+e+"&pass="+pass+"&cb="+cb); } }PHP Code: $cb = cleanstr($_POST['cb']); if(isset($cb) && ($cb == true)) { // IF USER CLICKED ON REMEMBER ME CHECKBOX CREATE THEIR SESSIONS AND COOKIES $_SESSION['userid'] = $db_id; $_SESSION['username'] = $db_username; $_SESSION['password'] = $db_pass; setcookie("id", $db_id, strtotime( '+30 days' ), "/", "", "", TRUE); setcookie("user", $db_username, strtotime( '+30 days' ), "/", "", "", TRUE); setcookie("pass", $db_pass, strtotime( '+30 days' ), "/", "", "", TRUE); // UPDATE THEIR "IP" AND "LASTLOGIN" FIELDS $sql = "UPDATE users SET ip='$ip', lastlogin=now() WHERE id='$db_id' LIMIT 1"; $query = mysqli_query($con, $sql); echo $db_username; exit(); } else { // IF USER HAS NOT CLICKED ON REMEMBER ME CHECKBOX CREATE THEIR SESSIONS ONLY $_SESSION['userid'] = $db_id; $_SESSION['username'] = $db_username; $_SESSION['password'] = $db_pass; // UPDATE THEIR "IP" AND "LASTLOGIN" FIELDS $sql = "UPDATE users SET ip='$ip', lastlogin=now() WHERE id='$db_id' LIMIT 1"; $query = mysqli_query($con, $sql); echo $db_username; exit(); } To me it is logical to store config data such as site name, meta, etc in a php file rather than storing ina table in mysql database. This will reduce the number of calls to the mysql database, as these are key parameters and needed in every page. But, a well-developed CMS like Wordpress uses a mysql table to store such basic data. What is your idea? Ain't it better to reduce mysql loads? I am having some problems with part of the code. What is going on is a user registers info with a form and is sent an email with a confirmation link. The info that was in a temp DB table is moved to a member table. All of this works fine, but I am trying to be able to store an ID and username associated with their passkey info and echo that variable out. This part I am having trouble with. Code is here. <? session_start(); include('config.php'); // Passkey t from link $passkey=$_GET['passkey']; $tbl_name1="Profile_temp"; // Retrieve data from table where row matches passkey $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'"; $result1=mysql_query($sql1); // If successfully queried if($result1){ // Count how many row has this passkey $count=mysql_num_rows($result1); // if passkey is found retrieve info from temporary DB if($count==1){ $rows=mysql_fetch_array($result1); $FirstName=$rows['FirstName']; $LastName=$rows['LastName']; $UserName=$rows['UserName']; $Password= md5($rows['Password']); $Password2=md5($rows['Password2']); $email=$rows['email']; $Zip=$rows['Zip']; $Birthday=$rows['Birthday']; $Security=$rows['Security']; $Security2=$rows['Security2']; $tbl_name2="Profile"; // Insert data that retrieves from "temp_members_db" into table "registered_members" $sql2="INSERT INTO $tbl_name2(`FirstName`,`LastName`,`Username`,`Password`,`Password2`,`email`,`Zip`,`Birthday`,`Security`,`Security2`) VALUES ('$FirstName','$LastName','$UserName','$Password','$Password2','$email','$Zip','$Birthday','$Security','$Security2')"; //echo $sql2; $result2=mysql_query($sql2); } // if passkey is not found, display message "Wrong Confirmation code" else { echo "<h2>Sorry, Your passkey was not found.</h2>"; } while ($row = mysql_fetch_assoc($result2)) { $_SESSION['id'] = $row['id']; $_SESSION['UserName']=$user_name; } // if successfully moved data from table"temp_members_db" to table "registered_members" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db" if($result2){ echo "<h2>Your account has been activated, </h2>"; echo "$user_name"; echo"<p>You may now upload a profile picture</p>"; // Delete information of this user from table "temp_members_db" that has this passkey $sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'"; $result3=mysql_query($sql3); } } ?> getting an error for this part while ($row = mysql_fetch_assoc($result2)) { $_SESSION['id'] = $row['id']; $_SESSION['UserName']=$user_name; } the error is "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in confirmation.php on line 62" Hi all I have a question about how to store parsed data into a multidimensional arrays -- I can store items into an array, but multidimensional arrays mystify me a bit. Any help would be greatly appreciated. I'm storing the images in a table, grouped according to their table and their descriptions, so that later when I call the images, I can display them accordingly. I'm using the Simple HTML DOM Parser. So say I have two tables, one with three images, and another with one. I'd like the resulting to array to look like: Code: [Select] Array ( [0] => Array ( [0] => image1.jpg [1] => 1st Variation Description ) [1] => Array ( [0] => image2.jpg [1] => image3.jpg [2] => image4.jpg [3] => 2nd Variation Description ) ) This is what I have so far: Code: [Select] $html = str_get_html($vartables); $varinfo = array(); foreach($html->find('table') as $table){ $varinfo[] = $table->innertext; } print_r($varinfo); Which yields: Code: [Select] Array ( [0] => <tr> <td width=150> Description1 </td> <td><a href="image1.jpg"> <img src="image1" height=100 border=1></a> </td> </tr> [1] => <tr> <td width=150> Description2 </td> <td><a href="image2.jpg"> <img src="image2.jpg" height=200 border=1></a> </td> <td><a href="image3.jpg"> <img src="image3.jpg" height=200 border=1></a> </td> <td><a href="image4.jpg"> <img src="image4.jpg" height=200 border=1></a> </td> </tr> ) I'd like to strip out the html and keep the .jpg's and descriptions together in a multidimensional array...unfortunately my newbness is getting the better of me there, I'm researching but running into a roadblock. Thanks in advance for any help. hi, I have created a login page this is my code <?php if (!isset($_SESSION)) { session_start(); } $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="Marketing"; // Database name $tbl_name="Marketinglogin"; // 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"); $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM Marketinglogin WHERE username='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); if ($myusername == "sandeep") { header("location:Marketingadmin.php"); } else { header("location:Marketingemployeeform.php"); } } else { echo "wrong password"; } ?> Marketingemployee form has some fields..here when we click submit button all the fields as well as the loginusername has to be stored in the database <?php if (!isset($_SESSION)) { session_start(); } $con = mysql_connect("localhost","root", ""); if (!$con) {die('Could not connect to DB: ' . mysql_error() );} mysql_select_db ("Marketing", $con); $date = $_POST['year'].$_POST['month'].$_POST['dt'] ; $_SESSION['myusername']=$_POST['myusername']; $myusername=$_SESSION['myusername']; $sql="INSERT INTO Marketingemployeetable (Employeeid, Date,Sector,Place,Contactpersonname,Contactaddress,Mobileno)VALUES ( '$myusername','$date','$_POST[project]','$_POST[place]','$_POST[Contactpersonname]','$_POST[Contactaddress]','$_POST[Mobileno]')"; if (!mysql_query($sql,$con)) {die ('Error: ' . mysql_error());} echo "Record added"; mysql_close($con)?> please help me out here |