tatlar
02-27-2003, 09:45 PM
Hi there,
More help required I'm afraid. Just getting my teeth into PHP and having all sorts of fun! (yeah...)
I am wanting to just update a table in MySQL and am using an HTML form to submit the various values to the PHP process:
---------------------------------------------------------------------------------------
<form action="insert_media.php" method="post">
<table border="0" width="50%" cellspacing="1" cellpadding="1">
<tr>
<td>Headline:</td>
<td><input type="text" name="headline" maxlength=100></td>
</tr>
<tr>
<td>Headline link:</td>
<td><input type="text" name="headline_link" maxlength=100></td>
</tr>
<tr>
<td>Date:</td>
<td><input type="text" name="date" maxlength=100></td>
</tr>
<tr>
<td>Source:</td>
<td><input type="text" name="source" maxlength=100></td>
</tr>
<tr>
<td>Source Link:</td>
<td><input type="text" name="source_link" maxlength=100></td>
</tr>
<tr>
<td><input type="reset" name="Reset" value="Reset" /></td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
---------------------------------------------------------------------------------------
In "insert_media.php" (the target) I have the following PHP:
---------------------------------------------------------------------------------------
<html>
<head>
<title>Entry Results</title>
</head>
<body>
<h1>Entry Results</h1>
<?php
if ( !$headline || !$headline_link || !$date || !$source || !$source_link )
{
echo "You have not entered all the required details.<br />Please go back and try again." ;
exit ;
}
$headline = addslashes( $headline ) ;
$headline_link = addslashes( $headline_link ) ;
$date = addslashes( $date ) ;
$source = addslashes( $source ) ;
$source_link = addslashes( $source_link ) ;
@ $db = mysql_pconnect( "$host", "$php", "$pwd" ) ;
if (!$db)
{
echo "Error: could not connect" ;
exit ;
}
mysql_select_db( "news" ) ;
$query = "INSERT INTO media VALUES ( '".$headline."' , '".$headline_link."' , '".$date."' , '".$source."' , '".$source_link."' )" ;
$result = mysql_query( $query ) ;
if ($result) echo mysql_affected_rows()." news items inserted into database." ;
?>
</body>
</html>
---------------------------------------------------------------------------------------
Should be simple right? However, the script always falls over at the first "if" statement:
if ( !$headline || !$headline_link || !$date || !$source || !$source_link )
Is this the correct syntax? I copied it from a book, so assumed it was correct. I tried to add a semicolon at the end of the "if" statement, but this didn't make any difference.
I just keep getting the first echo statement coming out on my browser:
"You have not entered all the required details.
Please go back and try again. "
I guess at least this is working :)
I am convinced this is simple and it is just my sleepy eyes that are missing something. Any ideas anyone?
Thanks in advance.
- Tatlar
More help required I'm afraid. Just getting my teeth into PHP and having all sorts of fun! (yeah...)
I am wanting to just update a table in MySQL and am using an HTML form to submit the various values to the PHP process:
---------------------------------------------------------------------------------------
<form action="insert_media.php" method="post">
<table border="0" width="50%" cellspacing="1" cellpadding="1">
<tr>
<td>Headline:</td>
<td><input type="text" name="headline" maxlength=100></td>
</tr>
<tr>
<td>Headline link:</td>
<td><input type="text" name="headline_link" maxlength=100></td>
</tr>
<tr>
<td>Date:</td>
<td><input type="text" name="date" maxlength=100></td>
</tr>
<tr>
<td>Source:</td>
<td><input type="text" name="source" maxlength=100></td>
</tr>
<tr>
<td>Source Link:</td>
<td><input type="text" name="source_link" maxlength=100></td>
</tr>
<tr>
<td><input type="reset" name="Reset" value="Reset" /></td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form>
---------------------------------------------------------------------------------------
In "insert_media.php" (the target) I have the following PHP:
---------------------------------------------------------------------------------------
<html>
<head>
<title>Entry Results</title>
</head>
<body>
<h1>Entry Results</h1>
<?php
if ( !$headline || !$headline_link || !$date || !$source || !$source_link )
{
echo "You have not entered all the required details.<br />Please go back and try again." ;
exit ;
}
$headline = addslashes( $headline ) ;
$headline_link = addslashes( $headline_link ) ;
$date = addslashes( $date ) ;
$source = addslashes( $source ) ;
$source_link = addslashes( $source_link ) ;
@ $db = mysql_pconnect( "$host", "$php", "$pwd" ) ;
if (!$db)
{
echo "Error: could not connect" ;
exit ;
}
mysql_select_db( "news" ) ;
$query = "INSERT INTO media VALUES ( '".$headline."' , '".$headline_link."' , '".$date."' , '".$source."' , '".$source_link."' )" ;
$result = mysql_query( $query ) ;
if ($result) echo mysql_affected_rows()." news items inserted into database." ;
?>
</body>
</html>
---------------------------------------------------------------------------------------
Should be simple right? However, the script always falls over at the first "if" statement:
if ( !$headline || !$headline_link || !$date || !$source || !$source_link )
Is this the correct syntax? I copied it from a book, so assumed it was correct. I tried to add a semicolon at the end of the "if" statement, but this didn't make any difference.
I just keep getting the first echo statement coming out on my browser:
"You have not entered all the required details.
Please go back and try again. "
I guess at least this is working :)
I am convinced this is simple and it is just my sleepy eyes that are missing something. Any ideas anyone?
Thanks in advance.
- Tatlar