I can't get any manuipulation of my mysql database online

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
I hope someone out there can help me (being a newbie)
I am writing what is probably quite a simple website using mainly php, I have sorted being able to read all the information from the various databases, but I can't seem to get any form of manipulation to work,
below is a cut down version my manipulation code, has anyone got any ideas?

Code:
<? 
 if ($savecruise) {
 
   $db = mysql_connect("localhost", "root", "homer");
	mysql_select_db("Cruises",$db);
 
 $sql = "UPDATE general SET Cruisenum=$cruisenum,PI=$pi,Institute=$institute,Location=$location, sailingport=$sailingport,completion=$completion, year=$year WHERE general.Cruisenum=$cruisenum";

 $result = mysql_query($sql);

  echo "Cruise Information Updated.\n";

 $cruisepage = $cruisenum;
 };
?>
    <?
 if ($deletebutton) {
 
    $db = mysql_connect("localhost", "root", "homer");

    mysql_select_db("Cruises",$db);
  
    $sql = "DELETE FROM general WHERE Cruisenum=$cruisenum";	

    $result = mysql_query($sql);

    echo "$sql Record deleted!";
 
 };
?>
    <?
  if ($newbutton) {
  
  $db = mysql_connect("localhost", "root", "homer");

  mysql_select_db("Cruises",$db);

  $sql = "INSERT INTO general (Cruisenum,PI,Institute,Location) VALUES ('$cruisenum','$pi','$institute','$location')";

  $result = mysql_query($sql);

  echo "New Cruise Entered\n";
};
?>
Thanks in advance
 
Ummmm I can't use phpmyadmin in its release format, I need to do it in the webpage because there are lots of tables that need to be altered at once, and the users need to be able to modify data rather than the webmaster
 
Mh_0 said:
$db = mysql_connect("localhost", "root", "homer");
mysql_select_db("Cruises",$db);

$sql = "UPDATE general SET Cruisenum=$cruisenum,PI=$pi,Institute=$institute,Location=$location, sailingport=$sailingport,completion=$completion, year=$year WHERE general.Cruisenum=$cruisenum";

$result = mysql_query($sql);

I can't see any major fault in your code here, but a few hints. Take your connection code out of the if branches and put it in the top of your script, and possibly in an include file you can use in multiple pages.
Its important to use quotes, so Institute='$institute' instead of Institute=$institute. The query will fail if you don't.
If these things don't help you'll have to be more specific as to what is actually not working.

!! You can use phpMyAdmin to test your querys against your database !!
 
Its sorted, it was sorted by putting `s around the field names and 's around the variables
 
Back
Top