Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. the above mentioned method is good, but not when you are going to work with databases, therefor i suggest you use the following code: [code] <?php if (isset($tmp)) { unset($tmp); $type='odd'; } else { $tmp = 1; $type='even'; } ?> [/code] this is a very messy code, but it really gets the job done! if anyone knows a better way of doing this, then please share it with us!
  2. i have been working with asp, and now am i trying to do something what i thought was possible! [code] <img src="image.php?f=an_image.gif" width="105" height="105" /> <!-- however when i load the page no image is being displayed, does anyone know what i did wrong? or what i am forgetting? --> [/code] thx in advance, i'm still looking into the problem so it might be that i'll find it in my next google search, but i appreciate any help :D
  3. this should do the trick, however put it high enough [code]<?php $offset = ''; ?>[/code]
  4. first of all your gonna need an ASCII Table to understand this, www.google.com/search?q=ascii+table [code] <?php $Key = $_REQUEST['key']; if (!$Key) {   $ASCII= 65; # uppercase (+32 for lowercase)   $i = 1;   while ($i < 27) {     $Char = chr($ASCII);     echo("<a href='?key=$Char'>$Char</a>");     $i++;     $ASCII++;   } } else {   $SQL = sprintf("SELECT `bla` FROM `blaTable` WHERE `bla` LIKE `%s*`", $Key);   # pass $SQL to the database } ?> [/code]
  5. yeah normally with $_SESSION[Data] you will be referring to a defined constant named Data therefor always use single- or double quotes
  6. First of all before posting make sure your text is between the code tags so the syntax is colored, second of all add some whitespace for readability... thx ;) ;D [code] <?php echo "<form name='attendance' action='{$_SERVER[PHP_SELF]}' method='POST'>"; echo "<input type='submit' value='Submit Changes'>"; $i=0; echo '<table>'; while ($row=mysql_fetch_row($result1)) {  $IDstudent=$row[0];  $name = $row[1];  $status = $row[2];    echo "  <tr>    <td>      <input name='studentid[{$i}]' type='hidden' value='{$IDstudent}'>    </td>    <td>      {$name}    </td>    <td>      {$status}    </td>    <td>      <input name='status[{$i}]' type='radio' value='P'" . (strtolower($status) == 'p') ? "checked='checked'" : ''"> Present    </td>    <td>      <input name='status[{$i}]' type='radio' value='T'" . (strtolower($status) == 't') ? "checked='checked'" : ''"> Tardy    </td>    <td>      <input name='status[{$i}]' type='radio' value='U'" . (strtolower($status) == 'u') ? "checked='checked'" : ''"> Unexcused Absence    </td>    <td>      <input name='status[{$i}]' type='radio' value='E'" . (strtolower($status) == 'e') ? "checked='checked'" : ''"> Excused Absence    </td>  </tr>'"; $i++; } echo "</table>"; ?> [/code]
  7. without javascript , your form will never automatically submit , php is a server-side language it resolves everything on the server not on the client , so when you fill in your form , php won't have a clue what is going on.
  8. [code] <?php // Declare the class 'Dbase' class Dbase { function Dbase(){ // Class constructor include ("connection.php"); // strange place to include a file $this->dbLink=$dbLink; // this adds the $dbLink to the class property dbLink } function select($retField, $table, $where="", $groupby="", $orderby="", $limit="") { $fields = implode(",", $retField); if ($where!="") { $q = sprintf("select %s from %s WHERE %s", $fields, $table, $where); // makes it a bit more secure } else { $q = sprintf("select %s from %s", $fields, $table); } if ($groupby!="") { $q .= sprintf(" GROUP BY %s", $groupby); // adds a group by to the current query (put duplicates together) } if ($orderby!="") { $q .= sprintf(" ORDER BY %s", $orderby); // adds a order by to the current query (orders the result by $orderby) } if ($limit!="") { $q .= sprintf(" LIMIT %s", $limit); // limits the result to a certain number } //return $q; //if($orderby == 'ts_datAdded DESC'){ // echo $q."<br><br>";exit;} $this->sql = $q; // adds the query to the class property sql $this->log(); // executes class method log(); , however this method is not in the current class $r = mysql_query($q); // sends the current sql syntax to the database for execution , however why do you use $q while you assigned it to $this->sql ?? if (!($r)) { // checks if mysql_query(); was executed succesfully , if (!($r = mysql_query($q)) , however i also would assign $r to a class property $this->error_log(); // executes the class method error_log(); } $num=mysql_num_rows($r); // counts the total rows returned $i=1; while ($row=mysql_fetch_object($r)) { // why do you fetch it as an object when you assign it to an array ? $cont[$i] = $row; $i++; } if (mysql_num_rows($r)>0) { // double work , use your declared/initialised $num instead , if ($num > 0) ... // echo print_r($cont); // exit; return $cont; } } } ?> [/code]
  9. k, thx, now something else, overloading is this done in the same way as in c++? string doMyHomework(string Input); string doMyHomework(double Input); however i can not define the return type or the argument type function doMyHomework($Input); function doMyHomework($Input); // cannot redeclare function 'doMyHomework' so how do i overload a php function?
  10. what you are looking at is a captcha method, google it, for more information on the subject
  11. try captcha, however you will need the "GD Library"
  12. thx for the information, @barand so an interface is much like the prototypes that you can define in c++? but now you use a child class to implement them instead of adding them after [ int main(); ]
  13. Hey after some googling and reading, have i come to a certain page in my life, that i got stuck! I'm a huge fan of normalisation (it makes atleast my life a bit easier) so now am i trying to do this also on some oop (object oriented programming - for those who do not know what i mean) So if interface, implements, extends, etc... is no foreign language for you, then please feel free to be so kind and enlight my mind... xD Thanx in advance, Ignace
  14. first i suggest you start using "proper" coding (saved me always from strange bugs, errors, etc...) for your page that sends data [code] <?php if ($_GET['done'] == "1") { ... } ?> [/code] for your page that receives it! [code] <?php // For readability have i added some newlines here $Sql = sprintf( "INSERT INTO `beer` (`beer_style`, `beer_status`, `beer_taste1`, `beer_taste2`, `beer_taste3`, `beer_brygdag`, `beer_coment`) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s')", $_POST['type'], $_POST['status'], $POST['samg1'], $POST['smag2'], $POST['smag3'], $POST['dato'], $POST['komentar'] ); if (mysql_query($Sql)) {    // We don't wanna have error's like "headers already sent..." therefor this does the job as well!    echo "<script>window.location.href='addbeer.php?done=1';</script>"; } else {   echo mysql_error();// TODO: i know that the db_resource is optional, however i should consider providing this anyhow! } ?> [/code]
  15. it seems that your search.php file is missing inside your missing search directory
  16. http://www.phpfreaks.com/forums/index.php/topic,103143.0.html <-- don't know if this is gonna help you, but it's worth checking out the manual on php.net http://nl2.php.net/manual/en/features.commandline.php, check if this gives you any answers P.S.: sdaniels as in steven daniels? from sint-truiden? because if so, you will probably know me ;D
  17. http://www.phpfreaks.com/forums/index.php/topic,103212.0.html you probably are gonna have to adjust the code, because this one is ment to be used for a guestbook, but it has the same cause! [code] <?php $PreCheckComplete=0; if ($_POST['submit']) {    $Error='';    $Name = $_POST['name'];    if (!$Name) $Error .= "&bull; Name is a required field.<br>";    if (strip_tags($Name) != $Name) $Error .= "&bull; You are not allowed to use html in your name.<br>";    if (strlen($Name) < 3) $Error .= "&bull; Your name must atleast contain 3 characters.<br>";    $Email = $_POST['email'];    // TODO: perform an regex on email when provided.    if ($Email) {       if (strip_tags($Email) != $Email) $Error .= "&bull; You are not allowed to use html in your e-mail.<br>";    }        $Website = $_POST['website'];    // TODO: perform an regex on website when provided.    if ($Website) {       if (strip_tags($Website) != $Website) $Error .= "&bull; You are not allowed to use html in your website address.<br>";    }    $Comment = $_POST['comment'];    if (!$Comment) $Error .= "&bull; Comment is a required field.<br>";    if (strip_tags($Comment) != $Comment) $Error .= "&bull; You are not allowed to use html in your comment.<br>";    if (strlen($Comment) < 10) $Error .= "&bull; Please make sure your comment atleast contain 10 characters.<br>";    if ($Error) {       echo "<div class='Error'>$Error</div>";    } else {       $PreCheckComplete=1;       $Error = '';       $Entry = "<div class='userdetails'>Name: " . $Name;       if ($Email) $Entry .= "<br>e-Mail: <a href='mailto:" . $Email . "'>".$Email."</a>";       $Entry .= "</div>";       if ($Website) $Entry .= "<a href='http://".str_replace('http://', '', $Website)."'>$Website</a>";       $Entry .= "<div class='comment'>$Comment</div>";       $Source = "messageview.html";       if (!($Resource = fopen($Source, "a"))) {// a because we always want to add data on the last line..          $Error .= "WARNING: Could not open file.<br>";       }       if (!flock($Resource, LOCK_EX)) {          $Error .= "WARNING: Could not lock file.<br>";       }       if (!fwrite($Resource, $Entry)) {          $Error .= "WARNING: Could not write to file.<br>";       }       if (!flock($Resource, LOCK_UN)) {          $Error .= "WARNING: Could not unlock the file.<br>";       }       if (!fclose($Resource)) {          $Error .= "WARNING: Could not close file.<br>";       }       if ($Error) {          echo "<div class='Error'>$Error</div>";       }    } } if ($PreCheckComplete==0) {//Display the form. ?> <form action="" method="post"> <h3>All fields marked with * are mandatory.</h3> <table width="100%" cellpadding="0" cellspacing="0"> <tr><td>* Name:</td><td><input type="text" name="username" value="<?php echo @$_POST['username'] ? $_POST['username'] : '';?>"></td></tr> <tr><td>E-mail:</td><td><input type="text" name="email" value="<?php echo @$_POST['email'] ? $_POST['email'] : '';?>"></td></tr> <tr><td>website:</td><td><input type="text" name="website" value="<?php echo @$_POST['website'] ? $_POST['website'] : '';?>"></td></tr> <tr><td>*comment:</td><td><textarea style="width:100%" rows="15" name="comment"><?php echo @$_POST['comment'] ? $_POST['comment'] : '';?></textarea></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="add to guestbook"></td></tr> </table> </form> <?php } ?> [/code]
  18. they probably are going to merge this... however i'm only here to help you (again) ;D [code] <?php $PreCheckComplete=0; if ($_POST['submit']) {   $Error='';   $Name = $_POST['name'];   if (!$Name) $Error .= "&bull; Name is a required field.<br>";   if (strip_tags($Name) != $Name) $Error .= "&bull; You are not allowed to use html in your name.<br>";   if (strlen($Name) < 3) $Error .= "&bull; Your name must atleast contain 3 characters.<br>";   $Email = $_POST['email'];   // TODO: perform an regex on email when provided.   if ($Email) {      if (strip_tags($Email) != $Email) $Error .= "&bull; You are not allowed to use html in your e-mail.<br>";   }     $Website = $_POST['website'];   // TODO: perform an regex on website when provided.   if ($Website) {      if (strip_tags($Website) != $Website) $Error .= "&bull; You are not allowed to use html in your website address.<br>";   }   $Comment = $_POST['comment'];   if (!$Comment) $Error .= "&bull; Comment is a required field.<br>";   if (strip_tags($Comment) != $Comment) $Error .= "&bull; You are not allowed to use html in your comment.<br>";   if (strlen($Comment) < 10) $Error .= "&bull; Please make sure your comment atleast contain 10 characters.<br>";   if ($Error) {      echo "<div class='Error'>$Error</div>";   } else {       $PreCheckComplete=1;      $Error = '';      $Entry = "<div class='userdetails'>Name: " . $Name;      if ($Email) $Entry .= "<br>e-Mail: <a href='mailto:" . $Email . "'>".$Email."</a>";      $Entry .= "</div>";      if ($Website) $Entry .= "<a href='http://".str_replace('http://', '', $Website)."'>$Website</a>";      $Entry .= "<div class='comment'>$Comment</div>";      $Source = "messageview.html";      if (!($Resource = fopen($Source, "a"))) {// a because we always want to add data on the last line..         $Error .= "WARNING: Could not open file.<br>";      }      if (!flock($Resource, LOCK_EX)) {         $Error .= "WARNING: Could not lock file.<br>";      }      if (!fwrite($Resource, $Entry)) {         $Error .= "WARNING: Could not write to file.<br>";      }      if (!flock($Resource, LOCK_UN)) {         $Error .= "WARNING: Could not unlock the file.<br>";      }      if (!fclose($Resource)) {         $Error .= "WARNING: Could not close file.<br>";      }      if ($Error) {         echo "<div class='Error'>$Error</div>";      }   } } if ($PreCheckComplete==0) {//Display the form. ?> <form action="" method="post"> <h3>All fields marked with * are mandatory.</h3> <table width="100%" cellpadding="0" cellspacing="0"> <tr><td>* Name:</td><td><input type="text" name="username" value="<?php echo @$_POST['username'] ? $_POST['username'] : '';?>"></td></tr> <tr><td>E-mail:</td><td><input type="text" name="email" value="<?php echo @$_POST['email'] ? $_POST['email'] : '';?>"></td></tr> <tr><td>website:</td><td><input type="text" name="website" value="<?php echo @$_POST['website'] ? $_POST['website'] : '';?>"></td></tr> <tr><td>*comment:</td><td><textarea style="width:100%" rows="15" name="comment"><?php echo @$_POST['comment'] ? $_POST['comment'] : '';?></textarea></td></tr> <tr><td colspan="2"><input type="submit" name="submit" value="add to guestbook"></td></tr> </table> </form> <?php } ?> [/code]
  19. if you do this [code] if ($_POST) {   $msg = "";   foreach($_POST as $k => $v) {         $v = trim($v);         ${$k} = $v;// to create a variable from a variable you'll need the { and } around it, as of php5 i guess, it worked when i still got php4         if ($v=="") {           $msg = "Please fill in all fields";         }   } [/code] then you don't have to do this: [code] $phc = isSet($_POST['phc']) ? $_POST['phc'] : ''; $cd1 = isSet($_POST['cd1']) ? $_POST['cd1'] : ''; $cf1 = isSet($_POST['cf1']) ? $_POST['cf1'] : ''; $ct1 = isSet($_POST['ct1']) ? $_POST['ct1'] : ''; $crc1 = isSet($_POST['crc1']) ? $_POST['crc1'] : ''; $ncb1 = isSet($_POST['ncb1']) ? $_POST['ncb1'] : ''; $cd2 = isSet($_POST['cd2']) ? $_POST['cd2'] : ''; $cf2 = isSet($_POST['cf2']) ? $_POST['cf2'] : ''; $ct2 = isSet($_POST['ct2']) ? $_POST['ct2'] : ''; $crc2 = isSet($_POST['crc2']) ? $_POST['crc2'] : ''; $ncb2 = isSet($_POST['ncb2']) ? $_POST['ncb2'] : ''; [/code]
  20. i like your sense of humor ;D however what do you want to be substracted? [code] <?php if (isset($_POST['submit'])) { function cleanUp($input) {   return htmlspecialchars(strip_tags(stripslashes(trim($input))));// well no-one ever gets passed this :D } $shop_title = cleanUp($_POST['shop_name']); $shop_front = $_POST['shop_front']; $shop_front = str_replace("<", "[", $shop_front); $shop_front = str_replace(">", "]", $shop_front); $shop_desc = cleanUp($_POST['shop_desc']); $shop_desc = nl2br($shop_desc); $shop_size = cleanUp($_POST['shop_size']); $shop_location = cleanUP($_POST['shop_location']); $timestamp = strtotime("now"); $username = $logged['username']; if ( (empty($shop_title)) || (empty($shop_desc)) || (empty($shop_size)) || (empty($shop_location))) { include($_SERVER['DOCUMENT_ROOT']."/connect.php"); $sql2 = "SELECT * FROM shops WHERE owner = '" . $logged[username] . "'"; $result2 = mysql_query($sql2) or print ("Can't select table.<p>" . mysql_query() . "</p>"); $number = mysql_num_rows($result2); if ($number != 1) { include($_SERVER['DOCUMENT_ROOT'] . "/connect.php"); $sql = "INSERT INTO shops (timestamp, owner, shop_name, shop_desc, shop_front, shop_size, Shop_location) VALUES ('$timestamp','$username','$shop_title','$shop_desc','$shop_front','$shop_size','$shop_location')"; $result = mysql_query( $sql ) or die ( mysql_error());//exit, can also be used $id = mysql_insert_id(); $shop_size2 = $_POST['shop_size']; if ($shop_size2 == "4") { $price = "50"; } else if ($shop_size2 == "8") { $price = "100"; } else if ($shop_size2 == "12") { $price = "200"; } else if ($shop_size2 == "16") { $price = "300"; } else if ($shop_size2 == "20") { $price = "400"; } else if ($shop_size2 == "60") { $price = "600"; } include($_SERVER['DOCUMENT_ROOT']."/connect.php"); $sql4 = "SELECT * FROM users WHERE username = '" . $logged[username] . "'"; $result4 = mysql_query($sql4) or die ("Can't select table.<p>" . mysql_query() . "</p>");// use exit or die, print won't stop the script.. while($row4 = mysql_fetch_array($result4)) { $points = $row4['points']; } $equation = ($points - $price); include($_SERVER['DOCUMENT_ROOT'] . "/connect.php"); $sql5 = "UPDATE users SET points='$equation' WHERE username='" . $logged[username] . "' LIMIT 1";// you could also just use $sql again, therefore they are called variables :P $result5 = mysql_query($sql5) or die (mysql_error());// same here, use $result instead of always incrementing if ($result5 != false) { echo "<span style=\"color: green;\">Success!  Your shop has been successfully created!It is located at <p><a href=\"shop.php?id=$id\">$address/shop.php?id=$id</a></span>"; } } else { echo "<span style=\"color: red;\">You Have already created a shop!</span>"; } } else { echo "<span style=\"color: red;\">You must fill in all the required fields.</span>"; } } ?> [/code]
  21. [code] <table border="1" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Symbol</font></th> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Time</font></th> <th><font face="Arial, Helvetica, sans-serif">Date</font></th> <th><font face="Arial, Helvetica, sans-serif">Last</font></th> <th><font face="Arial, Helvetica, sans-serif">Change</font></th> <th><font face="Arial, Helvetica, sans-serif">High</font></th> <th><font face="Arial, Helvetica, sans-serif">Low</font></th> </tr> <?php include("login.php"); mysql_connect("localhost",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM stocks"; $result=mysql_query($query); $i=0; while ($row = mysql_fetch_array($result)) { $quote = $row['symbol']; $standard = ".hk"; $findquote = "$quote$standard"; Class yahoo { function get_stock_quote($symbol) { $url = sprintf("http://finance.yahoo.com/d/quotes.csv?s=%s&f=snl1d1t1c1ohgv" ,$symbol); $fp = fopen($url, "r"); if(!$fp) { echo "error : cannot recieve stock quote information"; } else { $array = fgetcsv($fp , 4096 , ', '); fclose($fp); $this->symbol = $array[0]; $this->name = $array[1]; $this->last = $array[2]; $this->date = $array[3]; $this->time = $array[4]; $this->change = $array[5]; $this->open = $array[6]; $this->high = $array[7]; $this->low = $array[8]; $this->volume = $array[9]; } } } $quote = new yahoo; $quote->get_stock_quote("$findquote"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->symbol"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->name"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->time"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->date"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->last"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->change"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->high"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$quote->low"; ?></font></td> </tr> <? ++$i; } ?> </table> [/code]
  22. this now should work, fixed localhost to "localhost" removed the mysql_numrows() function, misspelled must be mysql_num_rows() changed the loop from while($i < $num) to while ($row = mysql_fetch_array($result)) removed mysql_result(); changed all variables inside the while loop fixed some unneccessary typing echo $name; echo $surname; mysql_close() now executes before php is closed instead of behind the mysql_num_rows() function [code] <?PHP include("login.php"); mysql_connect("localhost",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM people"; $result=mysql_query($query); echo "<b><center>2005-2006</center></b><br><br>"; ?> <table border="1" cellspacing="2" cellpadding="2"> <tr> <th><font face="Arial, Helvetica, sans-serif">Name</font></th> <th><font face="Arial, Helvetica, sans-serif">Nickname</font></th> <th><font face="Arial, Helvetica, sans-serif">Class</font></th> <th><font face="Arial, Helvetica, sans-serif">E-Mail</font></th> </tr> <?PHP $i=0; while ($row = mysql_fetch_array($result)) {    $surname=$row['surname'];    $name=$row['name'];    $nickname=$row['nickname'];    $class=$row['class'];    $email=$row['e_mail']; ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><? echo "$name" . " $surname"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$nickname"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><? echo "$class"; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo "$email"; ?>"><? echo "$email"; ?></a></font></td> </tr> <? ++$i; } echo "</table>"; mysql_close(); ?> [/code]
  23. what wildteen88 said + try the following code [code] <?php if (!@$_GET['title']) {    // if the following line returns error's then comment the line, and uncomment the second   header('Location: ' . $_SERVER['PHP_SELF'] . '?title=note1');    //echo "<script>window.location.href='" . $_SERVER['PHP_SELF'] . "?title=note1';</script>"; } include('note.php'); //now the get/post variable should be available in your note.php file // note.php echo $_GET['title']; ?> [/code]
  24. euhm.. are those your original username and password if it is, you might wanna change this... change this [code]ftp_fput($connection, $bandle, $file, FTP_ASCII);[/code] to [code]ftp_fput($connection, $tempfile, $file, FTP_ASCII);[/code] the second parameter needs to be an string not an resource i.e.: $bandle = fopen('$tempfile', 'w'); <-- resource
  25. Now, what you originally requested.. first of all mysqli can be used like you have always used mysql or in oop style [b]"Normal" mode:[/b] [code] <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world");   /* check connection */ if (mysqli_connect_errno()) {   printf("Connect failed: %s\n", mysqli_connect_error());   exit(); }   mysqli_query($link, "CREATE TABLE myCity LIKE City"); /* Prepare an insert statement */ $query = "INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)"; $stmt = mysqli_prepare($link, $query); mysqli_stmt_bind_param($stmt, "sss", $val1, $val2, $val3); $val1 = 'Stuttgart'; $val2 = 'DEU'; $val3 = 'Baden-Wuerttemberg';   /* Execute the statement */ mysqli_stmt_execute($stmt); $val1 = 'Bordeaux'; $val2 = 'FRA'; $val3 = 'Aquitaine';   /* Execute the statement */ mysqli_stmt_execute($stmt); /* close statement */ mysqli_stmt_close($stmt); /* retrieve all rows from myCity */ $query = "SELECT Name, CountryCode, District FROM myCity"; if ($result = mysqli_query($link, $query)) {   while ($row = mysqli_fetch_row($result)) {       printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);   }   /* free result set */   mysqli_free_result($result); } /* remove table */ mysqli_query($link, "DROP TABLE myCity"); /* close connection */    mysqli_close($link); ?> [/code] [b]Using Object Oriented Style[/b] [code] <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world");   /* check connection */ if (mysqli_connect_errno()) {   printf("Connect failed: %s\n", mysqli_connect_error());   exit(); }   $mysqli->query("CREATE TABLE myCity LIKE City"); /* Prepare an insert statement */ $query = "INSERT INTO myCity (Name, CountryCode, District) VALUES (?,?,?)"; $stmt = $mysqli->prepare($query); $stmt->bind_param("sss", $val1, $val2, $val3); $val1 = 'Stuttgart'; $val2 = 'DEU'; $val3 = 'Baden-Wuerttemberg';   /* Execute the statement */ $stmt->execute(); $val1 = 'Bordeaux'; $val2 = 'FRA'; $val3 = 'Aquitaine';   /* Execute the statement */ $stmt->execute(); /* close statement */ $stmt->close(); /* retrieve all rows from myCity */ $query = "SELECT Name, CountryCode, District FROM myCity"; if ($result = $mysqli->query($query)) {   while ($row = $result->fetch_row()) {       printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);   }   /* free result set */   $result->close(); } /* remove table */ $mysqli->query("DROP TABLE myCity"); /* close connection */    $mysqli->close(); ?> [/code] if there is something you don't understand, then i'll probably will be hearing from you...
×
×
  • 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.