problem with mysql_query
| From: | Rene Schoenmakers | Date: | Mon, 10 Jun 2002 09:14:24 +0000 |
| Subject: | problem with mysql_query | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-19708@lists.php.net to get a copy of this message | ||
Hi,
I've a problem with the following script. Sometimes it does write the
data into the database, sometimes it doesn't. When it doesn't $result is
completely blank, otherwise it is 1. $sql always returns the propper
values even though $result is blank. Can anybody tell me what I'm doing
wrong?
TIA,
Rene
Here's the code:
---------------
<?php
if (isset($submit)) {
// process form
$db = mysql_connect("$host", "$user", "$pass");
mysql_select_db("test_db",$db);
$sql = "INSERT INTO news
(newsTitle,newsDate,newsSource,newsTeaser,newsText,newsPhoto,newsUrl)
VALUES
('$newsTitle','$newsDate','$newsSource','$newsTeaser','$newsText','$news
Photo','$newsUrl')";
$result = mysql_query($sql);
echo $result."<br><br>";
echo $sql."<br><br>";
echo "Het nieuwsbericht is succesvol toegevoegd.<p>\n";
echo "<a href=\"news_input.php\">Meer nieuws
toevoegen</a><p>\n";
echo "<a href=\"../news.php\">Bekijk het
resultaat</a><p>";
} else{
// display form
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table cellspacing="0" cellpadding="0" border="0"
cellpadding="0"
cellspacing="0">
<tr>
<td valign="top">titel:</td>
<td><input type="Text" name="newsTitle"
size="55"></td>
</tr>
<tr>
<td valign="top">datum:</td>
<td><input type="Text" name="newsDate"
size="55"></td>
</tr>
<tr>
<td valign="top">bron:</td>
<td><input type="Text" name="newsSource"
size="55"></td>
</tr>
<tr>
<td valign="top">inleiding: </td>
<td><textarea name="newsTeaser" rows="5"
cols="58"></textarea></td>
</tr>
<tr>
<td valign="top">tekst:</td>
<td><textarea name="newsText" rows="5"
cols="58"></textarea></td>
</tr>
<tr>
<td>foto:</td>
<td><input type="Text" name="newsPhoto"
size="55"> <input
type=button value="Selecteer foto"
onClick="javascript:popUp('upload.php')"></td>
</tr>
<tr>
<td colspan="2"><br>Toevoegen zonder http://
Voorbeeld:
www.indyschoenmakers.com </td>
</tr>
<tr>
<td valign="top">link:</td>
<td><input type="Text" name="newsUrl"
size="55"></td>
</tr>
<tr>
<td></td>
<td><input type="Submit" name="submit" value="voeg
nieuws
toe"></td>
</tr>
</table>
</form>
<?php
} // end if
?>