Jump to content

PH fuckin P!


peasepud
 Share

Recommended Posts

Im stuck :D

 

just started to try and teach meself this thing for the website so I thought Id have a go at a ridiculously easy calendar thing but no matter what I do or how much I google I cant suss whats up.

 

Heres what I have so far:

 

A MySQL database called peasepu_whowhere which contains 1 table called items which in turn has 4 fields called who, when, loc & killby

 

 

A file called testphp.php which is

 

 <html>
<head><title>Get data</title></head>
<body>
<?php
$dbh=mysql_connect ("localhost",myusername,mypassword) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("peasepu_whowhere");
?>

<form action="insert.php" method="post">
Who: <input type="text" name="person"><br>
Where: <input type="text" name="place"><br>
When: <input type="text" name="datethere"><br>
Kill date: <input type="text" name="leavetill"><br>
<input type="Submit">
</form>
</body>
</html>

 

I know the connection is working because if I change the myusername slightly I get a cant connect error.

 

 

and then insert.php containing :

 

 <html>
<head><title>Insert a record</title></head>
<body>
<?php
$per=$_POST['person'];
$place=$_POST['place'];
$datethere=$_POST['datethere'];
$leavetill=$_POST['leavetill'];

$sql = "INSERT INTO `items` (`who`, `when`, `loc`, `killby`) VALUES ($per, $place,$datethere, $leavetill )";
mysql_query($sql);
?>

</body>
</html>

 

I dont get any error messages or anything strange, just nothing happens, no records are added to the table.

Link to comment
Share on other sites

"INSERT INTO items (who, when, loc, killby) VALUES ('$per','$place','$datethere','$leavetill')"

 

Everything else looks perfect. The only other thing I'd try would be putting the 'or die' statement on the second page again and then replacing the variables with static values just to rule out a problem there.

Link to comment
Share on other sites

Try this:

 

$sql = "INSERT INTO `items` (who, when, loc, killby) 
  VALUES ($per, $place,$datethere, $leavetill )";
if ( !($result = $db->mysql_query($sql)) )
{
  die('Could not insert data into items table. SQL statement: ' . $sql);
}

Link to comment
Share on other sites

Try this:

 

$sql = "INSERT INTO `items` (who, when, loc, killby) 
  VALUES ($per, $place,$datethere, $leavetill )";
if ( !($result = $db->mysql_query($sql)) )
{
  die('Could not insert data into items table. SQL statement: ' . $sql);
}

53374[/snapback]

 

Nope, although at least I now get an error message:

 

Fatal error: Call to a member function on a non-object in /home/peasepu/........../insert.php on line 13

Link to comment
Share on other sites

Howsabout this:

 

$sql = "INSERT INTO `items` (who, when, loc, killby) VALUES ($per, $place, $datethere, $leavetill)";
if ( !($result = mysql_query($sql)) )
{
  $message  = 'Invalid query: ' . mysql_error() . "\n";
  $message .= 'Whole query: ' . $sql;
  die($message);
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • 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.