Forum Moderators: coopster
//add records
$sql = "INSERT INTO users (`email`, `name`, `country`) VALUES ('john@gmail.com', 'john', 'non')";
if (!$sql){
dir ("Unable to create the record:" . mysql_error());
exit;
}
question : The above code is not creating the specified record.
currently i have 2 records already in globle_users db.
bought added manually using myphpadmin.
here is the complete code.
<?php
$link = mysql_connect('localhost', 'globe_sql', '123456');
if (!$link) {
die('Could not connect to mysql server: ' . mysql_error());
}
echo "Connected to mysql successfully.<br>". "\n";
//select db
mysql_select_db ("globe_users") or die ("But could not select the specified db!<br>");
//print data
// Select all rows in the users table
$query = "SELECT * FROM users";
$result = mysql_query($query);
if (!$result) {
die ("Query made to table named users was un-successfull");
}
print "Query made to the users table was successfull<br>" . "\n";
$x = 0;
//preparing the table
print "<table>";
print "<tr><th>Email</th><th>Name</th></tr>";
print "<tr><th>-----</th><th>----</th><tr>";
//looping to print rows
while ($x < mysql_numrows($result)): //$result is returned by mysql_query
$mail=mysql_result($result, $x, 'email');
$name=mysql_result($result, $x, 'name');
print"<tr>";
print"<td>$mail</td><td>$name</td>";
print"</tr>";
$x++;
endwhile;
print"</table>";
//add records
$sql = "INSERT INTO users (`email`, `name`, `country`) VALUES ('john@gmail.com', 'john', 'non')";
if (!$sql){
dir ("Unable to create the record:" . mysql_error());
exit;
}
mysql_close($link);
?>