Jump to content

marius_haugan

New Members
  • Posts

    6
  • Joined

  • Last visited

marius_haugan's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. You mean something like this? The while loop will go through your table and store your rows in an associative array, which in turn you can assign to a variable and echo out any way you need. $dbhost = "localhost"; $dbuser = "username"; $dbpass = "password"; $dbname = "my_database"; $dblink = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); $query = "SELECT * FROM countryTable WHERE country='USA'"; $result = mysqli_query($dblink, $query); while ($row = mysqli_fetch_assoc($result)) { $country = $row["country"]; echo $country; } You might consider looking into basic courses on PHP / SQL. There are some really good ones out there. I particularly like the ones from http://lynda.com
  2. He did show code. This: $query = "select * from countryTable where country = ".$_post['country']. " order by country asc";
  3. Agreed.. PDO & prepared statements might be too advanced though. There are easier solutions. Maybe this is better as a quick fix. $dbhost = "localhost"; $dbuser = "root"; $dbpass = "password"; $dbname = "database_name"; $dblink = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); $input = $_POST["country"]; $input = mysqli_real_escape_string($dblink, $input); // or some other sanitizing function (htmlspecialchars) $query = "SELECT * FROM countryTable WHERE country='$input';
  4. Try this! $input = $_POST["country"]; $query = "SELECT * FROM countryTable WHERE country='$input' ORDER BY country ASC";
  5. See how much easier your code is to read now? if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); } //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); while (($data = fgetcsv($handle, 2000, ",")) !== FALSE){ $Sql=mysql_query("select * from test where id ='$id'"); if(mysql_num_rows($Sql) > 0) { $import="update test set `name`='$data[1]', `gender`='$data[2]', `designation`='$data[3]' where id='$data[0]'"; mysql_query($import) or die(mysql_error()); } else { $import="insert into test set `name`='$data[1]', `gender`='$data[2]', `designation`='$data[3]', `id`='$data[0]'"; mysql_query($import) or die(mysql_error()); } } fclose($handle); print "Update done";
  6. I can't see what's giving you trouble. It's difficult to read the code when it's not formatted. (I'm a noob too!) You should use the full editor when posting and select the "code-option" for better readability! But anyway, here is a basic set up for retrieving and sending values from an HTML form to your database. Maybe it will help. <form method="POST" action="$_SERVER['PHP_SELF']"> Name: <input type="text" name="my_name"> Phone: <input type="number" name="my_phone"> <input type="submit"> </form> <?php $dbhost = "localhost"; $dbuser = "my_username"; $dbpass = "my_password"; $dbname = "my_database"; $dblink = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname); $value1 = "$_POST['my_name']"; $value2 = "$_POST['my_phone']"; $query = "INSERT INTO table_name (column1, column2) VALUES ('$value1', '$value2'); mysqli_query($dblink, $query); ?> Make sure your database is defined correctly, and see if you can get this basic set up to work. Then, expand one line of code at a time and you should be able to get where you want to be!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.