PDA

View Full Version : Inserting


Psybadek
06-10-03, 07:53 PM
Ok, Im having trouble inserting.

Heres the form page..


if ($s == 'addnews'){

include 'config.php';
include 'global.php';
?>
<head>
<style type='text/css'>
/* Main styles for 3B */

body {
scrollbar-face-color: #7f8e9b;
scrollbar-shadow-color: #eeeeee;
scrollbar-highlight-color: #eeeeee;
scrollbar-3dlight-color: #000000;
scrollbar-darkshadow-color: #000000
scrollbar-arrow-color: #000000
}

/* Main styles everything else inheirts from these */
body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px }
tr, td, table { font-family: Verdana, Arial, Helvetica, sans-serif }

/* Header Styles */




.headermain { font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000; font-size: 10px; background-color: #336699; }
.headermain2 { font-family: Verdana, Arial, Helvetica, sans-serif; color: #000000; font-size: 10px; background-color: #eeeeee; }
.headermain3 { font-family: Verdana, Arial, Helvetica, sans-serif; color: #ffffff; font-size: 10px; background-color: #336699; }
</style>
</head>
<?
include 'nav.php';
?>
<td width="60%">
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
<tr>
<td class="headermain3" width="100%">
<b>Add News
</td>
</tr>
<tr>
<form action="admincp.php?s=newssubmit1" method="post">
<td class="headermain2" width="100%">
<?
$news = mysql_query("SELECT * FROM al_news");
while ($row = mysql_fetch_array($news)) {
$id = $row['id'];
$subject = $row['subject'];
$author = $row['author'];
$content = $row['content'];
$source = $row['source'];
}
?>
Name: <input type=text name="name"><br>
Subject: <input type=text name="subject"><br>
Author: <input type=text name="author"><br>
Source: <input type=text name="source"><br>
Date: <input type=text name="date" value="<? print(date("F d, Y, h:i")); ?>"><br>
Content: <textarea cols="10" rows="5" name="content"></textarea><br>
<input type=submit value="Submit">


</td>
</form>

</tr>
</table>
<td width="20%" valign="top">
<table border="0" cellpadding="1" cellspacing="1" bgcolor="#000000" width="100%">
<tr>
<td class="headermain3" width="100%">
<b>Latest News</b>
</td>
</tr>

<tr>
<td class="headermain2" width="100%">

</td>
</tr>


</table>
</td>
<br>

</td>
</tr>
</table>

<br>
<center>
<?
footer()
?>
</center>
<?
}


and the rest to where i insert in DB

if ($s == 'newssubmit1') {
include 'config.php';

mysql_query("INSERT INTO al_news WHERE name = '$name', subject = '$subject', date = '$date', content = '$content', author = '$author', source = '$source'");
print "News successfully Inserted!<br>";
print "<a href=\"admincp.php\">Click Here</a> to return to the admincp.";
}
?>


what am i doing wrong?

AbelaJohnB
06-10-03, 08:18 PM
Ok, you kinda got the wrong theory going on here ;)

What you pasted was the code to do an UPDATE, not an INSERT.


("INSERT INTO al_news WHERE name = '$name', subject = '$subject', date = '$date', content = '$content', author = '$author', source = '$source'");

should be:

("INSERT INTO al_news (name, subject, date, contect, author, source) VALUES ($name, $subject, $date, $content, $author, $source)");


Check out this link: http://www.mysql.com/doc/en/INSERT.html : for proper usage of the INSERT statement.

The format you used: name = $value is what you'd use for an UPDATE statement.

wialniaz
06-10-03, 08:41 PM
Yeah, man, you have to insert a brand new line with no WHERE.
And update, has to be exact WHERE (AND), SET.

Psybadek
06-10-03, 10:11 PM
Thanks for you help but it still isnt inserting a new line.

Chris Boulton
06-11-03, 02:54 AM
Whats the exact problem?

Is there an error that you are getting? Is it not inserting a new row into the database? Or is it something else?

Stefan
06-11-03, 03:34 AM
you could put

echo mysql_error();

after the mysql_query with the insert statement to see what the error is that you might be getting.

Psybadek
06-11-03, 03:18 PM
its not inserting a new row at all

ChristGuy
06-11-03, 06:45 PM
Greetingz...

Firstly

I'd call the query like so:


MySQL_Query("INSERT INTO al_news (name, subject, date, contect, author, source) VALUES ('$name', '$subject', '$date', '$content', '$author', '$source')") or
die('Error executing query: ' . MySQL_Error());



BTW. Quoting the values depends on the field type.

Also are you sure you have a connection to the server... (Happened to me once...:rolleyes:)

Psybadek
06-11-03, 07:25 PM
its on my localhost and ive never had a problem before connecting

thanks Christguy..

the error you added helped.

What was wrong was that the collumn was wrong.

one was spelled "contect" and shoulda been "content"

thanks guys for the help

amailer
06-12-03, 12:59 AM
lol, happnes to me also, i get bugged and then fix it lol :) im bad @ spelling ;(

Psybadek
06-12-03, 01:23 AM
yea... and to thing.. c is no where near n on my keyboard.. O_O

digitalsea
06-13-03, 09:22 AM
Are you trying to insert a table under a different username, not the one assigned on your web server?

On localhost, you may have a different setup all together...

Psybadek
06-13-03, 10:35 AM
ive allready resolved this issue.. thanks anyway! :)

amailer
06-13-03, 11:29 AM
Originally posted by Psybadek
yea... and to thing.. c is no where near n on my keyboard.. O_O

lol, wow, what a typo ;)

ChristGuy
06-13-03, 05:59 PM
-K-... Pleasure man.... Don't worry my spling suks also..... :)

Psybadek
06-13-03, 06:05 PM
i spelled think wrong to.. and the g isnt close to the k either.. O_O