Cant write to this MySQL table

Permabanned
Joined
22 Apr 2007
Posts
1,805
Although my php programming sucks, I think that by now I can write to a database ok as my enquiry and contact form works.

I want to write to this database from another form but it never updates:-

here is the database:

11280051ff5.jpg


Why doesn't this work?
 
OK, yeah,

Here is the php

Code:
<?php
$p_title = $_POST['title'];
$p_menu_title = $_POST['menutitle'];
$p_summary = $_POST['summary'];
$p_body = $_POST['body'];

$address = "localhost";
$username = "mark1e_bourne";
$password = "******";
$database = "mark1e_bourne";

mysql_connect($address,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO news VALUES ('$p_title','$p_menu_title','$p_summary','$p_body')";
print($query);
mysql_query($query);

mysql_close();



?>

And here is the html

Code:
<html>
<body>
<form action="" method="post">
<p>Title - <input type="text" name="title" /></p>
<p>Menu Title - <input type="text" name="menutitle" /></p>
<p>Summary - <input type="text" name="summary" /></p>
<p>Body - <input type="text" name="body" /></p>
<p><input type="submit" name="submit" /></p>

</form>
</body>
</html>

Ta
 
Thanks guys, Markus, your way has worked fine.

Thanks sic too, I know there are tutorials available but its working out how to describe what to search for. I should probably get a book or something.

One other thing I want to do, as you have probably guessed, I am using a mini CMS to update a news page and it works.

I write to the sql database using the form above and another page queries the SQL and displays the results.

However, what I want to do is have a small section of the news with a link. Such as:-

News Flash. News page is updated.....(full story here)

Where the user clicks full story and is taken to the article.

Any ideas?
 
Markus,

When I submit the news form TO the database it enters a blank row into the table as well as the row with the correct data.

Why is this?
 
Cool, thanks.

One other thing. In the part above where you gave me the code for the news preview, I'm trying to alter so that the preview shows the user the p_summary and the (click here for full story) shows them the p_body (which it does already).

The only other two things I'm having trouble with are:

inserting the date above the summary (in dd month yyyy format (i.e. 22 November 2007)
and also making it so that the latest id increment shows on top of the previous news article not below it (if that makes sense).
 
Cool, thanks

When you say "inserting" and "displaying" do you mean altering the code of the input form and the news.php code?

also, quickly (i hope). I want the 'full story' link to appear directly beneath the summary. Is that possible?

Also, how can I get the code to conform to my CSS? as the link formatting of "full story here" is the default HTML link colours.

Thanks again
 
Back
Top Bottom