|
Posted by Christo on 11/15/06 01:06
I discovered that if i enter the id manually then it works, I do have
this field setup as auto inc and as PK and as not null, shouldn't this
field automatically assign its self a value of the next auto inc number
without mee having to input the id raw in the php code?
I would appreciate some help here as this has been an aim of mine for
some time to get mysql qworking and I am so so close.
TIA
Chris
PS - sorry if it appears as top posting, they look nicer on google
groups that way
thanks again
Chris
Christo wrote:
> OK.
>
> I have a mysql database and i have it displaying whats currently there
> using php, the problem is that I cannot insert into the database
> correctly. please check my code below
>
> <?php
> $username = "root";
> $password = "************"; //edited
> $server = "localhost";
> $dbname = "dbname";
>
> $title = $_POST["title"];
> $news = $_POST["news"];
> $id = $_POST["id"];
> $date = "2006-15-11 00:15:15";
>
> $dbc = mysql_connect($server, $username, $password) or die ("ERROR");
> $select = mysql_select_db($dbname, $dbc) or die("couldn't connect to
> dbname");
>
> $sqlquery = "INSERT INTO tnews VALUES('$id','$title','$news','$date')";
>
> //print "<html><body><center>";
> //print "<p>You have just entered this record<p>";
> //print "Title : $title<br><hr>";
> //print "$news<br>$date";
> //print "</body></html>";
>
> print $sqlquery;
> $results = mysql_query($sqlquery);
>
> mysql_close($dbc);
>
> ?>
>
> this submits the info from a form, the code for the form is below:
>
> <form method="post" action="add.php">
> Title: <input name="title" type="text" value="">
> <input type="hidden" name="id" />
> <br>
> News: <input name="news" type="text" value="">
> <br>
> <br>
> <input type="submit" name="submit" value="Submit">
> </form>
>
> I can see the insert query fine and it appears to be working however
> the data isnt being put in the database. I am hosting php on my home
> computer and it is being used with apache I am also hosting mysql on my
> own computer and am using SQLyog and the GUI toold from mysql to
> administer the db, I am a novice so please go easy but can anyone see a
> reason why i cant get this data to appear in my database table?
>
> Please please help me!!
Navigation:
[Reply to this message]
|