Jump to content

chris93

New Members
  • Posts

    3
  • Joined

  • Last visited

chris93's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. <b></b>i have written a code that connects to a database using Xampp in php... but it does not sort the database at all. <?php //Step1 $db = mysqli_connect('localhost','root','123','first_db') or die('Error connecting to MySQL server.'); ?> <html> <head> </head> <body> <h1>PHP connect to MySQL</h1> <?php $sql ="INSERT INTO users (id,name,password) VALUES ('7','chris','444')"; mysqli_query($db,$sql); $sql = "SELECT * FROM users ORDER BY id 'ASC'"; $query = mysqli_query($db, $sql); //Step2 $query = "SELECT * FROM users"; mysqli_query($db, $query) or die('Error querying database.'); //Step3 $result = mysqli_query($db, $query); //$row = mysqli_fetch_array($result); while ($row = mysqli_fetch_array($result)) { echo $row[0] . ' ' . $row[1] . ': '. $row[2] .'<br />'; } //Step 4 mysqli_close($db); ?> </body> </html>
  2. im trying to connect to database with mysql . when i run the code im getting Parse error: syntax error, unexpected end of file in C:\xampp2\htdocs\tutorials\ab1.php on line 22 <?php $username = 'root'; $pass = 'fireman9'; $db = 'testdb'; $link = mysql_connect('localhost',$username,$pass); mysql_select_db("testdb",$con); if(!link){ echo "Not Connected to DB" . mysqli_connect_error(); $result = mysql_query($link, "SELECT * FROM test"); while($row = mysql_fetch_array($result)){ echo "ID: " . $row['id']; echo "Name: " . $row['name33']; } ?>
  3. hi guys , I`m trying to create a table called table with php , this is my code when i run the code im getting Parse error: syntax error, unexpected 'mysql_query' (T_STRING) in C:\xampp2\htdocs\tutorials\abc.php on line 16 <?php $user = 'root' ; $pass = 'fireman9' ; $db = 'testdb' ; $con = new mysqli('localhost', $user , $pass , $db) or die("UNABLE TO CONNECT"); $selected = mysql_select_db($db,con) mysql_query(" CREATE TABLE people ( firstname varchar(15) gender varchar() )"); ?>
×
×
  • 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.