Jump to content

is this the correct syntax?


frijole

Recommended Posts

I am trying to build a CMS for my site so I can add videos with a description to my DB. I am not sure if this makes sense?

 

<table>
<tr>
<td>
<form method="post" action="mailto:[email protected]">
Embed HTML:</td><td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML">
Enter Embed HTML Here
</textarea></td></tr>
<br />
<tr><td>
Description: </td><td> <textarea rows="5" cols="50" wrap="physical" name="description">
Describe The Video Here
</textarea></td></tr>
<tr><td>
<input type="submit" value="Add Video!">
</form>
</td></tr>
</table>
<?php

require_once "dbConnect.php"; 

$embedHTML = mysql_real_escape_string($_POST['embedHTML']);
$videoDesc = mysql_real_escape_string($_POST['description']);

$query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")";

mysql_query($query) or die("could not insert data into database");

?>

Link to comment
https://forums.phpfreaks.com/topic/94818-is-this-the-correct-syntax/
Share on other sites

Besides redoing the mailto of the form, have it echo itself.

 

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

 

Then do:

 

<?php

if ($_POST['embedhtml'] && $_POST['description'])
{
require_once "dbConnect.php"; 

$embedHTML = mysql_real_escape_string($_POST['embedHTML']);
$videoDesc = mysql_real_escape_string($_POST['description']);

$query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")";

mysql_query($query) or die("could not insert data into database");

echo "Video entered into DB";
}
?>

i made those modifications, but when i execute nothing happens. The form reappears and nothing new is echoed to the screen. Any ideas?

 

My connection:

<?php
// Database settings
define("HOST", "localhost");
define("DBUSER", "********");
define("PASS", "********");
define("DB", "********");

// MySQL connection
$conn = mysql_connect(HOST, DBUSER, PASS);
if (!conn)
{
// the connection failed so quit the script
die('Could not connect !<br />Please contact the site\'s administrator.');
}

$db = mysql_select_db(DB);
if (!db)
{
// cannot connect to the database so quit the script
die('Could not connect to database <br /> Please contact the site\'s administrator.');
}
?>

 

And the add video script:

<?php

if ($_POST['embedHTML'] && $_POST['description'])
{
require_once "dbConnect.php";

$embedHTML = mysql_real_escape_string($_POST['embedHTML']);
$videoDesc = mysql_real_escape_string($_POST['description']);

$query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")";

mysql_query($query) or die("could not insert data into database");

echo "video added to the DB!";
}
else { die("the fileds are empty") }

?>
<html>

<table>

<tr>
<td> <form method="post" action="videoSubmit.php"> Embed HTML:</td> 
    <td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML"> Enter Embed HTML Here </textarea></td>
</tr>

<tr>
<td>Description: </td>
<td><textarea rows="5" cols="50" wrap="physical" name="description"> Describe The Video Here </textarea></td>
</tr>

<tr>
<td><input type="submit" value="Add Video!"></form></td>
</tr>

</table>

</html>

 

Any help would be greatly appreciated. Or any constructive criticisms.

<?php
if (isset($_POST['embedHTML'])||isset($_POST['description']))
{
require_once "dbConnect.php";

$embedHTML = mysql_real_escape_string($_POST['embedHTML']);
$videoDesc = mysql_real_escape_string($_POST['description']);

$query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")";

$result2=mysql_query($query) or die(mysql_error());

if($result2){

echo "video added to the DB!";}
}
elseif(empty($result2)){ echo "The Fields Are empty";}

?>

<?php
if (isset($_POST['embedHTML'])||isset($_POST['description']))
{
require_once("dbConnect.php");

$embedHTML = trim(mysql_real_escape_string($_POST['embedHTML']));
$videoDesc = trim(mysql_real_escape_string($_POST['description']));

$query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")";

$result2=mysql_query($query) or die(mysql_error());
}

if($result2){

echo "video added to the DB!";}
elseif(empty($result2)){ echo "The Fields Are empty";}

?>

I just tried it again and got this error:

Parse error: syntax error, unexpected '{' in /home/thinksna/public_html/videoSubmit.php on line 10

 

and this is line 10:

$query = "INSERT INTO videos VALUES ("{$embedHTML}", "{$videoDesc}")";

 

anything out of the ordinary?

use my code man it will work trust me ;D

 

 

your reverting back to your old code and adding bits and pieces of mine

 

 

<?php
if (isset($_POST['embedHTML'])||isset($_POST['description']))
{
require_once("dbConnect.php");

$embedHTML = trim(mysql_real_escape_string($_POST['embedHTML']));
$videoDesc = trim(mysql_real_escape_string($_POST['description']));

$query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)";

$result2=mysql_query($query) or die(mysql_error());
}

if($result2){

echo "video added to the DB!";}
elseif(empty($result2)){ echo "The Fields Are empty";}

?>

<?php
if ($_POST) {?>

form here


<?php

}else{
if (isset($_POST['embedHTML'])||isset($_POST['description']))
{
require_once("dbConnect.php");

$embedHTML = trim(mysql_real_escape_string($_POST['embedHTML']));
$videoDesc = trim(mysql_real_escape_string($_POST['description']));

$query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)";

$result2=mysql_query($query) or die(mysql_error());
}

if($result2){

echo "video added to the DB!";}
elseif(empty($result2)){ echo "The Fields Are empty";}
}

?>

 

 

 

I am now getting this error:

Parse error: syntax error, unexpected $end in /home/thinksna/public_html/videoSubmit2.php on line 43

 

And here is the new version of the whole script:

 

<?php
if($_POST){?>

<html>

<table>

<tr>
<td> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>"> Embed HTML:</td> 
    <td> <textarea rows="5" cols="50" wrap="virtual" name="embedHTML"> Enter Embed HTML Here </textarea></td>
</tr>

<tr>
<td>Description: </td>
<td><textarea rows="5" cols="50" wrap="physical" name="description"> Describe The Video Here </textarea></td>
</tr>

<tr>
<td><input type="submit" value="Add Video!"></form></td>
</tr>

</table>

</html>

<?php
if (isset($_POST['embedHTML'])||isset($_POST['description']))
{
require_once("dbConnect.php");

$embedHTML = trim(mysql_real_escape_string($_POST['embedHTML']));
$videoDesc = trim(mysql_real_escape_string($_POST['description']));

$query = "INSERT INTO videos VALUES ($embedHTML,$videoDesc)";

$result2=mysql_query($query) or die(mysql_error());
}

if($result2){

echo "video added to the DB!";}
elseif(empty($result2)){ echo "The Fields Are empty";}
?>

 

line 43 is the very last line of code. just

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.