



Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!




Connected to MySql";
//create DB (if not there) $query="CREATE DATABASE person_db"; if (!mysql_query("$query")) die("Could not create DB: ". mysql_error()); echo "Database created successfully ";
//select DB if(!mysql_select_db("person_db")) die("Could not select DB: ". mysql_error()); echo "person_db DB selected successfully";
//create table $query="CREATE TABLE Persons(Firstname CHAR(30),Lastname CHAR(30),Age INT)"; if (!mysql_query("$query")) die("Could not create DB table: ". mysql_error()); echo "Table Persons created successfully";
mysql_close(); ?>
...
Insert personal data in MySQL database
Firstname: Lastname: Age:
Connected to MySql";
//try to select DB if (!mysql_select_db("person_db")){ //create DB myFun_createDB("person_db"); //funzione contenente il codice dell’esercizio precedente }
$sql="INSERT INTO Persons (FirstName, LastName, Age) VALUES (’$_POST[firstname]’,’$_POST[lastname]’,’$_POST[age]’)"; if (!mysql_query($sql)) die(’Error: ’. mysql_error()); echo "1 record added";
echo "Here is the updated database content:"; $sql="SELECT * FROM Persons"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ echo $row[’Firstname’]. " ". $row[’Lastname’]." ".$row[’Age’].""; } mysql_close(); ?>
echo "No"; echo ""; } echo ""; mysql_close($con); ?> /body> /html>
Si";} else echo "Si";} if($row[’Dispon’]=="NO") echo "No"; else echo "No"; echo ""; ... ?>
";
foreach($POST as $date => $si_no){ $date=str_replace(""," ",$date); //elimina il carattere _ if($si_no=="SI"){ echo"In data ".$date." sei libero"; }else{ echo"In data ".$date." non sei libero"; } }
//aggiorna il Db $con = mysql_connect("localhost","root"); if (!$con) die("Could not connect: ". mysql_error());
//Select DB if (!mysql_select_db("Date_db", $con)) die("Could not select DB: ". mysql_error());
foreach($POST as $date => $si_no){ $date=str_replace(""," ",$date); //elimina il carattere _ $sql="UPDATE MieDate SET Disponibilita=’$si_no’ WHERE Data=’$date’"; if (!mysql_query($sql)) echo "Cannot update availability for date ".$date.""; }
mysql_close($con); ?>