Link to home
Start Free TrialLog in
Avatar of PoRL
PoRL

asked on

Adding database entries with PHP and mSQL

(Note: This is mSQL, rather than MySQL)..


I am getting SOOOOoooo depressed about this, it's not true!!!

All I want to do is to add an entry to a table with data entered into a form. The exact coding is below, but what happenes is that the "Submit" button is recognised (i.e. the "Data entered.." line comes up), but nothing is actually added to the table.

Please, please, please can somebody help???

Anyway, here's the exact code I'm trying to use..

<form>
<table border=0>
<tr>
<td>Country:</td>
<td><input type=text name=country size=20></td>
</tr>
<tr>
<td>Port:</td>
<td><input type=text name=port size=20></td>
</tr>
<tr>
<td>Country ID:</td>
<td><input type=text name=country_id size=20></td>
</tr>
<tr>
<td align=center><input type=submit name="submit" value="Add destination"></td>
<td align=center><input type=reset value="Cancel"></td>
</tr>
</table>
</form>
</center>

<?php
if ($submit=="Add destination") {

msql_connect ("");


$sql="INSERT INTO countries VALUES ($country,$port,$country_id)";

$result=msql ("1sitetest",$sql);

echo "Information added. Refresh this page to update table above\n";
}
?>


</form>
ASKER CERTIFIED SOLUTION
Avatar of sereda
sereda

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good comment from sereda :-)

My addition - I'd rewrite your database code in the following way:
Note die() calls, $db connection identifier, 's in $sql statement.

<?php
 if ($submit=="Add destination") {

   // Get link identifier
   $db = msql_connect () or die("Unable to connect to database");

    $sql="INSERT INTO countries VALUES ('$country','$port','$country_id')";

   // Use link identifier in request  
   msql ($db, $sql) or die ("Error inserting data to database. Query: $sql");

    echo "Information added. Refresh this page to update table above\n";
}
?>
Avatar of PoRL
PoRL

ASKER

Hmmmm... I thought I'd accepted this answer earlier on!?!

Basically, just after I posted the original question, I got a phone call out of the blue from an old friend in South Africa, and he guided me to where I wanted to be.

I felt the point about the Submit button was worth all the points, though!!!

Thanks for the help...

Paul