|
-
Jul 16th, 2004, 10:46 PM
#1
Thread Starter
Frenzied Member
Adding info
I have this code but nothing will add to my database... any ideas what is wrong?
PHP Code:
<?php
mysql_connect (localhost, root, password);
mysql_select_db (Database);
?>
<?php
if ($action == "save")
{
$result = mysql_query ("INSERT INTO News Values ('','$header','$author','$body','$result_id','$attachimg','$BCC','$WLG','$AKL','$CHC','$NPL','$DUD','$PMR','$TRG','$OHA','$NZL','$KWI','$NZW')");
?>
<font face="Verdana" size="2">
<b><a href="index.php">Click here to return to the main index</a></b>
<?php
} else {
?>
<form method="POST" action="add.php?action=save">
<p>
<font face="Verdana" size="1">
<b>Header: </b>
<input TYPE="text" NAME="header" SIZE="95"> <a href="javascript:popupPage3()">(help)</a></font></p>
<p>
<font face="Verdana" size="1">
<b>Author: </b><input TYPE="text" NAME="author" SIZE="40" value="<?php echo $user_fullname; ?>">
(Optional) <a href="javascript:popupPage4()">(help)</a></font></p>
<p>
<b><font face="Verdana" size="1">Result_id:
<input type="text" name="result_id" size="5">
</font>
</b>
<font face="Verdana" size="1"><a href="javascript:popupPage7()">(help)</a></font></p>
<p>
<b><font face="Verdana" size="1">Image to show next to news item, just select the best option:</font><font face="arial" size="2"> </font>
</font>
<select size="1" name="attachimg">
<option selected value=""></option>
</select>
</b>
<font face="Verdana" size="1"><a href="javascript:popupPage8()">(help)</a></font></p>
<p>
<textarea rows="24" name="body" cols="117"></textarea></p>
<p><b></p>
<hr color="#000000" size="1">
<p><font face="Verdana" size="1">Your news item will automatically
be added to the front page of the site so if it does not need to go
on a sub section don't click any of these boxes. </font></b>
<font face="Verdana" size="1"><a href="javascript:popupPage9()">(help)</a></font><b><font face="Verdana" size="1"> </font></p>
<p><font face="Verdana" size="1">
<input type="checkbox" name="BCC" value="1"></font></b><font size="1" face="Verdana">Bartercard
Cup | </font><b><font face="Verdana" size="1">
<input type="checkbox" name="WLG" value="1"></font></b><font size="1" face="Verdana">
Wellington | </font><b><font face="Verdana" size="1">
<input type="checkbox" name="AKL" value="1"> </font></b>
<font face="Verdana" size="1">Auckland | </font>
<b><font face="Verdana" size="1">
<input type="checkbox" name="CHC" value="1"></font></b><font size="1" face="Verdana">Cantbuery
| </font><b><font face="Verdana" size="1">
<input type="checkbox" name="NPL" value="1"></font></b><font size="1" face="Verdana">
Taranaki | <b>
<input type="checkbox" name="DUD" value="1"> </b>Otago (Southern
Alliance) | </font>
<b><font face="Verdana" size="1">
<input type="checkbox" name="PMR" value="1"></font></b><font face="Verdana" size="1">Western
Alliance </font></p>
<p><b><font face="Verdana" size="1">
<input type="checkbox" name="TRG" value="1"></font></b><font size="1" face="Verdana">
WaiCoa Bay | <b>
<input type="checkbox" name="OHA" value="1"> </b>Defence |
<b><input type="checkbox" name="NZL" value="1"></b>International
| </font><b><font face="Verdana" size="1">
<input type="checkbox" name="KWI" value="1"></font></b><font size="1" face="Verdana">
Kiwis | <b><input type="checkbox" name="NZW" value="1"> </b>Warriors
</font></p>
<p>
<font face="Verdana" size="1">
<br>
</font></p>
<input type="submit" value="Submit" name="save"></p>
</form>
<?php
}
?>
-
Jul 16th, 2004, 11:23 PM
#2
Stuck in the 80s
or die(mysql_error()); will save your life. Seriously.
Code:
$result = mysql_query ("INSERT INTO News Values ('','$header','$author','$body','$result_id','$attachimg','$BCC','$WLG','$AKL','$CHC','$NPL','$DUD', '$PMR','$TRG','$OHA','$NZL','$KWI','$NZW')") or die(mysql_error());
-
Jul 16th, 2004, 11:25 PM
#3
Stuck in the 80s
By the way, that should produce an error, if anything is wrong. If you get no error, the problem isn't with the code.
-
Jul 16th, 2004, 11:38 PM
#4
Thread Starter
Frenzied Member
Originally posted by The Hobo
By the way, that should produce an error, if anything is wrong. If you get no error, the problem isn't with the code.
Do you think it will be a problem with the way my database it set up? I get no errors?
-
Jul 17th, 2004, 01:07 PM
#5
Stuck in the 80s
How are you checking to see if the data is added? Is there possibly another SQL call somewhere that might be deleting the record?
Do you have phpMyAdmin? If so, do something like this in your code:
Code:
$sql = "INSERT INTO News VALUES ('','$header','$author','$body','$result_id','$attachimg','$BCC','$WLG'";
$sql .= ",'$AKL','$CHC','$NPL','$DUD','$PMR','$TRG','$OHA','$NZL','$KWI','$NZW')";
echo $sql;
$result = mysql_query($sql) or die(mysql_error());
That way it'll print out your SQL statement with the values in it. Copy what it outputs, and paste it into phpMyAdmin and see if it works that way. If it does, you'll know that there's nothing wrong with your SQL statement.
If you still haven't figured it out, post a dump of your table layout and maybe we can find something there causing it.
-
Jul 19th, 2004, 09:17 AM
#6
Frenzied Member
This is a long shot, but does this actually connect to your DB?
PHP Code:
mysql_connect (localhost, root, password);
mysql_select_db (Database);
I'm guessing you changed the values, but if you're passing values like that, I don't know if you're even connecting, but then again, you'd probably get an error if you weren't, so !?
-
Jul 19th, 2004, 11:22 AM
#7
Stuck in the 80s
Originally posted by ober0330
This is a long shot, but does this actually connect to your DB?
PHP Code:
mysql_connect (localhost, root, password);
mysql_select_db (Database);
I'm guessing you changed the values, but if you're passing values like that, I don't know if you're even connecting, but then again, you'd probably get an error if you weren't, so !?
If he was trying to run a query without being connected to the database, he'd get an error.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|