Jump to content

alenphp

New Members
  • Posts

    5
  • Joined

  • Last visited

alenphp's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Would you be kind to put it in above code? I don't know how. I found following code using mysql not PDO and it works. But I need it in PDO. Or just tell me where exactly does it fit this line you wrote. Thank you $connection = mysql_connect("$host", "$username", "$password") or die ("Unable to connect to server"); mysql_select_db("$database") or die ("Unable to select database"); $sql = "TRUNCATE TABLE `$table`"; mysql_query($sql); echo "Table Deleted"; mysql_close($connection);
  2. Hi guys. I have following code to delete particular row from a table based on the title. But how can I delete all data from the table? <?php require 'connpdo.php'; $naslov = $_POST['naslov']; #DELETE DATA //delete some data $sqlInsert = 'DELETE FROM bloging WHERE title=:title'; $preparedStatement = $conn->prepare($sqlInsert); $preparedStatement->execute(array(':title' => $naslov)); //REDIRECT TO HOME PAGE header('Location: http://localhost/ITAPHP/index.php'); ?> So I would need something which would say DELETE * FROM bloging...Basically I have this table bloging with 3 fields id, title and text, and above code will identify specific post based on the title and delete that particular post. But I need button to delete all posts, to empty table. Thank you in advance!
  3. I have basically 3 divs. Top horizontal for title etc. And two vertical ones. Float left and float right. On the left side I input data in the form and it is shown on the right side. But when there is more posts div doesn't grow to accommodate all posts? header{ position:fixed; top:0px; height:15%; left:0px; right:0px; background-color:#333; color:#FFF; z-index:10; opacity:0.6; } #left{ position:absolute; top:15%; bottom:0px; width:50%; height:100%; left:0px; background-color:#900; color:#FFF; z-index:8; overflow:hidden; clear:both; } #right{ position:absolute; top:15%; bottom:0px; width:50%; height:100%; right:0px; background-color:#999; color:#FFF; z-index:8; overflow:hidden; clear:both; }
  4. Thank you guys! I've got working code now, thanks to you. And it looks like this: <?php require 'DB/dbinc.php'; $oT = $_POST['starinaslov']; $nT = $_POST['novinaslov']; $nTx = $_POST['novitekst']; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $usernm, $dbpass); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 //Update $sql = "UPDATE bloging SET title=:ntitle, tekst=:ntext WHERE title=:oldtitle"; $stmt = $conn->prepare($sql); $stmt->execute(array( ':ntitle' => $nT , ':ntext' => $nTx , ':oldtitle' => $oT )); $conn = null; // Disconnect } catch(PDOException $e) { echo $e->getMessage(); } ?>
  5. Hi guys! I have a slight problem. When I pass values as variables to a sql statement it doesnt work. This is the example: THIS WORKS: <?php require 'DB/dbinc.php'; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $usernm, $dbpass); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 // changes data in "text" and "text" where title = some title $sql = "UPDATE bloging SET title='Novi Title', tekst='Novi tekst' WHERE title='Update post'"; $count = $conn->exec($sql); $conn = null; // Disconnect } catch(PDOException $e) { echo $e->getMessage(); } // If data added ($count not false) displays the number of rows added if($count !== false) echo 'Number of rows added: '. $count; ?> THIS DOES NOT WORK <?php require 'DB/dbinc.php'; $oldTitle = 'Stari naslov'; $nTitle = 'novinaslov'; $nText = 'novitekst'; try { // Connect and create the PDO object $conn = new PDO("mysql:host=$dbhost; dbname=$dbname", $usernm, $dbpass); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 // changes data in "text" and "text" where title = some title $sql = "UPDATE bloging SET title=$nTitle, tekst=$nText WHERE title=$oldTitle"; $count = $conn->exec($sql); $conn = null; // Disconnect } catch(PDOException $e) { echo $e->getMessage(); } // If data added ($count not false) displays the number of rows added if($count !== false) echo 'Number of rows added: '. $count; ?> I don't get it why it wont accept variable instead of string text as a value? Thanx in advance!
×
×
  • 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.