PDA

Click to See Complete Forum and Search --> : this does not add


kiwis
Jul 30th, 2004, 10:11 PM
Does anyone know why this doe not work?
nothing adds to my database and i can not see a error in my code



---------------------------------------------------------------------------------
<?php
mysql_connect (localhost, username, pass);
mysql_select_db (table);
?>

<?php


if ($action == "save")
{


$result = mysql_query ("INSERT INTO news Values ('','$header','$from','$IMG,'$body','$source','$re
sult_id','$WRE','$AKL','$TRG','$PMR','$NPL','$WLG'
,'$OHA','$CHC','$DUD','$NZK','$NZW','$NZI','$AGE',
'$EDI','$BCC','$BULLS','$FLA','$REP')");



?>


<title>Rugby League in New Zealand Admin - Add News</title>


<br>
<font face="Verdana">
<strong><font size="2">All Done!<br>
</font>
</strong><font size="2">The news item has been added.<br>
&nbsp;</font></font></font></p>
<p><font face="Verdana"
size="2"><a style="text-decoration: none" href="index.php">Return to the main menu</a>

<?php


} else {

?>
<p>

<font face="Verdana" size="1">
<a style="text-decoration: none" href="index.php">Back to the main</a></font><p>
<font face="Verdana" size="1">If you have any questions please contact
<a style="text-decoration: none" href="mailto:bevan@rugbyleaguenz.com">Bevan</a></font><hr>
<font face="Verdana" size="2">

<form method="POST" action="addnews.php?action=save">



<font face="Verdana" size="2">Header: <br><input name="header" size="40" style="font-family: Verdana; border-style: solid; border-width: 1px"></font><p>

<font face="Verdana" size="2">From:<br> <input name="from" size="40" style="font-family: Verdana; border-style: solid; border-width: 1px"></font><p>

<font face="Verdana" size="2">Image:<br> <input name="IMG" size="40" style="font-family: Verdana; border-style: solid; border-width: 1px"></font><p>

<font face="Verdana" size="2">Body: <br><textarea rows="10" name="body" cols="77" style="font-family: Verdana; border-style: solid; border-width: 1px"></textarea>

<font face="Verdana" size="2">Source:<br> <input name="source" size="40" style="font-family: Verdana; border-style: solid; border-width: 1px"></font><p>

<font face="Verdana" size="2">Result ID:<br> <input name="result_id" size="40" style="font-family: Verdana; border-style: solid; border-width: 1px"></font><p>





<p>
<input type="checkbox" value="1" name="WRE"> Northland <br>
<input type="checkbox" value="1" name="AKL"> Auckland <br>
<input type="checkbox" value="1" name="TRG"> Waicoa Bay <br>
<input type="checkbox" value="1" name="PMR"> Western Alliance <br>
<input type="checkbox" value="1" name="NPL"> Taranaki <br>
<input type="checkbox" value="1" name="WLG"> Wellington <br>
<input type="checkbox" value="1" name="OHA"> Defence <br>
<input type="checkbox" value="1" name="CHC"> Canterbury RL <br>
<input type="checkbox" value="1" name="DUD"> Southern Alliance <br>
<input type="checkbox" value="1" name="NZK"> New Zealand Kiwis <br>
<input type="checkbox" value="1" name="NZW"> New Zealand Warriors <br>
<input type="checkbox" value="1" name="NZI"> New Zealand International <br>
<input type="checkbox" value="1" name="AGE"> Age Groups <br>
<input type="checkbox" value="1" name="EDI"> Editorials <br>
<input type="checkbox" value="1" name="BCC"> Bartercard Cup <br>
<input type="checkbox" value="1" name="BULLS"> Canterbury Bulls <br>
<input type="checkbox" value="1" name="FAL"> Central Falcons <br>
<input type="checkbox" value="1" name="REP"> Rep Footie



<p align="center">
<br><br>

<input type="submit" value="Save" name="B1" style="border-style: solid; border-width: 1px"></p>
</form>

<?php

}


?>
</body>
</font>
</html>
--------------------------------------------------------------------------------



and my table is set up like this

CREATE TABLE `news` (
`id` int(10) NOT NULL auto_increment,
`header` varchar(250) NOT NULL default '',
`from` varchar(250) NOT NULL default '',
`IMG` varchar(250) NOT NULL default '',
`body` text NOT NULL,
`source` varchar(250) NOT NULL default '',
`result_id` int(11) default NULL,
`WRE` int(11) default NULL,
`AKL` int(11) default NULL,
`TRG` int(11) default NULL,
`PMR` int(11) default NULL,
`NPL` int(11) default NULL,
`OHA` int(11) default NULL,
`WLG` int(11) default NULL,
`CHC` int(11) default NULL,
`DUD` int(11) default NULL,
`NZK` int(11) default NULL,
`NZW` int(11) default NULL,
`NZI` int(11) default NULL,
`AGE` int(11) default NULL,
`EDI` int(11) default NULL,
`BCC` int(11) default NULL,
`BULLS` int(11) default NULL,
`FAL` int(11) default NULL,
`REP` int(11) default NULL,
KEY `id` (`id`)
) TYPE=MyISAM AUTO_INCREMENT=2 ;

visualAd
Jul 31st, 2004, 01:08 AM
Use mysql_error() (http://www.php.net/mysql_error) after executing tthe query.

kiwis
Jul 31st, 2004, 09:37 PM
Originally posted by visualAd
Use mysql_error() (http://www.php.net/mysql_error) after executing tthe query.

it's all ok, i dont get a error

The Hobo
Aug 1st, 2004, 12:07 AM
Originally posted by kiwis
it's all ok, i dont get a error

How do you know that if you're not using mysql_error()?

visualAd
Aug 1st, 2004, 02:01 AM
Originally posted by kiwis
it's all ok, i dont get a error
If I were MySql and you sent me your query, I would give you an error. You have posted queries with similar errors several times before, I and others have also shown you how to use the error checking functions.

Use the SQL parser to check you queries not VBF members :rolleyes:

Heres what you need to do:

$result = mysql_query ("INSERT INTO news Values ('','$header','$from','$IMG,'$body','$source','$re
sult_id','$WRE','$AKL','$TRG','$PMR','$NPL','$WLG'
,'$OHA','$CHC','$DUD','$NZK','$NZW','$NZI','$AGE',
'$EDI','$BCC','$BULLS','$FLA','$REP')");

if (! $result) die (mysql_error ());

The Hobo
Aug 1st, 2004, 01:54 PM
It might be smart to get familiar with the addslashes() and stripslashes() functions as well. If someone enters a ' into one of the text fields, it's going to cause an error in your query when it gets run to MySQL.

That might be the problem you're having now.